Oto program:
#include <iostream>
#include <string>
using namespace std;
class Tstudent{
public:
string Nazwisko;
int Nr_indexu;
int Liczba_ocen;
double* Oceny;
Tstudent(const Tstudent &in);
Tstudent();
Tstudent(string nazw, int index);
Tstudent(string nazw, int index, int l_ocen, double *stopnie);
~Tstudent();
int Wypisz();
int operator== (const Tstudent &s);
void operator>> (const Tstudent &s);
void operator<< (const Tstudent &s);
};
int operator== (Tstudent &s, Tstudent &d){
if( (s.Nazwisko==d.Nazwisko) && (s.Nr_indexu==d.Nr_indexu) ){
return 0;
}
return 1;
};
void operator>> (Tstudent &s,int a){
cout << s.Nazwisko << " " << s.Nr_indexu << endl;
for(a=0;a<=s.Liczba_ocen;a++){
cout << s.Oceny[a] << " ";
}
cout << endl;
};
void operator<< (Tstudent &s, int a){
cout << "Podaj nazwisko : ";
cin >> s.Nazwisko;
cout << endl << "Podaj nr indexu : ";
cin >> s.Nr_indexu;
cout << endl << "Podaj liczbe ocen : ";
cin >> s.Liczba_ocen;
cout << endl;
};
Tstudent::Tstudent(){
Nazwisko="0";
Nr_indexu=0;
Liczba_ocen=0;
Oceny=NULL;
}
Tstudent::Tstudent(string nazw, int index){
Nazwisko=nazw;
Nr_indexu=index;
Liczba_ocen=0;
Oceny=NULL;
}
Tstudent::Tstudent(string nazw, int index, int l_ocen, double *stopnie){
Nazwisko=nazw;
Nr_indexu=index;
Liczba_ocen=l_ocen;
Oceny=new double[l_ocen];
for (int i=0; i<l_ocen; i++)
Oceny=stopnie;
}
Tstudent::Tstudent(const Tstudent &in) {
Nazwisko = in.Nazwisko;
Nr_indexu = in.Nr_indexu;
Liczba_ocen = in.Liczba_ocen;
if(Liczba_ocen != 0) {
Oceny = new double[Liczba_ocen];
for(int i = 0; i < Liczba_ocen; i++)
Oceny = in.Oceny;
}
}
int Tstudent::Wypisz(){
cout<<Nazwisko<<" "<<Nr_indexu<<" "<<Liczba_ocen;
for(int i=0;i<Liczba_ocen;i++){
cout<<" "<<Oceny;
}
cout<<"
";
}
Tstudent::~Tstudent(){
if (Oceny!=NULL) delete Oceny;
}
class Nowa_Klasa : public Tstudent{
string Imie;
string Wydzial;
Nowa_Klasa();
Nowa_Klasa(string nazw, string im);
Nowa_Klasa(string nazw, int index);
Nowa_Klasa(string nazw, string im, string wydz, int index);
};
Nowa_Klasa::Nowa_Klasa():Tstudent() {}
Nowa_Klasa::Nowa_Klasa(string nazw, string im):Tstudent(nazw) {Imie=im;}
Nowa_Klasa::Nowa_Klasa(string nazw, int index):Tstudent(nazw,index){}
Nowa_Klasa::Nowa_Klasa(string nazw, string im, string wydz, int index):Tstudent(nazw,index)
{Imie=im;Wydzial=wydz;}
int main(){
Tstudent Grupa1[20];
Tstudent Kazio ("Nowak", 2349);
double T[2]={3.5,4};
Tstudent Jasio ("Kowalski", 3480, 2, T);
Tstudent Wicio(Jasio);
Tstudent Stasio;
Stasio = Kazio;
int a;
a= Stasio==Kazio; //jeżeli 0 to te same dane, a jeżeli 1 to inne
Stasio<<a;
Kazio<<a;
Kazio>>a;
cin>>a;
cout << a << endl;
Jasio. Wypisz();
Stasio. Wypisz();
Kazio. Wypisz();
Wicio. Wypisz();
double O[3]={2,3,4.5};
Nowa_Klasa Zbyszko ("Michalski", 2345, 3, O, "Zbigniew", "W-4");
system("PAUSE");
return 0;
}