Documente Academic
Documente Profesional
Documente Cultură
RAPORT
Lucrarea de laborator nr.3
la disciplina Programarea Orientată pe Obiecte
A efectuat:
st. gr. AI-161 S.Dubac
A verificat:
lector univ. M.Oșovschi
Chişinău 2017
Lucrarea de laborator nr.3
#include<iostream>
using namespace std;
class Money
{
private:
int LL;
int BB;
int nr;
public:
Money()
{
LL = 0;
BB = 0;
}
const Money operator+( Money &) const ;
const Money operator-( Money &) const;
const Money operator*( Money &) const;
const Money operator/( Money &) const;
const Money operator=( Money &) const;
1
{
LL++;
BB -= 100;
}
}
return *this;
}
Money operator-( Money & M)
{
LL -= M.LL;
BB -= M.BB;
if(BB>= 100)
{
while(BB/100)
{
LL--;
BB -= 100;
}
}
return *this;
}
Money operator*( double coef)
{
LL *= coef;
BB *= coef;
if(BB>= 100)
{
while(BB/100)
{
LL++;
BB -= 100;
}
}
return *this;
}
Money operator/(double coef)
{
LL /= coef;
BB /= coef;
if(BB>= 100)
{
while(BB/100)
{
LL++;
BB -= 100;
}
}
2
return *this;
}
Money operator=(Money M)
{
LL = M.LL;
BB = M.BB;
return *this;
}
void Init()
{
cout<<"\nDati valoarea in lei :"<<endl;
cin>>LL;
cout<<"\nDati valoarea in bani :"<<endl;
cin>>BB;
}
int Adunarea ()
{
int ll1,bb1;
int ll2,bb2;
cout<<" Adunarea:"<<endl;
cout<<"Introduceti prima suma:"<<endl;
cout<<"Lei:"; cin>>ll1;
cout<<"Bani:"; cin>>bb1;
cout<<"Introduceti a doua suma:"<<endl;
cout<<"Lei:"; cin>>ll2;
cout<<"Bani:"; cin>>bb2;
BB=bb1+bb2;
LL=ll1+ll2+(BB/100);
BB=BB%100;
cout<<"Suma finala este:"<<endl;
cout<<endl<<LL<<" lei "<<BB<<" de bani. "<<endl;
}
int Scaderea()
{
int ll1,bb1;
int ll2,bb2;
cout<<"\n Scaderea"<<endl;
cout<<"Pentru a efectua scaderea sumelor introduceti prima suma mai mare ca a doua
suma:"<<endl;
cout<<"Introduceti prima suma:"<<endl;
cout<<"Lei:"; cin>>ll1;
cout<<"Bani:"; cin>>bb1;
cout<<"Introduceti a doua suma:"<<endl;
cout<<"Lei:"; cin>>ll2;
cout<<"Bani:"; cin>>bb2;
BB=bb1-bb2;
LL=ll1-ll2+(BB/100);
3
BB=BB%100;
cout<<"Suma finala este:"<<endl;
cout<<endl<<LL<<" lei "<<BB<<" de bani. "<<endl;
}
int Inmultirea()
{
int ll1,bb1;
int numar;
cout<<"\n Imultirea:"<<endl;
cout<<"Introduceti suma:"<<endl;
cout<<"Lei:"; cin>>ll1;
cout<<"Bani:"; cin>>bb1;
cout<<"Introduceti coeficietul:"<<endl;
cout<<"Coeficientul de inmultit este:"; cin>>numar;
BB=bb1*numar;
LL=ll1*numar+(BB/100);
BB=BB%100;
cout<<"Suma este:";
cout<<endl<<LL<<" lei "<<BB<<" de bani. "<<endl;
}
int Impartirea()
{
float ll1,bb1;
float numar;
float n,m;
cout<<"\n Impartirea:"<<endl;
cout<<"Introduceti suma:"<<endl;
cout<<"Lei:";
cin>>ll1;
cout<<"Bani:";
cin>>bb1;
cout<<"Introduceti coeficietul:"<<endl;
cout<<"Coeficientul de impartire este:"; cin>>numar;
n=ll1*100;
m=n+bb1;
BB=m/numar;
LL=BB/100;
BB=BB%100;
cout<<endl<<LL<<" lei "<<BB<<" de bani. "<<endl;
}
void show()
{
cout<<"Lei="<<LL;
cout<<"\nBani="<<BB;
}
};
4
int main()
{
Money M1, M2;
cout<<"\nIntroduceti prima suma: ";
M1.Init();
M1.show();
cout<<"\nIntroduceti a doua suma: ";
M2.Init();
M2.show();
Money M3;
cout<<"\nM3 este egal:"<<endl;;
M3=M1+M2;
M3.show();
Money M7;
cout<<"\nIntroduceti prima suma: ";
M7.Init();
M7.show();
double coef;
cout<<"\nDati coeficientul:";
cin>>coef;
M7 = M7*coef;
M7.show();
Money M9;
cout<<"\nIntroduceti suma: ";
M9.Init();
M9.show();
double coef1;
cout<<"\nDati coeficientul:";
cin>>coef1;
cout <<"\nM9 este egal:"<<endl;
M9 = M9/coef1;
M9.show();
}
5
Rezultatul obtinut:
Figura -1 Adunarea
Figura -2 Scăderea
Figura -3 Înmulțirea
6
Figura -4 Împărțirea
Bibliografie: