Sunteți pe pagina 1din 10

#include <iostream>//c

#include <string>
using namespace std;// c++

class Profesor {
char* numeProfesor;
string materie;
int nrSalarii;
float* salarii;
int nrClase;
string clase[110];//

};

class Student {

// daca nu scriu private e by default private


char* nume;// este un pointer ce gestioneaza adresa unui vector dinamic de
caractere
string facultate;// faculgtate este un obiect de tip string care gestioneaza
un sir de caractere
int nrNote;// o var ce gestioneaza nr de note din vectorul dinamic din
pointerul note
int *note;// un pointer ce gestioneaza adresa de mem a unui vector dinm de
intregi ce reprezinta notele studentului
bool inmatriculat;
const int id;// se declara in clasa si se initiializeaza obligatoriu in
absolut toti constructorii si nu se mai modifica
// -se initializeaza cu 2 pct in mediat dupa lista de parametrii
static int nrStudneti;// cu acest static monitorizezi cati studenti a creat
clasa ta
static int notaMaxima;
public:
static int notaPromovare;// descrie toata clasa .. se declara in clasa si se
initializeaza ina fara clasei

// Student s;
Student() :id(nrStudneti++){

this->note = NULL;
this->nume = new char[strlen("Acest bla bla bla...") + 1];
strcpy(this->nume, "Acest bla bla bla...");
this->facultate = "na";
this->inmatriculat = 0;
this->nrNote = 0;

}
//
//Student s1( "IOnescu ion" csie 1 3
vectnote);
// IOnescu Ion 5 5 69
// yyy csie 1 3 ttt
Student(const char*nu, string fac, bool in, int nrn, int*no) :id(nrStudneti+
+) {

this->nrNote = nrn;
this->note = new int[nrn];
for (int i = 0; i < nrn; i++) {
if (no[i] <= notaMaxima) {
this->note[i] = no[i];
}
else {
note[i] = 10;
}

}
this->nume = new char[strlen(nu) + 1];
strcpy(this->nume, nu);
this->facultate = fac;
this->inmatriculat = in;
}

// acest constructor nu i se genereaza id ul ... il dam noiin lista de


parametri
Student(int iddd,const char*nu, string fac, bool in, int nrn, int*no)
:id(iddd) {

this->nrNote = nrn;
this->note = new int[nrn];
for (int i = 0; i < nrn; i++) {
if (no[i] <= notaMaxima) {
this->note[i] = no[i];
}
else {
note[i] = 10;
}

}
this->nume = new char[strlen(nu) + 1];
strcpy(this->nume, nu);
this->facultate = fac;
this->inmatriculat = in;
}

// IOnescu Ion
// yyy csie
Student(const char*nu, string fac) :id(nrStudneti++) {

this->note = NULL;
this->nume = new char[strlen(nu) + 1];
strcpy(this->nume, nu);
this->facultate = fac;
this->inmatriculat = 0;
this->nrNote = 0;

}
//Student s4(s2); /// constructor de copiere creaza un obiect pe baza altui
obiect deja existent
// in cazul nostru creaza pe s4 pe baza lui s 2
Student(const Student& sursa) :id(nrStudneti++) {

this->nrNote = sursa.nrNote;
this->note = new int[sursa.nrNote];
for (int i = 0; i < sursa.nrNote; i++) {
this->note[i] = sursa.note[i];
}

this->nume = new char[strlen(sursa.nume) + 1];


strcpy(this->nume, sursa.nume);

this->facultate = sursa.facultate;
this->inmatriculat = sursa.inmatriculat;
}

