Amaliy ish Mavzu: Qoidalar tizimini ishlab chiqish. Oila a`zolari o`rtasidagi ishlab chiqish. Ishdan maqsad
Download 87.7 Kb.
|
3-amaliy Mirjonov O
Dastur kodi:
#include #include #include using namespace std; int main () { string ism1 = "Doniyor",ism2= "Begzod",ism3 = "Azimjon", ism4 = "Eldorbek",ism5 = "Hafiza"; int i,k;
cout<<"1 - "< cout<<"5 - "< cout<<"1 dan 5 gacha 2 ta son kiriting : "; cin>>i>>k;
switch(i+k) { case 3:
cout<<"Kursdosh"; break; case 4:
cout<<"Amakivachcha"; break; case 5:
cout<<"aka uka"; break; case 6:
cout<<"Ona bola"; break; case 7:
cout<<"sinfdosh"; break; case 8:
cout<<"Opa singil"; break; case 9:
cout<<"Ona bola"; break; return 0; Dastur kodi: #include #include #include #include {
protected: int ID;
string gender; public:
Person (string name, int ID, string gender) { this-> name = name; this-> ID = ID; this-> gender = gender; }
{ return name; } const int getID () { return ID; } const string getGender () { return gender; } vector }; class Male: public Person { public:
Male (string name, int ID, string gender) : Person(name, ID, gender) { } void addWife (Person *arr [], string p1, string p2); void displayWifeChildren (Person *arr[], string p1) { int SIZE = 10; int i = 0; int j = 0; cout << "Children of " << p1 << "\n"; while (i < wife.size () ) { cout << i + 1 << " " << wife [i] << "\n"; j = 0; for(int k = 0; k < SIZE; k++) { if(arr [k] -> getName() == wife[i]) { while (j < arr [k] -> children.size () ) { cout << "\t" << arr [k] -> children [j] << "\n"; j++; } } } i++; } } private: vector }; class Female: public Person { public:
Female (string name, int ID, string gender) : Person(name, ID, gender) { } void addChild (Person *arr [], string p1, string p2, string p3); private:
vector };
{ int SIZE = 10; cout << "\nThe people in the system are...\n"; for(int i = 0; i < SIZE; i++) { cout << arr[i] -> getName () << " " << arr [i] -> getID () << " " << arr [i] -> getGender () << "\n"; } cout << "\n"; }
{ int SIZE = 10; for (int i = 0; i < SIZE; i++) { if(arr[i]-> getName () == p1) { wife. push_back (p2); } }
void Female:: addChild (Person *arr[], string p1, string p2, string p3) { int SIZE = 10; for (int i = 0; i < SIZE; i++) { if(arr[i]-> getName () == p2) { children. push_back (p3); } }
/* void displayChildren (Person *arr[], string p1) { int SIZE = 10; for (int i = 0; i < SIZE; i++) { if (arr [i] -> getName () == p1) { cout << "Children of " << arr [i] -> getName () << " are "; ((Male *) arr [i]) -> displayWifeChildren (arr); } } cout << "\n"; } */ int main() {
Person *arr[SIZE];
arr [1] = new Female ("Sevara", 2, "F"); arr [2] = new Female ("Oydin", 3, "F"); arr [3] = new Female ("Hafiza", 4, "F"); arr [4] = new Male ("Islomjon", 5, "M") ; arr [5] = new Male ("Jovoh", 6, "M"); arr [6] = new Male ("Mehroj", 7, "M"); arr [7] = new Male ("Ismoil", 8, "M"); arr [8] = new Female ("Rayhona", 9, "F"); arr [9] = new Male ("Ubaydullo", 10, "M"); displayAll(arr); Male *m = (Male *) arr[0]; m -> addWife(arr, "Ibrohim", "Rayhona"); /// Rayhona Ibrohimning rafiqasi m -> addWife (arr, "Ibrohim", "Oydin"); m -> addWife (arr, "Ibrohim","Hafizaxon"); Female *f1 = (Female *) arr[1]; f1 -> addChild(arr, "Ibrohim", "Sevara", "Islomjon"); /// Islom - Ibrohim va Sevaraning farzandi Female *f2 = (Female *) arr[2]; f2 -> addChild(arr, "Ibrohim", "Oydin", "Mehroj"); f2 -> addChild(arr, "Ibrohim", "Oydin", "Ubaydullo"); Female *f3 = (Female *) arr[3]; f3 -> addChild(arr, "Ibrohim", " Hafiza", " Jovoh"); m-> displayWifeChildren(arr, "Ibrohim"); /* displayChildren(arr, "Ibrohim"); /// Ibrohimning barcha farzandlarini aks ettiradi va har bir bolani xotiniga guruhlaydi */ cout << "\nPress enter (or Ctrl-C) to quit ... " << endl; cin.get();
{ if ( arr [i] != NULL) { delete arr[i]; }
return 0; }} Download 87.7 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling