1-TopshiriqTalaba nomli sinf yarating. Tarkibida ikkita metod, ikkita xossa bo’lsin. Talaba yoshini getYosh metodi orqali jo’nating


Download 16.39 Kb.
Sana22.12.2022
Hajmi16.39 Kb.
#1041973
Bog'liq
Dasturlash mustaqil ish2



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
#include
using namespace std;

class Futbols {

public:
string m_nomi[3];
int m_orni[3];
int m_achko[3];
int m_gollari[3];
int tanlash;

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++) {
if(fut_nom == m_nomi[i]) {
tanlash = i;
}
}
}

void print() {

cout<<"Assalomu alaykum. \nSiz tanlagan jamoa "<cout<<"\nJamoa egallagan o'rni "<}
~Futbols(){
cout << "Destruktor ishga tushdi";

}
};

int main()
{
Futbols jamoa;
jamoa.malumot();
string kirit;
cout<<"Jamoa nomini tanlang:\n ---> ";
getline(cin,kirit);
Futbols obyekt(kirit);
jamoa.print();
return 0;
}

5-topshiriq. Talaba nomli sinf yarating. Tarkibida public, private spetsifikatorlari orqali metodlar va xossalar e’lon qiling. Ulardan asosiy dasturda foydalaning.

#include
#include
using namespace std;
class Talaba{
private:
string FIO;
int guruhi;
int yoshi;
public:
Talaba()
{
FIO = "Toshboltayev Sheroz Sayfiddin o'g'li";
guruhi = 317;
yoshi = 21;
}
string getFIO() { return FIO; }
int getguruhi() { return guruhi; }
int getyoshi() { return yoshi; }
void setDate(string m_FIO, int m_guruhi, int m_yoshi) {
FIO = m_FIO;
guruhi = m_guruhi;
yoshi = m_yoshi;
}
};
int main()
{
string a;
int b, c;
cout << "FIO ni kiriting : "; getline(cin,a);
cout << "Guruhni kiriting: "; cin >> b;
cout << "Yoshni kiriting: "; cin >> c;
Talaba drob;
drob.setDate(a,b,c);
cout <<"Talaba FIO - " << drob.getFIO() << "\nGuruhi - " << drob.getguruhi() << "\nTalaba yoshi - " << drob.getyoshi()<< '\n';
return 0;
}
5+ - topshiriq. Mashina nomli sinf yarating. Uning bosib o’tgan yo’liga qarab yoqilg’i sarfini aniqlash metodi bo’lsin.

#include

using namespace std;

class Car{
private:
string name;
float extra;
public:
Car(){
name = "NaN";
extra = 0.0;
}
Car(float extra,string name){
this->extra=extra;
this->name=name;
}
int getValue(int S){
return S*extra;
}
};

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'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling