using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace fractie_rational
{
class fractie
{
protected int nr, nu;
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());
}
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 Program
{
static void Main(string[] args)
{
rational r = new rational(4, 8);
r.afisare();
rational r1 = new rational();
r1.citire();
r1.afisare();
Console.ReadKey();
}
}
}
|