TINCHLIKOV ELDOR
22. Mashina rusumi, yoqilg’i sarfi, bosib o’tgan masofasi kabi xossalarga ega Car (Avtomobil) ajdod sinfini yarating. Malibu sinfini Car sinfidan meros olgan holda yarating. Mashina rangi, narxi xossalarini qo’shing. Mashina to’lovini qancha muddatda to’lash mumkinligin aniqlash medotini hosil qiling.
#include
using namespace std;
class Car{
protected:
string m_model;
float m_fuel;
int m_dst;
public:
Car(string model="",float fuel=0,int dst=0){
m_model=model;
m_fuel=fuel;
m_dst=dst;
}
};
class Malibu:public Car{
protected:
string m_color;
float m_prize;
public:
Malibu(string model="",float fuel=0,int dst=0,string color="",float prize=0):
Car(model,fuel,dst){
m_color=color;
m_prize=prize;
}
string getModel(){
return m_model;
}
float getFuel(){
return m_fuel;
}
int getDst(){
return m_dst;
}
float getCredit(int n){ // n-muddat (oy)
n=n/12+1;
for(int i=0; im_prize = m_prize/10+m_prize; // 10%lik ustama.
}
return m_prize;
}
void getDate(int n=1){
int day=300;
if(n<5000){
day = 6-n%1000;;
cout<<"Malibuni "<}
else{
cout<<"Malibuni bugun olasiz."<}
}
};
int main() {
Malibu car("Malibu2", 15, 0, "black", 45000);
cout<<"36 oy uchun kredit: "<<(int)car.getCredit(36)<<"$"<car.getDate(4000);
return 0;
}
|
40. Minstry (Vazirlik) nomli ajdod sinf hosil qiling. Uning tarkibida vazirlik nomini aniqlaydigan virtual metod bo’lsin. SportMinistry, EducationMinistry kabi avlod sinflar hosil qilib, unga ajratilgan davlat byudjetini chop etadigan metod yarating.
#include
using namespace std;
class Ministy{
protected:
string m_name;
string m_minister;
public:
Ministy(string name, string minister){
m_name = name;
m_minister = minister;
}
virtual string getMinister(){
return m_minister;
}
};
class SportMinister:public Ministy{
int m_budget;
public:
SportMinister(string name, string minister, int a):
Ministy(name, minister){
m_budget = a;
}
virtual int getBudget(){
return m_budget;
}
string getName(){
return m_name;
}
};
class EducationMinister:public Ministy{
int m_budget;
public:
EducationMinister(string name, string minister, int a):
Ministy(name, minister){
m_budget = a;
}
virtual int getBudget(){
return m_budget;
}
string getName(){
return m_name;
}
};
int main()
{
SportMinister A1("Sport Vazirligi", "E.Tinchlikov", 900000000);
EducationMinister A2("Ta'lim Vazirligi", "Bermurod K.", 500000000);
cout<cout<return 0;
}
|
Do'stlaringiz bilan baham: |