Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma warning (disable 4996)
- #include <iostream>
- #include <conio.h>
- using namespace std;
- class Student {
- private:
- char *nume;
- int nota;
- public:
- //constructor implicit cu parametri impliciti
- Student(char *nume = "NA", int nota = 5);
- //constructor de copiere
- Student(const Student &s);
- //destructor
- ~Student();
- //functie care returneaza numele
- char * getNume();
- //functie care returneaza nota
- int getNota();
- //functie de modificare a numelui
- void setNume(char *nume);
- //functie de modificare a notei
- void setNota(int nota);
- //functie de afisare
- void afis();
- //functie de citire
- void citeste();
- };
- class Catalog {
- private:
- int nr;
- Student *s;
- public:
- Catalog(int n);
- ~Catalog();
- void afis();
- void citeste();
- };
- void main() {
- int k;
- cout << "Introduceti numarul de studenti: " << endl;
- cin >> k;
- Catalog ceva(k);
- ceva.citeste();
- ceva.afis();
- _getch();
- }
- Student::Student(char *nume, int nota) {
- this->nume = new char[strlen(nume) + 1];
- strcpy_s(this->nume, strlen(nume) + 1, nume);
- this->nota = nota;
- }
- Student::Student(const Student &v) {
- this->nume = new char[strlen(nume) + 1];
- strcpy_s(this->nume, strlen(nume) + 1, v.nume);
- this->nota = v.nota;
- }
- Student::~Student() {
- if (nume != 0)
- delete nume;
- }
- char* Student::getNume() {
- return nume;
- }
- int Student::getNota() {
- return nota;
- }
- void Student::setNume(char * nume) {
- this->nume = nume;
- }
- void Student::setNota(int nota) {
- this->nota = nota;
- }
- void Student::afis() {
- cout << "Studentul " << nume << " are nota " << nota << endl;
- }
- void Student::citeste() {
- char n1[30];
- cout << endl<< "Introduceti numele studentului: " << endl;
- cin >> n1;
- nume = new char[strlen(n1) + 1];
- strcpy_s(nume, strlen(nume), n1);
- cout <<endl<< "Introduceti nota studentului: " << endl;
- cin >> nota;
- }
- Catalog::Catalog(int nr) {
- this->nr = nr;
- s = new Student[this->nr];
- }
- Catalog::~Catalog() {
- if (s != 0)
- delete s;
- }
- void Catalog::citeste() {
- for (int i = 0; i < nr; i++) {
- s[i].citeste();
- }
- }
- void Catalog::afis() {
- for (int i = 0; i < nr; i++) {
- s[i].afis();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement