0% found this document useful (0 votes)
34 views3 pages

Using: "X (0) and y (1) "

The document defines classes for performing basic mathematical operations - Addition, Subtraction, Multiplication, and Division. Each operation class inherits from an abstract Choose class and overrides a print method. The Main method presents a menu to select an operation, gets user input for the numbers, calls the appropriate operation class to perform the calculation, and prints the result.

Uploaded by

Jason May
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views3 pages

Using: "X (0) and y (1) "

The document defines classes for performing basic mathematical operations - Addition, Subtraction, Multiplication, and Division. Each operation class inherits from an abstract Choose class and overrides a print method. The Main method presents a menu to select an operation, gets user input for the numbers, calls the appropriate operation class to perform the calculation, and prints the result.

Uploaded by

Jason May
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

using System;

class Choose
{
protected int x, y;
public virtual void print()
{ Console.Out.WriteLine("x = {0} and y = {1}", x, y); }
}
class Subtraction : Choose
{
private int result;
public void sub()
{
Console.Write("\n\nEnter first number: ");
x = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter second number: ");
y = Convert.ToInt32(Console.ReadLine());
result = x - y;
}
public override void print()
{
Console.Out.WriteLine("\n{0} - {1} = {2}", x, y, result);
}
}
class Addition : Choose
{
private int result;
public void sum()
{
Console.Write("\n\nEnter first number: ");
x = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter second number: ");
y = Convert.ToInt32(Console.ReadLine());
result = x + y;
}
public override void print()
{
Console.Out.WriteLine("\n{0} + {1} = {2}", x, y, result);
}
}
class Division : Choose
{
private int result;
public void div()
{
Console.Write("\n\nEnter first number: ");
x = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter second number: ");
y = Convert.ToInt32(Console.ReadLine());
result = x / y;
}
public override void print()
{
Console.Out.WriteLine("\n{0} / {1} = {2}", x, y, result);
}
}
class Multiplication : Choose
{

private int result;


public void mul()
{
Console.Write("\n\nEnter first number: ");
x = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter second number: ");
y = Convert.ToInt32(Console.ReadLine());
result = x * y;
}
public override void print()
{
Console.Out.WriteLine("\n{0} * {1} = {2}", x, y, result);
}

}
class Program
{
static void Main(string[] args)
{
int opt;
Addition sumobj = new Addition();
Subtraction subobj = new Subtraction();
Multiplication mulobj = new Multiplication();
Division divobj = new Division();
while (true)
{
Console.WriteLine("Hello Dr.Adel this program for
addition, subtraction, multipliction and division");
Console.WriteLine("\t\t\t\t Made By Saeed");
Console.WriteLine("-------------- Menu
----------------");
Console.WriteLine("Choose 1 for addition ( + )");
Console.WriteLine("Choose 2 for subtraction ( - )");
Console.WriteLine("Choose 3 for multiplication ( * )");
Console.WriteLine("Choose 4 for Division ( / )");
Console.WriteLine("Choose 5 for try again");
Console.WriteLine("Choose 6 for Exit");
Console.WriteLine("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
Console.WriteLine("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
Console.Write("Choose Your Process: ");
opt = Convert.ToInt32(Console.ReadLine());
if (opt == 1)
{
sumobj.sum();
sumobj.print();
}
else if (opt == 2)
{
subobj.sub();
subobj.print();
}
else if (opt == 3)
{
mulobj.mul();
mulobj.print();
}
else if (opt == 4)
{
divobj.div();
divobj.print();

else if (opt == 5)
Console.Out.WriteLine("Sorry try again (-__-)");
else if (opt == 6)
{
Console.Out.WriteLine("This is the END (^-^)");
break;
}
}
Console.ReadKey();
}

You might also like