Swd003-L1 Ibragimova Fariza 6-variant 1-laboratoriya ishi
Download 177.54 Kb.
|
1 laboratoriya
SWD003-L1 Ibragimova Fariza 6-variant 1-laboratoriya ishi Piyola va choynak class larini yarating va ularni bog’lovchi funksiyalar yarating #include using namespace std; namespace CustomNamespace{ int ID_COUNTER = 0; class Piyola{ string Color, Date; int ID; public:
Piyola(string color, string date){ Color = color; Date = date; this->setID(ID_COUNTER); ID_COUNTER++; } Piyola(){} void show(){ cout << "Piyola -> Color: " << Color << "\t" << "Date: " << Date << endl; } void setID(int id){ ID = id; } int getID(){ return ID; } }; class Choynak{ string Color, Brand; int Cost; list
public: Choynak(string color, string brand, int cost){ Color = color; Brand = brand; Cost = cost; } void AddPiyola(Piyola p){ piyola.push_back(p); } void showPiyolalar(){ list ::iterator it = piyola.begin(); for(int i = 0; i < getPiyolaCount(); i++){ (*it).show(); it++;
} } void removePiyola(Piyola p){ list ::iterator it = piyola.begin(); for(int i = 0; i < getPiyolaCount(); i++){ if((*it).getID() == p.getID()){ piyola.erase(it); break; }
} int getPiyolaCount(){ return piyola.size(); } int getCost(){ return (Cost + (Cost/3) * piyola.size()); } }; } using namespace CustomNamespace; int main(){ Choynak choynak = Choynak("Mixed", "UzbekChay", 21000); Piyola piyola[] = {Piyola("Blue","20.02.2003"), Piyola("Yellow","12.02.2012"), Piyola("Green","17.05.2001"), Piyola("Gray","20.11.2012"), Piyola("Black","23.08.2016"), Piyola("Pink","01.12.2018")}; cout << "Hozirda choynak narxi -> " << choynak.getCost() << endl << endl; cout << "Unga piyolalar qo'shamiz" << endl << endl; for(int i = 0; i < 6; i++){ choynak.AddPiyola(piyola[i]); cout << "Hozirda choynak va " << choynak.getPiyolaCount() << " ta piyola narxi -> " << choynak.getCost() << endl; } cout << endl << "Ikkita piyolani olib tashlaymiz" << endl; choynak.removePiyola(piyola[1]); choynak.removePiyola(piyola[4]); cout << endl << "Hozirda qolgan piyolalar: " << endl; choynak.showPiyolalar(); cout << endl << "Hozirda choynak va " << choynak.getPiyolaCount() << " ta piyola narxi -> " << choynak.getCost() << endl; return 0; } 2. #include #include using namespace std; namespace CustomNamespace{ class Vaqt{ int hour, minute, second; public:
Vaqt(int h, int min, int sec){ hour = h; minute = min; second = sec; } Vaqt(){} int getTimeInSeconds(){ return (hour * 3600 + minute * 60 + second); } string getTimeInString(){ stringstream h, min, sec; h << hour; min << minute; sec << second; return (h.str() + ":" + min.str() + ":" + sec.str()); } }; class Mashgulot{ string pair[2]; Vaqt begin, end; string audition; public: Mashgulot(string p[], Vaqt beg, Vaqt en, string aud){ pair[0] = p[0]; pair[1] = p[1]; begin = beg; end = en; audition = aud; } bool Currently(Vaqt currentTime){ if(currentTime.getTimeInSeconds() > this->begin.getTimeInSeconds() && currentTime.getTimeInSeconds() < this->end.getTimeInSeconds()){ } } bool StartsNow(Vaqt currentTime){ if(currentTime.getTimeInSeconds() == this->begin.getTimeInSeconds()){ return true; } return false; } void show(){ cout << "Mashg'ulot -> Juftlik: " << pair[0] << " va " << pair[1] << "\t" << "auditoriya: " << audition << "\t" << "boshlanish vaqti: " << begin.getTimeInString() << "\t" << "tugash vaqti: " << end.getTimeInString() << endl; } };
} using namespace CustomNamespace; int main(){ string pair1[] = {"Kamol","Alisa"}; string pair2[] = {"Asadbek","Jamila"}; string pair3[] = {"Aziz","Mahliyo"}; string pair4[] = {"Ali","Feruza"}; Mashgulot mashgulot[] ={Mashgulot(pair1, Vaqt(16,40,0), Vaqt(18,40,0), "AUDLHG3"), Mashgulot(pair2, Vaqt(12,30,0), Vaqt(14,30,0), "AUDLWE7"), Mashgulot(pair3, Vaqt(7,40,0), Vaqt(9,40,0), "AUDLJK2"), Mashgulot(pair4, Vaqt(20,20,0), Vaqt(22,20,0), "AUDLDS4")}; cout << "Hozirgi vaqtni kiriting" << endl; int hour; cout << "soat: "; cin >> hour; int minute; cout << "daqiqa: "; cin >> minute; int second; cout << "soniya: "; cin >> second; cout << "Hozirda davom etyotgan mashg'ulotlar: " << endl; bool exist = false; for(int i = 0; i < 4; i++){ if(mashgulot[i].Currently(Vaqt(hour,minute,second))){ mashgulot[i].show(); exist = true; } } if(!exist){ cout << "Bu vaqtda hech qanday mashg'ulotlar yo'q" << endl; } cout << "Hozirda davom boshlangan mashg'ulotlar: " << endl; bool exist1 = false; for(int i = 0; i < 4; i++){ if(mashgulot[i].StartsNow(Vaqt(hour,minute,second))){ mashgulot[i].show(); exist1 = true; } } if(!exist1){ cout << "Bu vaqtda hech qanday mashg'ulotlar boshlanmadi" << endl; } return 0; } Download 177.54 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling