No to generalnie tak, główny program wygląda tak, może bajzel, ale jest to wersja robocza, na początek chciałbym, żeby działało:
#include <cstdlib>
#include <iostream>
#include "osoba.h"
#include "pracownik.h"
#include "student.h"
#include "emeryt.h"
#include "rektor.h"
using namespace std;
void poprosDane()
{
cout << "Podaj dane osoby w formacie: imie nazwisko rok_studiow :" << endl;
}
int main(int argc, char *argv[])
{
int rok;
string imie, nazwisko;
int buffer;
int type;
int size;
int n = 0;
string czy;
bool next = true;
cout << "Podaj ilosc wpisywanych osob:";
cin >> size;
Osoba tablica[size];
//Petla wczytujaca osoby
while(next)
{
next = false;
cout << "Podaj kategorie:"
<< endl << "(1) pracownik"
<< endl << "(2) student"
<< endl << "(3) emeryt"
<< endl << "(4) rektor"
<< endl;
cin >> type;
switch(type)
{
case 1:
poprosDane();
cin >> imie >> nazwisko >> rok;
tablica[n] = Pracownik(imie, nazwisko, rok);
cout << "Podaj pensje: " << endl;
cin >> buffer;
tablica[n].ustalPensje(buffer);
cout << "Ustalona pensja to: " << (int)tablica[n].podajPensje() << endl;
cout << "Calkowity dochod po obliczeniu premii, wynosi: " << tablica[n].dochod() << endl;
break;
case 2:
tablica[n] = Student();
cout << "Poda wysokosc stypendium: " << endl;
cin >> buffer;
tablica[n].ustalStypendium(buffer);
cout << "Ustalona wysokosc stypendium to: " << tablica[n].podajStypendium() << endl;
cout << "Po odliczeniu podatku, dochod studenta wynosic bedzie: " << tablica[n].dochod() << endl;
break;
case 3:
break;
case 4:
break;
}
cout << "Wprowadzasz dalej? [t] / [n]:" << endl;
cin >> czy;
if (czy != "t") { next = false; }
n = n + 1;
}
system("PAUSE");
return EXIT_SUCCESS;
}
A nie działa.
Klasa osoba wygląda tak:
#include <string.h>
class Osoba
{
public:
void ustalImie(char* i) { strcpy(imie,i); }
void ustalNazwisko(char* n) { strcpy(nazwisko,n); }
void ustalRokUr(int r) { rokur=r; }
const char* podajImie() { return imie; }
const char* podajNazwisko() { return nazwisko; }
int podajRokUr() { return rokur; }
void ustalDane(char* i, char* n, int r)
{
ustalImie(i);
ustalNazwisko(n);
ustalRokUr(r);
}
Osoba(char* i, char* n, int r)
{
ustalDane(i,n,r);
}
//virtual methods
virtual double dochod(){}
virtual void ustalPensje( int pensja ){}
virtual int podajPensje(){}
virtual void ustalStypendium(){}
virtual int podajStypendium(){}
Osoba() {};
private:
char imie[40];
char nazwisko[40];
int rokur;
};
A np. klasa Pracownik wyglada tak:
class Pracownik : public Osoba
{
private:
int pensja;
public:
Pracownik(char* i, char* n, int r)
{
Osoba :: Osoba(i, n, r);
}
void ustalPensje( int pensja )
{ this -> pensja = pensja; }
int podajPensje()
{ return this -> pensja; }
double podajPremie()
{ return 0,2 * this -> pensja; }
double dochod()
{ return (this -> pensja + this -> podajPremie()) - (this -> pensja + this -> podajPremie() * 0,19); }
};
Patent jest taki, że MUSZĘ, taki mam prikaz, zrobić zunifikowaną tablicę, zawierającą różne typy, mam wyjść z klasy Osoba, jednak każda klasa dziedzicząca po osobie jest i tak obcinana. Kompilator nie widzi w Podklasie konstruktora, który wywołuje, albo metod które znajdują sie tylko i wyłącznie w danej podklasie. Czy to co chcę zrobić jest niewykonalne czy źle się do tego zabieram?