Potrebujem surne pomoct s programom (seminarna praca).
Pri programovani ma byt pouzite objektovo orientovane programovanie (OOP) a moze to byt program v C++ - console, C++ - windows apl., C# - console alebo C# - windows apl..
Jedna sa o nasledujuci program (zadanie):
Jednoducha kalkulacka
1. trieda - 4 metody (+, -, *, / (nekontrolovat vstupnu hodnotu))
|
| dedenim
|
v
2. trieda - 3 metody (x^2 (druha mocnina), sqrt(x) (druha odmocnina), / (delenie -kontrolovat vstupnu hodnotu na delenie nulou))
Skuste niekto pomoct, pls.
Vopred dakujem.
spero
Program - objektovo orientovane programovanie - POMOC, PLS!!
uz to mam hotove
splodil som toto:
//program Kalkulacka podla zadania z 6.10.2007
//Lubomir Sperka, AIA, II. roc. Ext. BC.
using System;
using System.Collections.Generic;
using System.Text;
namespace Kalkulacka
{
public class calc_1
{
public void Plus(decimal x, decimal y) { Console.WriteLine("Sucet X+Y={0}\n", x + y); }
public void Minus(decimal x, decimal y) { Console.WriteLine("Rozdiel X-Y={0}\n", x - y); }
public void Nasobenie(decimal x, decimal y) { Console.WriteLine("Sucin X*Y={0}\n", x * y); }
public void Delenie(decimal x, decimal y) { Console.WriteLine("Podiel X/Y={0}\n", x / y); }
}
public class calc_2:calc_1
{
public void Mocnina_1(decimal x) { Console.WriteLine("Drha mocnina X^2={0}\n", x * x); }
public void Mocnina_2(decimal y) { Console.WriteLine("Drha mocnina Y^2={0}\n", y * y); }
public void Odmocnina_1(double x) { Console.WriteLine("Odmocnina X={0}\n", Math.Sqrt(x)); }
public void Odmocnina_2(double y) { Console.WriteLine("Odmocnina Y={0}\n", Math.Sqrt(y)); }
public new void Delenie(decimal x, decimal y)
{
try{base.Delenie(x,y);}
catch { Console.WriteLine("Chyba: nie je mozne delenie nulou\n"); }
}
}
class Program
{
static void Main(string[] args)
{
calc_2 calc = new calc_2();
decimal x;
decimal y;
Console.WriteLine("Zadaj cislo X");
x=Convert.ToDecimal(System.Console.ReadLine());
Console.WriteLine("Zadaj cislo Y");
y=Convert.ToDecimal(System.Console.ReadLine());
Console.WriteLine("\n\n");
Console.WriteLine("Vysledky jednoduchych matematickych operacii su:\n\n");
calc.Plus(x,y);
calc.Minus(x,y);
calc.Delenie(x,y);
calc.Nasobenie(x,y);
calc.Mocnina_1(x);
calc.Mocnina_2(y);
calc.Odmocnina_1(Convert.ToDouble(x));
calc.Odmocnina_2(Convert.ToDouble(y));
Console.ReadLine();
}
}
}
//program Kalkulacka podla zadania z 6.10.2007
//Lubomir Sperka, AIA, II. roc. Ext. BC.
using System;
using System.Collections.Generic;
using System.Text;
namespace Kalkulacka
{
public class calc_1
{
public void Plus(decimal x, decimal y) { Console.WriteLine("Sucet X+Y={0}\n", x + y); }
public void Minus(decimal x, decimal y) { Console.WriteLine("Rozdiel X-Y={0}\n", x - y); }
public void Nasobenie(decimal x, decimal y) { Console.WriteLine("Sucin X*Y={0}\n", x * y); }
public void Delenie(decimal x, decimal y) { Console.WriteLine("Podiel X/Y={0}\n", x / y); }
}
public class calc_2:calc_1
{
public void Mocnina_1(decimal x) { Console.WriteLine("Drha mocnina X^2={0}\n", x * x); }
public void Mocnina_2(decimal y) { Console.WriteLine("Drha mocnina Y^2={0}\n", y * y); }
public void Odmocnina_1(double x) { Console.WriteLine("Odmocnina X={0}\n", Math.Sqrt(x)); }
public void Odmocnina_2(double y) { Console.WriteLine("Odmocnina Y={0}\n", Math.Sqrt(y)); }
public new void Delenie(decimal x, decimal y)
{
try{base.Delenie(x,y);}
catch { Console.WriteLine("Chyba: nie je mozne delenie nulou\n"); }
}
}
class Program
{
static void Main(string[] args)
{
calc_2 calc = new calc_2();
decimal x;
decimal y;
Console.WriteLine("Zadaj cislo X");
x=Convert.ToDecimal(System.Console.ReadLine());
Console.WriteLine("Zadaj cislo Y");
y=Convert.ToDecimal(System.Console.ReadLine());
Console.WriteLine("\n\n");
Console.WriteLine("Vysledky jednoduchych matematickych operacii su:\n\n");
calc.Plus(x,y);
calc.Minus(x,y);
calc.Delenie(x,y);
calc.Nasobenie(x,y);
calc.Mocnina_1(x);
calc.Mocnina_2(y);
calc.Odmocnina_1(Convert.ToDouble(x));
calc.Odmocnina_2(Convert.ToDouble(y));
Console.ReadLine();
}
}
}