~Student() {
nrStudneti--;
if (note) {
delete[] note;
}
if (nume) {
delete[] nume;
}

//s=s2
Student& operator=(const Student& sursa) {

//dezalocarea

if (note) {
delete[] note;
}
if (nume) {
delete[] nume;
}

this->nrNote = sursa.nrNote;

this->note = new int[sursa.nrNote];


for (int i = 0; i < sursa.nrNote; i++) {
this->note[i] = sursa.note[i];
}
this->nume = new char[strlen(sursa.nume) + 1];
strcpy(this->nume, sursa.nume);

this->facultate = sursa.facultate;
this->inmatriculat = sursa.inmatriculat;
return *this;
}

// Student::setNotaPromovare(4);
static void setNrNotaPrommovare(int nota) {
if (nota > 0) {
notaPromovare = nota;
}
}

// s2.setInmatriculare( true);
void setInmatriculare(bool in) {
inmatriculat = in;
}

// id nu facem set

// s2.setFacultate("Agroalimentara");
void setFacultate(string fac) {
if (fac.length() > 2) {
facultate = fac;
}
}

// s2.setNume("Picurel");
void setNume(const char* nu) {
if (strlen(nu) > 2) {
if (nume) {
delete[] nume;
}
this->nume = new char[strlen(nu) + 1];
strcpy(this->nume, nu);

}
}

// setteri
// s2.setNote(2, vectnote);
void setNote(int nrn, int * no) {
if (nrn > 0) {
if (note) {
delete[] note;
}
this->nrNote = nrn;
this->note = new int[nrn];
for (int i = 0; i < nrn; i++) {
this->note[i] = no[i];
}
}
}

//char* nume;// este un pointer ce gestioneaza adresa unui vector dinamic de


caractere
//string facultate;// faculgtate este un obiect de tip string care
gestioneaza un sir de caractere
//int nrNote;// o var ce gestioneaza nr de note din vectorul dinamic din
pointerul note
//int *note;// un pointer ce gestioneaza adresa de mem a unui vector dinm de
intregi ce reprezinta notele studentului
//bool inmatriculat;
//static int notaPromovare;// descrie toata clasa .. se declara in clasa si
se initializeaza ina fara clasei
//const int id;// se declasa in calsa si se initiializeaza obligatoriu in
absolut toti constructorii si nu se mai modifica
//// se initializeaza cu 2 pct in mediat dupa lista de p[arametrui
//static int nrStudneti;// cu acest static monitorizezi cati studenti a creat
clasa ta

char* getNume() {
return nume;
}
string getFacultate() {
return facultate;
}
int getNrNote() {
return nrNote;
}
int* getNote() {
return note;
}
bool getInmatriculare() {
return inmatriculat;
}

int getId() {
return id;
}

static int getNrStudenti() {


return nrStudneti;
}

static int getNotaPromovare() {


return notaPromovare;
}
static void setNotaMaxima(int n) {
if (n > 0) {
notaMaxima = n;
}
}

//cout<<s2.getMin();
int getMin() {
int min = note[0];
for (int i = 0; i < nrNote) {
if (min > note[1]) {
min = note[i];
}
}
return min;
}

//cout<<s2.getMedie();//metoda generica
float getMedie() {
float m = 0;
for (int i = 0; i < nrNote) {
m += note[i];
}
m = m / nrNote;
return m;
}

// s2.afisare();////metoda generica
void afisare() {
cout << "ID: " << id<<" "<<nume << endl;
cout << "Facultate: " << facultate << endl;
if (inmatriculat == 1) {
cout << "Status: Inamtriculat" << endl;
}
else {
cout << "Status: Neinamtriculat" << endl;
}
cout << "Stundetul are "<<nrNote<<" note, notele: ";
for (int i = 0; i < nrNote; i++) {
cout << note[i] << " ";
}
cout << endl << endl;

// s2.afisare();
friend void afisare1(Student& s) {
cout << "ID: " << s.id << " " << s.nume << endl;
cout << "Facultate: " << s.facultate << endl;
if (s.inmatriculat == 1) {
cout << "Status: Inamtriculat" << endl;
}
else {
cout << "Status: Neinamtriculat" << endl;
}
cout << "Stundetul are " << s.nrNote << " note, notele: ";
for (int i = 0; i < s.nrNote; i++) {
cout << s.note[i] << " ";
}
cout << endl << endl;

void afisare3();

friend void afisare2(Student& s);

// cout<<s2 <<s3;
friend ostream& operator<<(ostream& o,const Student & s) {

o << "ID: " << s.id << " " << s.nume << endl;
o << "Facultate: " << s.facultate << endl;
if (s.inmatriculat == 1) {
o << "Status: Inamtriculat" << endl;
}
else {
o << "Status: Neinamtriculat" << endl;
}
o << "Stundetul are " << s.nrNote << " note, notele: ";
for (int i = 0; i < s.nrNote; i++) {
o << s.note[i] << " ";
}
o << endl << endl;

return o;

//cin>>s2 // obs: Intotdeauna vom face transferul studentului prin referinta


.. ca vrem sa facem modificari pe original
friend istream& operator>>(istream& in, Student& s) {
cout << "Da nume: ";
char buf[150];
in >> buf;
//if (s.nume) {
// delete[] s.nume;
//}
//s.nume = new char[strlen(buf) + 1];
//strcpy(s.nume, buf);
s.setNume(buf);

cout << "Da facultate: ";


in >> s.facultate;

cout << "Da inmatriculare: ";


in >> s.inmatriculat;

cout << "Da nr note: ";


in >> s.nrNote;

if (s.note) {
delete[] s.note;
}
s.note = new int[s.nrNote];
for (int i = 0; i < s.nrNote; i++) {
cout << "Da nota de pe poztia " << i << ": ";
in >> s.note[i];
}

return in;
}

};

int Student::notaPromovare = 5;
int Student::nrStudneti = 0;
int Student::notaMaxima = 10;

void Student::afisare3() {
cout << "ID: " << id << " " << nume << endl;
cout << "Facultate: " << facultate << endl;
if (inmatriculat == 1) {
cout << "Status: Inamtriculat" << endl;
}
else {
cout << "Status: Neinamtriculat" << endl;
}
cout << "Stundetul are " << nrNote << " note, notele: ";
for (int i = 0; i < nrNote; i++) {
cout << note[i] << " ";
}
cout << endl << endl;
}

void afisare2(Student& s) {
cout << "ID: " << s.id << " " << s.nume << endl;
cout << "Facultate: " << s.facultate << endl;
if (s.inmatriculat == 1) {
cout << "Status: Inamtriculat" << endl;
}
else {
cout << "Status: Neinamtriculat" << endl;
}
cout << "Stundetul are " << s.nrNote << " note, notele: ";
for (int i = 0; i < s.nrNote; i++) {
cout << s.note[i] << " ";
}
cout << endl << endl;

}
void main() {
int a;

//int a = 4;
//int v[3] = {4,4,5};

//int * po;
//po = new int[3];
//po = new int;

Student s, s1;
//cout << &s<<&s1 << endl;
//cout << s1.nrNote;
{
Student sssdsds;

string facus2 = "csie";


bool inmats2 = true;
char numes2[111] = { "Ionescu Ion" };//yyy
int nrnotes2 = 3;
int notes2[3] = { 5,5,12 };//ttt
// yyy
Student s2(numes2, facus2, inmats2, nrnotes2, notes2);
//s2.afisare();
// afisare1(s2);
// afisare2(s2);
// s2.afisare3();

//cout << s2.note[1];


Student s3("Gabriel", "Csie");
Student s4(s2);
s4 = s;
Student s5(122,"Paduchel", facus2, inmats2, 3, new int[3]{ 90,34,56 });

//cout << Student::getNrStudenti() << endl;

Student::setNotaMaxima(100);

//cout << s2.getNume() << endl;


for (int i = 0; i < s2.getNrNote(); i++) {
//cout << s5.getNote()[i] << " ";
}
//cout << endl;
//cout << Student::getNrStudenti() << endl;

s3.setNote(4, new int[4]{ 5,6,7,6 });


s.setNote(3, notes2);
s2.setNume("Picurel");
//cout << s2.getNume() << endl;

Student::setNrNotaPrommovare(4);
Student::notaPromovare = 5;
// cout << Student::getNotaPromovare() << endl;
// cout << Student::notaPromovare << endl;
// cout << s2 << s1;

cin >> s;
cout << s;

S-ar putea să vă placă și