O’ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA
KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI
MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT
TEXNOLOGIYALARI UNIVERSITETI QARSHI FILIALI
“KI” FAKULTETI
II – BOSQICH KI 12-22(S) GURUH TALABASINING
DASTURLASH FANIDAN TAYYORLAGAN
4-Amaliy mashg’uloti
Bajardi:
Abdivaliyev.U
Qabul qildi:
Nosirov.B
QARSHI – 2023
10-variant
1.
O`quv xonasi nomli sinfni yarating. Unda kamida 5 ta maydon va ularni
ekranga chiqaruvchi, qayta ishlovchi usullarni yarating.
Dastur kodi:
#include
#include
#include
using namespace std;
class Classroom {
private:
string roomNumber;
int capacity;
vector students;
public:
// Constructor
Classroom(string num, int cap) : roomNumber(num), capacity(cap) {}
// Setters
void setRoomNumber(string num) { roomNumber = num; }
void setCapacity(int cap) { capacity = cap; }
// Add a student to the classroom
void addStudent(string student) {
if (students.size() < capacity) {
students.push_back(student);
cout << student << " sinfga qo'shildi.\n";
} else {
cout << "Sinf to'ldirilgan, " << student << " sinfga qo'shilmadi.\n";
}
}
// Display classroom information
void displayInfo() const {
cout << "Sinf ma'lumotlari:\n";
cout << "Sinf raqami: " << roomNumber << endl;
cout << "Sinf sigimi: " << capacity << " o'quvchi" << endl;
cout << "Hozirgi o'quvchilar:\n";
for (const string& student : students) {
cout << "- " << student << endl;
}
}
};
int main() {
// O'quv xonasi obyekti yaratish
Classroom classroom("101", 30);
// O'quvchilarni sinfga qo'shish
classroom.addStudent("Ali");
classroom.addStudent("Lola");
classroom.addStudent("Husan");
classroom.addStudent("Diana");
classroom.addStudent("Bek");
// Sinfga qo'shilgan o'quvchilarni ko'rish
classroom.displayInfo();
return 0;
}
Dastur natijasi:
Dostları ilə paylaş: |