Apelsin so’zidan “qirqib olish” va “yopishtirish” lar orqali
Ushbu: nomer, kelish vaqti, chiqish vaqti, yo ’nalishi, masofa
Download 59.58 Kb.
|
Algoritmik tillar va dasturlash
- Bu sahifa navigatsiya:
- Ushbu
Ushbu: nomer, kelish vaqti, chiqish vaqti, yo ’nalishi, masofa maydonlariga ega Poyezd sinfini tuzing. Elementlari Poyezd obyektlaridan iborat massiv yarating. Har bir poyezdning o’rtacha tezligi topilsin.
#include #include #include using namespace std; class Train { private: int number; string departureTime; string arrivalTime; string route; int distance; public: Train() {} Train(int num, string depTime, string arrTime, string rt, int dist) { number = num; departureTime = depTime; arrivalTime = arrTime; route = rt; distance = dist; } int getNumber() { return number; } string getDepartureTime() { return departureTime; } string getArrivalTime() { return arrivalTime; } string getRoute() { return route; } int getDistance() { return distance; } double getAverageSpeed() { double timeInHours = (stod(arrivalTime.substr(0, 2)) + (stod(arrivalTime.substr(3, 2))) / 60) - (stod(departureTime.substr(0, 2)) + (stod(departureTime.substr(3, 2))) / 60); double averageSpeed = (distance / timeInHours); return averageSpeed; } }; int main() { Train trains[3] = { Train(1, "06:00", "10:30", "Tashkent-Samarkand", 344), Train(2, "08:30", "12:45", "Tashkent-Andijan", 432), Train(3, "11:45", "16:15", "Samarkand-Navoiy", 230) }; for (int i = 0; i < 3; i++) { cout << "Train " << trains[i].getNumber() << ", " << "Departure Time: " << trains[i].getDepartureTime() << ", " << "Arrival Time: " << trains[i].getArrivalTime() << ", " << "Route: " << trains[i].getRoute() << ", " << "Distance: " << trains[i].getDistance() << " km, " << "Average Speed: " << trains[i].getAverageSpeed() << " km/h." << endl; } return 0; } Ushbu: familiya, ismi, otasining ismi, lavozimi, jinsi, ishga olingan kuni maydonlaridan tashkil topgan Ishchi sinfini tuzing. Elementlari Ishchi obyektlaridan iborat massiv yarating. Ishchilarni familiyasi bo’yicha saralang va eng ko’p stajga ega ishchini toping. #include #include #include using namespace std; using namespace std; struct Ishchi { string familiya; string ismi; string otasining_ismi; string lavozimi; string jinsi; string ishga_olingan_kun; }; int main() { const int SIZE = 5; Ishchi ishchilar[SIZE]; for (int i = 0; i < SIZE; i++) { cout << "Ishchi #" << i+1 << " ma'lumotlarini kiriting:\n"; cout << "Familiya: "; cin >> ishchilar[i].familiya; cout << "Ismi: "; cin >> ishchilar[i].ismi; cout << "Otasining ismi: "; cin >> ishchilar[i].otasining_ismi; cout << "Lavozimi: "; cin >> ishchilar[i].lavozimi; cout << "Jinsi: "; cin >> ishchilar[i].jinsi; cout << "Ishga olingan kun: "; cin >> ishchilar[i].ishga_olingan_kun; cout << endl; } for (int i = 0; i < SIZE-1; i++) { for (int j = 0; j < SIZE-1-i; j++) { if (ishchilar[j].familiya > ishchilar[j+1].familiya) { Ishchi temp = ishchilar[j]; ishchilar[j] = ishchilar[j+1]; ishchilar[j+1] = temp; } } } int max_staj = 0; int max_staj_index = 0; for (int i = 0; i < SIZE; i++) { int staj_yili; cout << "Ishchi #" << i+1 << "ning staj yilini kiriting: "; cin >> staj_yili; if (staj_yili > max_staj) { max_staj = staj_yili; max_staj_index = i; } } cout << "Ishchilar: " << endl; for (int i = 0; i < SIZE; i++) { cout << i+1 << ". " << ishchilar[i].familiya << " " << ishchilar[i].ismi << ", " << ishchilar[i].lavozimi << endl; } cout << "\nEng ko'p stajga ega ishchi: " << ishchilar[max_staj_index].familiya << " " << ishchilar[max_staj_index].ismi << ", " << ishchilar[max_staj_index].lavozimi << endl; return 0; } Ushbu: familiya, tug’ilgan kuni, tug’ligan mamlakati, amplua, sariq kartalar soni, o ’yinlar soni- maydonlariga ega Player sinfini tuzing. Elementlari Player obyektlaridan iborat massiv yarating. 20 yoshdan katta va sariq kartalari 10 ta o’yinda 1 tadan ko’p bo’lmagan o’yinchilarni toping. #include #include #include using namespace std; class Player{ private: string familiya; string tugilgan_kuni; string tugilgan_mamlakat; string amplua; int sariq_kartalar_soni; int o_yinlar_soni; public: Player(string f, string t, string tm, string a, int sks, int oys){ familiya = f; tugilgan_kuni = t; tugilgan_mamlakat = tm; amplua = a; sariq_kartalar_soni = sks; o_yinlar_soni = oys; } string getFamiliya(){return familiya;} string getTugilganKuni(){return tugilgan_kuni;} string getTugilganMamlakat(){return tugilgan_mamlakat;} string getAmplua(){return amplua;} int getSariqKartalarSoni(){return sariq_kartalar_soni;} int getOYinlarSoni(){return o_yinlar_soni;} }; int main(){ Player players[5] = { Player("Ivanov", "12.05.1990", "Russia", "Forward", 3, 8), Player("Petrov", "01.01.1988", "Ukraine", "Goalkeeper", 1, 6), Player("Sidorov", "03.02.1992", "Russia", "Defender", 4, 10), Player("Smith", "07.11.1994", "USA", "Midfielder", 2, 7), Player("Lee", "25.08.1991", "South Korea", "Midfielder", 5, 12) }; int count = 0; for(int i = 0; i < 5; i++){ if(players[i].getSariqKartalarSoni() <= 10 && players[i].getOYinlarSoni() > 1){ count++; cout << count << ". " << players[i].getFamiliya() << endl; } } return 0; } Download 59.58 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling