Здравствуйте, если кому не сложно поправьте пожалуйста код.
Код |
#include "iostream" #include <string.h>
using namespace std;
class Base // bazovyy class soderzhit vse obschie { // polya i methody protected: char Naimenovanie[50]; char Areal_obitania[50]; int Temperatura_sodergania; int Vlagnost; int Vrema_life; int Reproduktivniy_vozrast; public: Base(void); // constructor virtual void Input(void) = 0; // method vvoda virtual void Print(void) = 0; // method vyvoda
/* opisanie drugih methodov, naprimer: */ virtual int Type(void) = 0; // tip objecta (Cat=1, Dog=2) int GetVlagnost(void); // uznat' Vlagnost int LessThan(Base * p); // sravnit' nicki (menshe chem) };
Base::Base(void) : Temperatura_sodergania(0), Vlagnost(0), Vrema_life(0), Reproduktivniy_vozrast(0) { Naimenovanie[0] = 0; Areal_obitania[0] = 0; } int Base::GetVlagnost(void) { return Temperatura_sodergania, Vlagnost(0), Vrema_life, Reproduktivniy_vozrast; }
int Base::LessThan(Base*p) { return strcmp(Naimenovanie, p->Naimenovanie) < 0; }
class Ratenia : public Base { private: char Sposob_razmnogenia[50]; char Nalichie_plodov[5]; /*äà èëè íåò*/ public: Rastenia(void); void Input(void); void Print(void); int Type(void) {return 1; } };
class Ribi : public Base { private: char Tip_vodi[20]; public: Ribi(void); void Input(void); void Print(void); int Type(void) { return 2; } };
Rastenia::Rastenia(void); { Sposob_razmnogenia[0] = 0; Nalichie_plodov[0] = 0; }
void Rastenia::Input(void) { cout << "Please, input Rastenie info\nRastenie\t| Naimenovanie: "; cin >> Naimenovanie; cout << "\t| Areal_obitania: "; cin >> Areal_obitania; cout << "\t| Sposob_razmnogenia: "; cin >> Sposob_razmnogenia; cout << "\t| Nalichie_plodov: "; cin >> Nalichie_plodov; cout << "\t| Tip_rastenia: "; cin >> Tip_rastenia; cout << "\t| Temperatura_sodergania: "; cin >> Temperatura_sodergania; cout << "\t| Vlagnost: "; cin >> Vlagnost; cout << "\t| Vrema_life: "; cin >> Vrema_life; cout << "\t| Reproduktivniy_vozrast: "; cin >> Reproduktivniy_vozrast; }
void Rastenia::Print(void); { cout << "\nRastenie\t| Naimenovanie: " << Naimenovanie << "\n\t| Areal_obitania: " << Areal_obitania << "\n\t| Sposob_razmnogenia: " << Sposob_razmnogenia << "\n\t| Nalichie_plodov: " << Nalichie_plodov << "\n\t| Tip_rastenia: " << Tip_rastenia << "\n\t| Temperatura_sodergania: " << Temperatura_sodergania << "\n\t| Vlagnost: " << Vlagnost << "\n\t| Vrema_life: " << Vrema_life << "\n\t| Reproduktivniy_vozrast: " << Reproduktivniy_vozrast <<"\n" ; }
Ribi::Ribi(void) : { Tip_vodi[0] = 0; }
void Ribi::Input(void) { cout << "Please, input Ribi info\nRibi\t| Naimenovanie: "; cin >> Naimenovanie; cout << "\t| Areal_obitania: "; cin >> Areal_obitania; cout << "\t| Tip_vodi: "; cin >> Tip_vodi; cout << "\t| Temperatura_sodergania: "; cin >> Temperatura_sodergania; cout << "\t| Vlagnost: "; cin >> Vlagnost; cout << "\t| Vrema_life: "; cin >> Vrema_life; cout << "\t| Reproduktivniy_vozrast: "; cin >> Reproduktivniy_vozrast; }
void Ribi::Print(void) { cout << "\nRastenie\t| Naimenovanie: " << Naimenovanie << "\n\t| Areal_obitania: " << Areal_obitania << "\n\t| Tip_vodi: " << Tip_vodi << "\n\t| Temperatura_sodergania: " << Temperatura_sodergania << "\n\t| Vlagnost: " << Vlagnost << "\n\t| Vrema_life: " << Vrema_life << "\n\t| Reproduktivniy_vozrast: " << Reproduktivniy_vozrast <<"\n"; }
void Sort (Base * A[], int N) { int i, j; Base * p;
for (i = N-1; i > 0; i--) for (j = 0; j < i; j++) if (A[i]->LessThan(A[j])) // sravnenie objectov pri { // pomoschi metoda p = A[i]; A[i] = A[j]; A[j] = p; } }
void Filter(Base * A[], int N) // vyvod po priznaku { int i, j;
cout << "Vvedite vlagnost: "; cin >> j; for (i = 0; i < N; i++) if (A[i]->GetVlagnost() == j) A[i]->Print(); }
void FilterType(Base * A[], int N, int tip) // vyvod po tipu { int i, j;
for (i = 0; i < N; i++) if (A[i]->Type() == tip) // proverka tipa A[i]->Print(); }
int main(void) { Base * A[20]; int N =0;
char key, key2; Base * p; int i, j;
do { cout << "\n\n 1 dobavit'\n 2 udalit'\n 3 pechatat'\n" " 4 iskat'\n 5 sortirovat'\n 0 vyhod\n>>"; cin >> key;
switch (key) // proverka nazhatoy klavishi { case '1': // dobavlenie if (N >= 20) { cout << "net mesta!\n"; break; } cout << "Dobavit':\n 1 Rastenie\n 2 Ribu\n>>"; cin >> key2; if (key2 == '1') p = new Rastenie; // sozdaem object Rastenie else if (key2 == '2') p = new Riba; // sozdaem object Riba else { cout << "nepravilno nazhali!\n"; break; // i vyhodim }
if (p) // yesly object sozdalsa, to { p->Input(); // vyzyvaem vvod objecta s klaviatury A[N] = p; // zanosim ego v massiv N++; // uvelichivaem kolichestvo objectov } else cout << "pamyaty ne hvataet!\n"; break; case '2': // udalenie cout << "Udalit':\nvvedite nomer ot 0 do " << N-1 << ": "; cin >> i; if (i < 0 || i >= N) cout << "nepravilnyy nomer!\n"; else { delete A[i]; // unichtozhaem element for (; i < N-1; i++) // sdvigaem ostalnye chtob A[i] = A[i+1]; // v massive nebylo "dyrki" N--; // umenshaem kolichestvo objectov } break; case '3': // prosmotr if (!N) // yesli net objectov - soobschaem cout << "Prosmotr: net objectov!\n"; else for (i = 0; i < N; i++) // dlya vseh objectov A[i]->Print(); // vyzyvaem method vyvoda break; case '4': // poisk cout << "Poisk:\n 1 vse Rastenia\n 2 vse Ribi\n 3 po Naimenovanie\n>>"; cin >> key2; if (key2 == '1') FilterType(A, N, 1); // vyvod vseh Rastenii else if (key2 == '2') FilterType(A, N, 2); // vyvod vseh Rib else if (key2 == '3') Filter(A, N); // filtraciya po priznaku else cout << "nepravilno nazhali!\n"; break; case '5': // sortirovka Sort(A, N); break;
case '0': // vyhod break; default: cout << "nepravilno nazhali!\n"; break; } } while (key != '0'); // rabotaem poka ne nazhat 0
for (i = 0; i < N; i++) // unichtozhaem vse objecty delete A[i];
cout << "Poka!\n"; }
|
Журнал компиляции:
Êîìïèëÿòîð: Default compiler
Âûïîëíåíèå g++.exe...
g++.exe "C:\Users\Performance\Desktop\LS2.cpp" -o "C:\Users\Performance\Desktop\LS2.exe" -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
C:\Users\Performance\Desktop\LS2.cpp: In member function `int Base::GetVlagnost()':
C:\Users\Performance\Desktop\LS2.cpp:34: error: `((Base*)this)->Base::Vlagnost' cannot be used as a function
C:\Users\Performance\Desktop\LS2.cpp: At global scope:
C:\Users\Performance\Desktop\LS2.cpp:49: error: ISO C++ forbids declaration of `Rastenia' with no type
C:\Users\Performance\Desktop\LS2.cpp:66: error: `Rastenia' has not been declared
C:\Users\Performance\Desktop\LS2.cpp:66: error: expected constructor, destructor, or type conversion before ';' token
C:\Users\Performance\Desktop\LS2.cpp:67: error: expected unqualified-id before '{' token
C:\Users\Performance\Desktop\LS2.cpp:67: error: expected `,' or `;' before '{' token
C:\Users\Performance\Desktop\LS2.cpp:72: error: `Rastenia' has not been declared
C:\Users\Performance\Desktop\LS2.cpp: In function `void Input()':
C:\Users\Performance\Desktop\LS2.cpp:75: error: `Naimenovanie' undeclared (first use this function)
C:\Users\Performance\Desktop\LS2.cpp:75: error: (Each undeclared identifier is reported only once for each function it appears in.)
C:\Users\Performance\Desktop\LS2.cpp:77: error: `Areal_obitania' undeclared (first use this function)
C:\Users\Performance\Desktop\LS2.cpp:79: error: `Sposob_razmnogenia' undeclared (first use this function)
C:\Users\Performance\Desktop\LS2.cpp:81: error: `Nalichie_plodov' undeclared (first use this function)
C:\Users\Performance\Desktop\LS2.cpp:83: error: `Tip_rastenia' undeclared (first use this function)
C:\Users\Performance\Desktop\LS2.cpp:85: error: `Temperatura_sodergania' undeclared (first use this function)
C:\Users\Performance\Desktop\LS2.cpp:87: error: `Vlagnost' undeclared (first use this function)
C:\Users\Performance\Desktop\LS2.cpp:89: error: `Vrema_life' undeclared (first use this function)
C:\Users\Performance\Desktop\LS2.cpp:91: error: `Reproduktivniy_vozrast' undeclared (first use this function)
C:\Users\Performance\Desktop\LS2.cpp: At global scope:
C:\Users\Performance\Desktop\LS2.cpp:94: error: `Rastenia' has not been declared
C:\Users\Performance\Desktop\LS2.cpp:95: error: expected unqualified-id before '{' token
C:\Users\Performance\Desktop\LS2.cpp:95: error: expected `,' or `;' before '{' token
C:\Users\Performance\Desktop\LS2.cpp: In constructor `Ribi::Ribi()':
C:\Users\Performance\Desktop\LS2.cpp:109: error: expected identifier before '{' token
C:\Users\Performance\Desktop\LS2.cpp:109: error: expected `(' before '{' token
C:\Users\Performance\Desktop\LS2.cpp: In function `int main()':
C:\Users\Performance\Desktop\LS2.cpp:205: error: `Rastenie' has not been declared
C:\Users\Performance\Desktop\LS2.cpp:208: error: `Riba' has not been declared
Это сообщение отредактировал(а) kot070 - 13.4.2014, 19:34