Conan
Moderator
 Inregistrat: acum 17 ani
Postari: 198
|
|
/*sa se implementeze clasa student avand ca atribute nume, prenume, nota1, nota 2, si ca metode un constructor cu parametrii, functii de acces pentru toate atributele si o metoda care det nota maxima*/
#include <iostream.h> #include <conio.h>
class student { private: char* nume; char* prenume; float nota1,nota2; public: student(char* n, char* p,float n1, float n2); char* getnume(); char* getprenume(); float getn1(); float getn2(); void setnume(char* s); void setprenume(char* s); void setn1(float nr); void setn2(float nr); float notamax(); };
student::student(char* n, char* p,float n1, float n2) { nume=n; prenume=p; nota1=n1; nota2=n2; }
char* student::getnume() { return nume; }
char* student::getprenume() { return prenume; }
float student::getn1() { return nota1; }
float student::getn2() { return nota2; }
void student::setnume(char* s) { nume=s; }
void student::setprenume(char* s) { prenume=s; }
void student::setn1(float nr) { nota1=nr; }
void student::setn2(float nr) { nota2=nr; }
float student::notamax() { if (nota1>nota2) return nota1; else return nota2; }
void main() { clrscr(); student s("voinea","lucian",9,10); cout<<s.getnume()<<" "<<s.getprenume()<<" "<<s.getn1()<<" "<<s.getn2()<<endl; cout<<"Nota max="<<s.notamax()<<endl; s.setnume("dima" ); s.setprenume("stefan" ); s.setn1(8); s.setn2(7); cout<<s.getnume()<<" "<<s.getprenume()<<" "<<s.getn1()<<" "<<s.getn2()<<endl; cout<<"Nota max="<<s.notamax()<<endl; getch(); }
|
|