Witam.
Mam do zrobienia program, w którym klasy Student i Wykładowca dziedziczą po klasie Osoba. Następnie mam następna klasę Przedmiot. Mam wyświetlić średnie z ocen itd, dla każdego studenta. Więc zrobiłem aby klasa Przedmiot dziedziczyła po klasie Student.
Mam problem ze stworzeniem obiektu i użycia funkcji. Dostaje błąd w linii 160 i 172
"error: no matching function for call to 'Osoba::addInt(std::string&, std::string&, int&, int&, int&, std::string&, int&, int&, std::string&)'|"
"error: no matching function for call to 'Osoba::dodaj(std::string&, std::string&, int&, std::string&)'|"
Na początku w funkcji main mam zakomentowane stworzenie obiektu, które działa poprawnie. Nie wiem jak to przerobić na tablicę żeby działało.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Osoba
{
public:
string imie;
string nazwisko;
int wiek;
Osoba() {}
~Osoba() {}
void dodaj2(string imie, string nazwisko, int wiek)
{
this->imie = imie;
this->nazwisko = nazwisko;
this->wiek = wiek;
}
virtual void drukuj() {};
virtual void addInt() {};
virtual void dodaj() {};
};
class Student : public Osoba
{
public:
int rok;
int nr_indeksu;
string kierunek;
void dodaj(string imie, string nazwisko, int wiek, int rok, int nr_indeksu, string kierunek)
{
dodaj2(imie, nazwisko, wiek);
this->rok = rok;
this->nr_indeksu = nr_indeksu;
this->kierunek = kierunek;
}
void drukuj()
{
cout<<"Imie i nazwisko: "<<imie<<" "<<nazwisko<<endl;
cout<<"Wiek: "<<wiek<<endl;
cout<<"Rok: "<<rok<<endl;
cout<<"Numer indeksu: "<<nr_indeksu<<endl;
cout<<"Kierunek: "<<kierunek<<endl;
}
};
class Wykladowca : public Osoba
{
public:
string tytul;
void dodaj(string imie, string nazwisko, int wiek, string tytul)
{
dodaj2(imie, nazwisko, wiek);
this->tytul = tytul;
}
void drukuj()
{
cout<<"Imie: "<<imie<<endl;
cout<<"Nazwisko: "<<nazwisko<<endl;
cout<<"Wiek: "<<wiek<<endl;
cout<<"Tytul: "<<tytul<<endl;
}
};
class Przedmiot : public Student
{
public:
vector <int> oceny;
vector <int> punkty_ECTS;
vector <string> nazwa_przed;
Przedmiot() {}
~Przedmiot() {}
void addInt(string imie, string nazwisko, int wiek, int rok, int nr_indeksu, string kierunek, int ocena, int punkty, string nazwa)
{
dodaj(imie, nazwisko, wiek, rok, nr_indeksu, kierunek);
oceny.push_back(ocena);
punkty_ECTS.push_back(punkty);
nazwa_przed.push_back(nazwa);
}
void drukuj()
{
cout<<"Imie i nazwisko: "<<imie<<" "<<nazwisko<<endl;
cout<<"Wiek: "<<wiek<<endl;
cout<<"Rok: "<<rok<<endl;
cout<<"Numer indeksu: "<<nr_indeksu<<endl;
cout<<"Kierunek: "<<kierunek<<endl;
for( unsigned int i = 0; i < oceny.size(); i++ )
{
cout << "Ocena: " << oceny[i] << endl;
cout << "Punkty ECTS " << punkty_ECTS[i] << endl;
cout << "Nazwa przedmiotu " << nazwa_przed[i] << endl;
}
cout << endl;
}
};
int main(int argc, char** argv)
{
/*
Przedmiot *obj = new Przedmiot;
obj->addInt("Patryk", "BlaBla", 21, 2017, 1251, "Informatyka", 5, 12, "Pszyra");
obj->drukuj();
Wykladowca *leszek = new Wykladowca;
leszek->dodaj("Leszek", "Belka", 21, "Profsesor");
leszek->drukuj();
*/
int n, wiek, rok, nr_indeksu, ocena, punkty_ECTS,ile_przedmiotow;
char wybor;
string imie, nazwisko, kierunek, tytul, nazwa;
cout<<"Podaj liczbe osob: "<<endl;
cin>>n;
Osoba** tab=new Osoba*[n];
for(int i=0; i<n; i++)
{
cout<<"Kogo chcesz dodac: 0=Student || 1=Wykladowca "<<endl;
cin>>wybor;
switch(wybor)
{
case '0':
cout<<"Podaj imie i nazwisko: "<<endl;
cin>>imie>>nazwisko;
cout<<"Podaj wiek: "<<endl;
cin>>wiek;
cout<<"Podaj rok i numer indeksu: "<<endl;
cin>>rok>>nr_indeksu;
cout<<"Podaj kierunek: "<<endl;
cin>>kierunek;
cout<<"Podaj ilosc przedmiotw: "<<endl;
cin>>ile_przedmiotow;
//tab[i]=new Student(imie, nazwisko, wiek, rok, nr_indeksu, kierunek);
for(int k=0; k<ile_przedmiotow; k++)
{
cout<<"Podaj nazwe: "<<endl;
cin>>nazwa;
cout<<"Podaj ocene i punkty ECTS: "<<endl;
cin>>ocena>>punkty_ECTS;
tab[i]= new Przedmiot;
tab[i]->addInt(imie, nazwisko, wiek, rok, nr_indeksu, kierunek, ocena, punkty_ECTS, nazwa);
}
break;
case '1':
cout<<"Podaj imie i nazwisko: "<<endl;
cin>>imie>>nazwisko;
cout<<"Podaj wiek: "<<endl;
cin>>wiek;
cout<<"Podaj tytul: "<<endl;
cin>>tytul;
tab[i] = new Wykladowca;
tab[i] -> dodaj(imie, nazwisko, wiek, tytul);
break;
}
}
for(int m=0; m<n; m++)
{
tab[m]->drukuj();
}
delete [] tab;
return 0;
}