1-TopshiriqTalaba nomli sinf yarating. Tarkibida ikkita metod, ikkita xossa bo’lsin. Talaba yoshini getYosh metodi orqali jo’nating
Download 16.39 Kb.
|
Dasturlash mustaqil ish2
- Bu sahifa navigatsiya:
- 2-topshiriq. Futbol komandasi nomli sinf yarating. Tarkibida 2 ta metod, 3 ta xossa bo’lsin. Jamoa sardorini getSardor() metodi orqali jo’nating
- 3-topshiriq. Mashina nomli sinf yarating. Tarkibida 2 ta metod, 4 ta xossa, 2 ta konstruktor, 1 ta destruktor bo’lsin
- 5+ - topshiriq. Mashina nomli sinf yarating. Uning bosib o’tgan yo’liga qarab yoqilg’i sarfini aniqlash metodi bo’lsin.
1-TopshiriqTalaba nomli sinf yarating. Tarkibida ikkita metod, ikkita xossa bo’lsin. Talaba yoshini getYosh() metodi orqali jo’nating #include using namespace std; class Talaba { private: int m_age; string m_name; public: Talaba() { m_age = 30; m_name="Sherozbek"; } //Parametrli konstruktor Talaba(int yosh, string ism) { m_age = yosh; m_name = ism; } int getAge() {return m_age;} string getIsm() {return m_name;} }; int main() { Talaba getYosh(10,"Sherozbek"); cout<<"Yoshi: " << getYosh.getAge() << endl; cout<<"Ismi: " << getYosh.getIsm() << endl; return 0; } 2-topshiriq. Futbol komandasi nomli sinf yarating. Tarkibida 2 ta metod, 3 ta xossa bo’lsin. Jamoa sardorini getSardor() metodi orqali jo’nating #include using namespace std; class fudbolchi { public: string m_ismi; string m_club_nomi; double m_maoshi; void print() { cout< }; int main() { fudbolchi today{"Ranaldo","Real Madrid",340000}; today.m_ismi="Messi"; today.m_club_nomi= "Barselona"; today.m_maoshi = 350000; today.print(); return 0; } 3-topshiriq. Mashina nomli sinf yarating. Tarkibida 2 ta metod, 4 ta xossa, 2 ta konstruktor, 1 ta destruktor bo’lsin #include using namespace std; class Mashina { public: string m_rusum; string m_rangi; double m_yili; double m_narxi; void print() { cout< }; int main() { Mashina today{"Mustang","Qizil",2020,100000}; today.m_yili=2022; today.m_narxi= 110000; today.print(); return 0; } 4-topshiriq. Futbol komandasi nomli sinf yarating. Tarkibida 2 ta metod, 4 ta xossa, 2 ta konstruktor, 1 ta destruktor bo’lsin #include class Futbols { public:
Futbols () { m_nomi[0] = "Barselona"; m_nomi[1] = "Real madrid"; m_nomi[2] = "Atletiko"; m_orni[0] = 1; m_orni[1] = 2; m_orni[2] = 3; m_achko[0] = 45; m_achko[1] = 42; m_achko[2] = 41; m_gollari[0] = 70; m_gollari[1] = 78; m_gollari[2] = 65; } void malumot() { cout<<"Fudbol jamoalari nomi\n 1.Barselona\n 2.Real madrid \n 3.Atletiko"< Futbols (string fut_nom) { for(int i=0; i<=2; i++) {
void print() { cout<<"Assalomu alaykum. \nSiz tanlagan jamoa "< }
int main()
5-topshiriq. Talaba nomli sinf yarating. Tarkibida public, private spetsifikatorlari orqali metodlar va xossalar e’lon qiling. Ulardan asosiy dasturda foydalaning. #include using namespace std; class Car{
int main(){ Car A(0.06,"Malibu"); int S; cout<<"Bosoib o'tilgan masofani kiriting: "; cin>>S; cout << "yoqilg'i sarfi:" << A.getValue(S) << " litr"<< endl; return 0; } Download 16.39 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling