Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class LUDZIE {
- protected:
- int ilosc;
- string *imiona;
- public:
- LUDZIE(int _ilosc): ilosc(_ilosc) {
- imiona = new string[ilosc];
- if(imiona == NULL) {
- cerr << "brak pamieci";
- exit(1);
- }
- }
- void dopiszKlan(string nazwa) {
- for(int i=0; i<ilosc; i++) {
- imiona[i] += "(" + nazwa + ")";
- }
- }
- ~LUDZIE() {
- delete[] imiona;
- }
- };
- class KUZNIA {
- protected:
- int ilosc;
- string *arsenal;
- public:
- KUZNIA(int _ilosc): ilosc(_ilosc) {
- arsenal = new string[ilosc];
- if(arsenal == NULL) {
- cerr << "brak pamieci";
- exit(1);
- }
- }
- ~KUZNIA() {
- delete[] arsenal;
- }
- };
- class RYCERZE: public LUDZIE, public KUZNIA {
- private:
- string nazwa_armii;
- public:
- RYCERZE(int ludzie, int kuznie, string nazwa): LUDZIE(ludzie), KUZNIA(kuznie) {
- nazwa_armii = nazwa;
- }
- friend istream& operator >> (istream&, RYCERZE&);
- void operator ~ () {
- cout << "Imiona = [ ";
- for(int i=0; i<LUDZIE::ilosc; i++) {
- cout << LUDZIE::imiona[i] << ", ";
- }
- cout << "]\n";
- cout << "Arsenal = [ ";
- for(int i=0; i<KUZNIA::ilosc; i++) {
- cout << KUZNIA::arsenal[i] << ", ";
- }
- cout << "]\n";
- }
- void Przygotuj() {
- srand(time(NULL));
- cout << "\nWynik metody Przygotuj():\n";
- for(int i=0; i<LUDZIE::ilosc; i++) {
- cout << LUDZIE::imiona[i] << " -> " << KUZNIA::arsenal[rand()%KUZNIA::ilosc] << endl;
- }
- }
- };
- int main()
- {
- RYCERZE *rycerze = new RYCERZE(5, 3, "mala armia");
- string nazwaKlanu;
- cout << "Podaj nazwe klanu: ";
- cin >> nazwaKlanu;
- cin >> *rycerze;
- rycerze->dopiszKlan(nazwaKlanu);
- ~*rycerze;
- rycerze->Przygotuj();
- //cin.get();
- //cin.get();
- system("PAUSE");
- return 0;
- }
- istream& operator >> (istream &str, RYCERZE &r) {
- for(int i=0; i<r.LUDZIE::ilosc; i++) {
- cout << "Podaj imie[" << i << "]: ";
- cin >> r.LUDZIE::imiona[i];
- }
- for(int i=0; i<r.KUZNIA::ilosc; i++) {
- cout << "Podaj nazwe broni[" << i << "]: ";
- cin >> r.KUZNIA::arsenal[i];
- }
- return str;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement