Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace bryanoverload
{
    class Arithmetics
    {

        int sum;
        public int Sum
        {
            get { return sum; }
            set { sum = value; }
        }

        decimal difference;
        public decimal Difference
        {
            get { return difference; }
            set { difference = value; }
        }
       
        double product;
        public double Product
        {
            get { return product; }
            set { product = value; }
        }
        
        float qoutient;
        public float Qoutient
        {
            get { return qoutient; }
            set { qoutient = value; }
        }

        int num1;
        public int Num1
        {
            get { return num1; }
            set { num1 = value; }
        }

        int num2;
        public int Num2
        {
            get { return num2; }
            set { num2 = value; }
        }
        
        
        public void Arithmethic()
        {

            Console.Write("Enter the first number:");
            num1 = int.Parse(Console.ReadLine());
            Console.Write("Enter the second number:");
            num2 = int.Parse(Console.ReadLine());        
        }

        public void Compute(int ans, int number1, int number2)
        {

            ans = number1 + number2;
            Console.WriteLine("The sum of the two numbers is: ");
        }

        public void Compute(decimal ans, int number1, int number2)
        {
            ans = number1 - number2;
            Console.WriteLine("The difference of the two numbers is: ");
        }

        public void Compute(double ans, int number1, int number2)
        {

            ans = number1 * number2;
            Console.WriteLine("The product of the two numbers is: ");
        }

        public void Compute(float ans, int number1, int number2)
        {

            ans = number1 / number2;
            Console.WriteLine("The qoutient of the two numbers is: ");
        }
           
    }
}
Posted
Updated 11-Aug-13 15:16pm
v3

1 solution

In your program.cs file you would do something like:

C#
Arithmetics arith = new Arithmetics();

arith.Arithmetic();


But in your arithmetic class you have some problems, namely that the functions never really return anything. In order to do it with the parameter in the prototype like you have, you have to declare them with the "out" keyword, like:

C#
public void Compute(out float ans, int number1, int number2)


But the best way to do it is to return the value from the function rather than use it in the prototype, like this:

C#
public float Compute(int number1, int number2)
{
   float ans = 0.0f;
   //... Compute here, assigning it to ans
   return ans;
}


You also want to use more descriptive names instead of "compute", like add/subract, etc. That way you can use the same prototype for each one and not have the type in the parameter list.
 
Share this answer
 
v2
Comments
borlon 11-Aug-13 22:31pm    
how should I declared an out to my class and what is the purpose of this ?
borlon 11-Aug-13 23:26pm    
sir the output this program, is must be like this ! with the arithmetic.class and program.cs can you help me in that way ! thanks
MuhammadUSman1 12-Aug-13 0:43am    
Ron Beryer answered your question.

[+5 Ron Beyer]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900