74 lines
2.0 KiB
C#
74 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ConsoleApp1
|
|
{
|
|
class Szamolo
|
|
{
|
|
public double operand1, operand2;
|
|
public Szamolo(double operand1, double operand2)
|
|
{
|
|
this.operand1 = operand1;
|
|
this.operand2 = operand2;
|
|
}
|
|
public double Kalk(char operatorCode)
|
|
{
|
|
switch (operatorCode)
|
|
{
|
|
case '+':
|
|
return operand1 + operand2;
|
|
break;
|
|
case '-':
|
|
return operand1 - operand2;
|
|
break;
|
|
case '*':
|
|
return operand1 * operand2;
|
|
break;
|
|
case '/':
|
|
if (operand2 != 0)
|
|
{
|
|
return operand1 / operand2;
|
|
} else
|
|
{
|
|
throw new DivideByZeroException("Ne osszá nullával!");
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
}
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
Console.WriteLine("Adja meg az első operandust!");
|
|
double op1 = Convert.ToDouble(Console.ReadLine());
|
|
Console.WriteLine("Adja meg a második operandust!");
|
|
double op2 = Convert.ToDouble(Console.ReadLine());
|
|
Console.WriteLine("Add meg a műveletet!");
|
|
char muvelet = Convert.ToChar(Console.ReadLine());
|
|
|
|
Szamolo szamol = new Szamolo(op1, op2);
|
|
|
|
try
|
|
{
|
|
double er = szamol.Kalk(muvelet);
|
|
Console.WriteLine(er);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
|
|
throw;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|