using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace fractie_rational
{
class fractie
{
protected int nr, nu;// ca sa se poate mosteni
public fractie()
{
}
public fractie(int a, int b)
{
nr = a; nu = b;
}
public void citire()
{
nr = Int32.Parse(Console.ReadLine());
nu = Int32.Parse(Console.ReadLine());
}
virtual public void afisare()
{
Console.Write(nr+"/"+nu);
}
}
class rational : fractie
{
public rational()
{
}
public rational(int a, int b):base(a,b)//apeleaza constructorul clasei de baza
{
simplificare();
}
private int cmmdc(int a, int b)
{ while(a!=b)
if(a>b) a=a-b;
else b=b-a;
return a;
}
private void simplificare()
{
int c=cmmdc(nr,nu);
nr = nr / c;
nu = nu / c;
}
new public void citire()//rescrie metoda pentru citire
{
nr = Int32.Parse(Console.ReadLine());
nu = Int32.Parse(Console.ReadLine());
simplificare();
}
}
class complex : fractie
{
public complex()
{
}
public complex(int a, int b):base(a,b)//apeleaza constructorul clasei de baza
{
}
override public void afisare()
{
Console.Write(nr + "+i*" + nu);
}
}
class Program
{
static void Main(string[] args)
{
rational r = new rational(4, 8);
r.afisare();
rational r1 = new rational();
r1.citire();
r1.afisare();
complex c = new complex(2, 3);
c.afisare();
fractie f = new fractie(3, 7);
f = new complex(4, 5);
f.afisare();
Console.ReadKey();
}
}
}
|