Question: Design an OOP using C# (C_Sharp) console application that will read two numbers and an integer code. The value of the integer code should be

Design an OOP using C# (C_Sharp) console application that will read two numbers and an integer code. The value of the integer code should be 1,2,3 or 4. If the value of the code is one, use an ADDITION method to compute the sum of the two numbers. If the code is two, use a SUBTRACT method to compute the difference (first minus second). If the code is three, use a MULTIPLY method to compute the product of the two numbers. If the code is four and the second number is not zero, use a DIVISION method to compute the quotient (first divide by second). If the code is not equal to 1.2.3 or 4 display an error message. The program should then display the computed result on the screen. Use a MENU method to assist with the selection of the integer code. Be sure to include constructor and destructor methods. Also, Program should be able to be run in Visual Studio.

Sol120:

Here is an example implementation of the program in C# console application:

using System;

class Calculator

{

private double num1, num2;

public Calculator(double num1, double num2)

{

this.num1 = num1;

this.num2 = num2;

}

public double Addition()

{

return num1 + num2;

}

public double Subtract()

{

return num1 - num2;

}

public double Multiply()

{

return num1 * num2;

}

public double Divide()

{

if (num2 == 0)

{

Console.WriteLine(\"Error: Cannot divide by zero\");

return 0;

}

else

{

return num1 / num2;

}

}

}

class Program

{

static void Main(string[] args)

{

Console.WriteLine(\"Enter two numbers:\");

double num1 = Convert.ToDouble(Console.ReadLine());

double num2 = Convert.ToDouble(Console.ReadLine());

Console.WriteLine(\"Select an operation:\");

Console.WriteLine(\"1. Addition\");

Console.WriteLine(\"2. Subtraction\");

Console.WriteLine(\"3. Multiplication\");

Console.WriteLine(\"4. Division\");

int choice = Convert.ToInt32(Console.ReadLine());

Calculator calculator = new Calculator(num1, num2);

switch (choice)

{

case 1:

Console.WriteLine(\"Result: \" + calculator.Addition());

break;

case 2:

Console.WriteLine(\"Result: \" + calculator.Subtract());

break;

case 3:

Console.WriteLine(\"Result: \" + calculator.Multiply());

break;

case 4:

Console.WriteLine(\"Result: \" + calculator.Divide());

break;

default:

Console.WriteLine(\"Error: Invalid operation code\");

break;

}

}

}

To run this program in Visual Studio, create a new console application project and copy and paste the code into the Program.cs file. Then build and run the project by pressing the \"Start\" button or pressing F5 on your keyboard.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!