Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma warning(disable:4996)
- #include <conio.h>
- #include <iostream>
- #include <stdlib.h>
- #include <stdio.h>
- using namespace std;
- class Student {
- private:
- char *nume;
- int nota;
- public:
- Student(char *nume = 0, int nota = 0);
- Student(const Student &s);
- // Student();
- ~Student();
- char* getNume();
- int getNota();
- void SetNume(char *nume);
- void SetNota(int nota);
- void afis();
- void citeste();
- };
- Student::Student(char *nume, int nota) {
- if (nume != NULL) {
- this->nume = new char[strlen(nume) + 1];
- strcpy_s(this->nume, strlen(nume) + 1, nume);
- }
- else this->nume = NULL;
- this->nota = nota;
- }
- Student::Student(const Student &s) {
- this->nume = new char[strlen(s.nume) + 1];
- strcpy(this->nume, s.nume);
- this->nota = s.nota;
- }
- char *Student::getNume() {
- return this->nume;
- }
- int Student::getNota() {
- return nota;
- }
- Student::~Student() {
- if (nume != NULL)
- delete nume;
- }
- void Student::SetNume(char *nume) {
- strcpy(this->nume, nume);
- }
- void Student::SetNota(int nota) {
- this->nota = nota;
- }
- void Student::afis() {
- if (nume != NULL)
- cout << nume << ": " << nota << endl;
- }
- void Student::citeste() {
- char aux[75];
- cout << "Nume: ";cin >> aux;
- this->nume = new char[strlen(aux) + 1];
- strcpy(this->nume, aux);
- cout << "Nota: ";cin >> nota;
- cout << endl;
- }
- class Catalog {
- private:
- int nr;
- Student *s;
- public:
- Catalog(int n);
- ~Catalog();
- void afis();
- void Citeste();
- };
- Catalog::Catalog(int n) {
- this->nr = n;
- s = new Student[nr];
- }
- Catalog::~Catalog() {
- if (nr != 0)
- delete s;
- }
- void Catalog::afis() {
- for (int i = 0;i < nr;i++) {
- // cout << i + 1 << "." << s[i].getNume << ": " << s[i].getNota;
- s[i].afis();
- }
- }
- void Catalog::Citeste() {
- for (int i = 0;i < nr;i++) {
- // cout << "Student" << i << "." << endl;
- s[i].citeste();
- }
- }
- void main() {
- Catalog classA(3);
- classA.Citeste();
- classA.afis();
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement