Amaliy ish bo’yicha sinov savollari
1.
Klavyatura va sichqoncha class larini yarating va ularni bog‘lovchi metodlar
yarating.
#include
#include
using namespace std;
// Klavyatura sinfi
class Klavyatura {
public:
// Konstruktor
Klavyatura(string brand, string model) {
this->brand = brand;
this->model = model;
}
// Bog'lovchi metodlar
void press_key(char key) {
cout << brand << " " << model << " klavyaturasida " << key << " tugmasi
bosildi." << endl;
}
private:
string brand;
string model;
};
// Sichqoncha sinfi
class Sichqoncha {
public:
// Konstruktor
Sichqoncha(string brand, string model) {
this->brand = brand;
this->model = model;
}
// Bog'lovchi metodlar
void press_button(int button_number) {
cout << brand << " " << model << " sichqonchasida " << button_number
<< " tugma bosildi." << endl;
}
private:
string brand;
string model;
};
int main() {
// Klavyatura va sichqoncha obyektlari yaratiladi
Klavyatura keyboard("Logitech", "K480");
Sichqoncha mouse("Logitech", "M325");
// Obyektlarning metodlari chaqiriladi
keyboard.press_key('A');
mouse.press_button(1);
return 0;
}
Dastur natijasi:
|