Kis Alexandru Lab 9
Kis Alexandru Lab 9
Kis Alexandru Lab 9
#include<iostream>
using namespace std;
cout<<endl<<"Supraincarcarea operatorului=";
Matrix n=m;
cout<<endl;
for(i=0;i<Linii;i++){
cout<<endl;
for(j=0;j<Coloane;j++)
cout<<n(i,j)<<"\t";
}
Matrix m1(Linii,Coloane);
cout<<endl<<"Dati matricea";
m1.citire();
cout<<endl<<"Matricea este:"<<endl;
m1.afisare();
Matrix m2(Linii,Coloane);
cout<<endl<<"Supraincarcarea operatorului+";
m2=m+m1;
cout<<endl<<"Matricea rezultata din suma celor 2 matrici este:";
m2.afisare();
cout<<endl<<"Supraincarcarea operatorului-";
m2=m-m1;
cout<<endl<<"Matricea rezultata din diferenta celor 2 matrci este:";
m2.afisare();
Matrix m3(3,2);//matricea m are 2 linii si 3 coloane deci pentru a fi posibil
produsul m3 trebuie sa aiba 3 linii si 2 coloane
cout<<endl<<"Dati matricea pentru produs";
m3.citire();
Matrix m4(2,2);//matricea rezultata dupa produs va avea 2 linii si 2 coloane
cout<<endl<<"Supraincarcarea operatorului*";
m4=m*m3;
cout<<endl<<"Matricea rezultata din suma produselor celor 2 matrici este:";
m4.afisare();
}
#include<iostream>
using namespace std;
#include<string.h>
class Departament;
class Angajat{
char nume[20];
float salariu;
public:
friend class Departament;
Angajat(){};
void afisare();
char* getter_n();
float getter_s();
};
class Departament{
int n;
Angajat *ang;
public:
Departament(int nr);
void citire();
Angajat operator[](int);
};
char * Angajat::getter_n(){
return nume;
}
float Angajat::getter_s(){
return salariu;
}
void Angajat::afisare(){
cout<<endl<<"Nume:"<<nume<<"Salariu:"<<salariu;
}
Departament::Departament(int nr)//consturctor
{
n=nr;
ang=new Angajat[n];
}
#include<iostream>
using namespace std;
#include<string.h>
class Departament;
class Angajat{
char nume[20];
float salariu;
public:
friend class Departament;
Angajat(){}
Angajat(char *,float s);
void afisare();
char* getter_n();
float getter_s();
class Departament{
int n;
public:
Angajat *ang;
Departament(int nr);
Departament();
void citire();
Angajat operator[](int);
char * Angajat::getter_n(){
return nume;
}
float Angajat::getter_s(){
return salariu;
}
void Angajat::afisare(){
cout<<endl<<"Nume:"<<nume<<"Salariu:"<<salariu;
}
void *Angajat::operator new(size_t marime){
printf("\n Supraincarc local operatorul new pt clasa Angajat");
return malloc(marime);
}
void Angajat::operator delete(void *a){
printf("\nSupraincarc local operatorul delete pentru clasa Angajat.");
free(a);
}
void *Angajat::operator new[](size_t marime){
printf("\nSupraincarc local operatorul new[] pt clasa Angajat");
return malloc(marime);
}
void Angajat::operator delete[](void *a){
printf("\nSupraincarc local operatorul delete[] pt clasa Angajat.");
free(a);
}
Departament::Departament(int nr)//consturctor
{
n=nr;
for(int i=0;i<n;i++)
ang=new Angajat[n];
if(!ang){
printf("\Nu am putut aloca memorie pt. ang.");
exit(0);
}
}
void main(){
int nr,ind;
cout<<endl<<"Dati nr de angajati:";
cin>>nr;
Angajat *a=new Angajat("Popescu",200);
cout<<"\nInformatia despre angajat:";
a->afisare();
Departament ob(nr);
Departament *ob2=new Departament[2];
ob2[0]=Departament(1);
ob2[1]=Departament(2);
ob.citire();
cout<<endl<<"Dati angajatul cu numarul de ordine:";
cin>>ind;
if((ind>=1)&&(ind<=nr)){
cout<<"Angajatul cu numarul de ordine"<<ind<<"este:\n";
ob[ind].afisare();
}
else
cout<<"Numarul de ordine este invalid!";
delete a;
delete []ob2;
}
#include<iostream>
using namespace std;
class Functii{
int a,b;
public:
Functii(){}
Functii(int x,int y){
a=x;
b=y;
}
int myFunction(int x){
return x;
}
int myFunction(int x,int y){
return x*y;
}
};
void main(){
int a,b;
cout<<"introduceti a:";
cin>>a;
cout<<"introduceti b:";
cin>>b;
Functii f(a,b);
printf("\nvaloarea primului parametru este :%d",f.myFunction(a));
printf("\nprodusul paramatrilor este:%d\n",f.myFunction(a,b));
}
/*5. Sa se scrie programul care utilizeaza o clasa numita Calculator si care are n
componenta sa (definite ca metode
publice) functiile:
- int calcul(int x) care returneaza patratul valorii primite;
- int calcul(int x, int y) care returneaza produsul celor doua valori primite;
- float calcul(int x, int y, int z) care returneaza rezultatul nlocuirii n
formula f(x,y,z) = (x-y)(x+z)/2 a valorilor
primite;
Programul primeste prin linia de comanda toti parametrii necesari.*/
#include<iostream>
using namespace std;
#include<stdlib.h>
class Calculator{
public:
int calcul(int x);
int calcul(int x, int y);
float calcul(int x, int y, int z);
};
int Calculator::calcul(int x){
return x*x;
}
int Calculator::calcul(int x, int y){
return x*y;
}
float Calculator::calcul(int x, int y, int z){
return ((x-y)*(x+z)/2.0);
}
/*6. Sa se defineasca clasa Student avnd ca date membre private: numele (?ir de
caractere), note (pointer de tip ntreg) ?i
nr_note (int). Clasa mai con?ine un constructor cu parametri, un constructor de
copiere, o func?ie de suprancarcare a operatorului de atribuire, o
metoda de setare a notelor, o metoda de afi?are a atributelor ?i un destructor. Sa
se instan?ieze obiecte folosind constructorul cu parametri, un alt
obiect folosind constructorul de copiere, afi?nd de fiecare data atributele
obiectului creat. Realiza?i o opera?ie de copiere a unui obiect n alt obiect,
ambele fiind create in prealabil. Afi?ati rezultatul copierii.*/
#include<iostream>
using namespace std;
#include<string.h>
class Student{
char nume[20];
int *note;
int nr_note;
public:
Student(char n[],int *p,int nr);
Student(Student &ob1);
Student& operator=(Student &s);
void setter(char n[],int *p,int nr);
void afisare();
~Student(void);
};
void main(){
char num[20];
int not[20],*p=¬[0],nr;
cout<<endl<<"Dati numele:";
cin>>num;
cout<<endl<<"Dati numarul de note:";
cin>>nr;
cout<<endl<<"Dati notele:";
for(int i=0;i<nr;i++)
cin>>*(p+i);
Student ob3(num,p,nr);
ob3.afisare();
cout<<"\nRealizam o operatie de asignare intre obiectele create:\n";
ob3=ob1;
ob3.afisare();
}
#include<iostream>
using namespace std;
#define Pi 3.14
#include<math.h>
class Complex{
double re;
double im;
public:
Complex(double x=0,double y=0);
double getter_re();
double getter_im();
void afisare();
double modul();
double argum();
Complex operator +(Complex &ob1);//calc suma a 2 nr complexe
Complex operator -(Complex &ob1);//calc diferenta a 2 nr complexe
Complex operator *(Complex &ob1);//calc produsul a 2 nr complexe
Complex operator /(Complex &ob1);//calc raportul a 2 nr complexe
Complex operator !();//calculeaza radacina patrata a ob curent,argum,oartea
reala si partea imaginara
};
Complex::Complex(double x,double y){
re=x;
im=y;
}
double Complex::getter_re(){
return re;
}
double Complex::getter_im(){
return im;
}
Complex Complex::operator +(Complex &ob1){
Complex obb;
obb.re=re+ob1.re;
obb.im=im+ob1.im;
return obb;
}
Complex Complex::operator -(Complex &ob1){
Complex obb;
obb.re=re-ob1.re;
obb.im=im-ob1.im;
return obb;
}
double Complex::modul()//calculeaza modulul unu numar complex
{
return sqrt(re*re+im*im);
}
double Complex::argum(){
double a=atan(im/re);
if(re<0)return Pi+a;
if(im>0)return(2*Pi+a);
}
Complex Complex::operator !()//calculeaza radacina patrata a ob curent ,argum,parte
reala si parte imaginara
{
Complex z;
double a=modul();
double alfa;
alfa=argum();
a=sqrt(a);
z.re=a*cos(alfa);//scriem nr complex sub forma trigonometrica
z.im=a*sin(alfa);
return z;
}
Complex Complex::operator *(Complex &ob1)//calculeaza produsul a 2 nr complexe
{
Complex obb;
obb.re=re*ob1.re-im*ob1.im;
obb.im=re*ob1.im+im*ob1.re;
return obb;
}
Complex Complex::operator /(Complex &ob1)//calculeaza raportul a 2 nr complexe
{
Complex z;
double a=ob1.re*ob1.re+ob1.im*ob1.im;
if(a!=0){
z.re=(re*ob1.re+im*ob1.im)/a;
z.im=(im*ob1.re-re*ob1.im)/a;
return z;
}
}
void Complex::afisare(){
if(im<0)
cout<<re<<im<<"j";
else
cout<<re<<"+"<<im<<"j";
}
void main(){
double x,y,x1,y1;
cout<<endl<<"Dati partea reala a primului numar complex:";
cin>>x;
cout<<endl<<"Dati aprtea imaginara pentru primul nr complex:";
cin>>y;
Complex z(x,y);
cout<<endl<<"Primul numar complex este:";
z.afisare();
Complex ob;
ob=z+z1;
cout<<endl<<"Suma celor 2 numere complexe este:";
ob=z-z1;
cout<<endl<<"Diferenta celor 2 numere complexe este:";
ob=z*z1;
cout<<endl<<"Produsul celor 2 numere complexe este:";
ob=z/z1;
cout<<endl<<"Raportul celor 2 numere complexe este:";
ob.afisare();
cout<<endl;
}