MUHAMMAD AL-XORAZMIY NOMIDAGI
TOSHKENT AXBOROT TEXNOLOGIYALARI
UNIVERSITETI
Radio va mobil aloqa fakulteti
Dasturlash fani boʻyicha
4-Labaratoriya ishi
Bajardi:830-21 guruh talabasi
Hamroyev Husniddin
Tekshirdi:Rustamova .M.Y
Variant N_9
1.Kastyum va shim class larini yarating va ularni bog’lovchi funksiyalar yarating.
#include
#include
#include
using namespace std;
class Kostyum{
public :
int narxi;
string rangi;
string firma;
string davlati;
void QiymatKirit(int narx, string rang, string firm, string davlat){
narxi = narx;
rangi = rang;
firma = firm;
davlati = davlat;
}
int FindMaxPrice(Kostyum kostyum[], int narxi){
int max = kostyum[0].narxi;
for(int i = 1; i < narxi; i++){
if(kostyum[i].narxi > max)
max = kostyum[i].narxi;
}
return max;
}
void ChopEt(){
cout << "Narxi : " << narxi << endl;
cout << "Rangi : " << rangi << endl;
cout << "Firma : " << firma << endl;
cout << "Davlati : " << davlati << endl;
}
};
class shim{
public :
int narxi;
string rangi;
string firma;
string davlati;
void QiymatKirit(int narx, string rang, string firm, string davlat){
narxi = narx;
rangi = rang;
firma = firm;
davlati = davlat;
}
int FindMaxPrice(shim Shimlar[], int narxi){
int max = Shimlar[0].narxi;
for(int i = 1; i < narxi; i++){
if(Shimlar[i].narxi > max)
max = Shimlar[i].narxi;
}
return max;
}
void ChopEt(){
cout << "Narxi : " << narxi << endl;
cout << "Rangi : " << rangi << endl;
cout << "Firma : " << firma << endl;
cout << "Davlati : " << davlati << endl;
}
};
int main()
{
int n1, N1, n2, N2;
string r1, f1, d1, r2, f2, d2;
cout << "Kostyumlar sonini kiriting : "; cin >> N1;
Kostyum objects[N1];
Kostyum object2;
for(int i = 0; i < N1; i++){
cout << i + 1 << " - Kostyum xususiyatlari : \n";
cout << "Narxini kiriting :"; cin >> n1;
cout << "Rangini kiriting :"; cin >> r1;
cout << "Firmani kiriting :"; cin >> f1;
cout << "Davlatini kiriting :"; cin >> d1;
objects[i].QiymatKirit(n1, r1, f1, d1);
}
cout << "Shimlar sonini kiriting : "; cin >> N2;
shim shobjects[N2];
shim shobject2;
for(int i = 0; i < N2; i++){
cout << i + 1 << " - Shim xususiyatlari : \n";
cout << "Narxini kiriting :"; cin >> n2;
cout << "Rangini kiriting :"; cin >> r2;
cout << "Firmani kiriting :"; cin >> f2;
cout << "Davlatini kiriting :"; cin >> d2;
shobjects[i].QiymatKirit(n2, r2, f2, d2);
}
cout << "\nKostyumlar xususiyatlari : \n\n";
for(int i = 0; i < N1; i++){
cout << "\n" << i + 1 << " - Kostyum xususiyatlari : \n";
objects[i].ChopEt();
}
cout << "\nShimlar xususiyatlari : \n\n";
for(int i = 0; i < N2; i++){
cout << "\n" << i + 1 << " - Kostyum xususiyatlari : \n";
shobjects[i].ChopEt();
}
cout << "\nEng qimmat kostyum : " << object2.FindMaxPrice(objects, N1);
cout << "\nEng qimmat shim : " << shobject2.FindMaxPrice(shobjects, N2);
getch();
return 0;
}
2.Odam sinfini yarating. Unda kamida 5 ta maydon va ularni ekranga chiqaruvchi, qayta ishlovchi usullarni yarating.
#include
using namespace std;
class odam
{
public:
string millati;
int yoshi;
string familiyasi;
string ismi;
string jinsi;
};
int main(){
odam ob1, ob2, ob3 ,ob4, ob5;
ob1.millati="Ozbek";
ob1.yoshi=18;
ob1.familiyasi="Hamroyev";
ob1.ismi="Husniddin";
ob1.jinsi="erkak\n\n";
ob2.millati="qozoq";
ob2.yoshi=20;
ob2.familiyasi="Yuldashev";
ob2.ismi="Qambar";
ob2.jinsi="erkak\n\n";
ob3.millati="Ozbek";
ob3.yoshi=18;
ob3.familiyasi="Razzoqov";
ob3.ismi="Maqsud";
ob3.jinsi="erkak\n\n";
ob4.millati="rus";
ob4.yoshi=25;
ob4.familiyasi="Romanova";
ob4.ismi="Natasha";
ob4.jinsi="ayol\n\n";
ob5.millati="Ozbek";
ob5.yoshi=17;
ob5.familiyasi="Mamasoatov";
ob5.ismi="Samandar";
ob5.jinsi="erkak";
cout<<"Shaxsning millati- "<
cout<<"Shaxsning yoshi- "<
cout<<"SHaxsning familiyasi- "<
cout<<"Shaxsning ismi- "<
cout<<"Jinsi- "<
cout<<"Shaxsning millati- "<
cout<<"Shaxsning yoshi- "<
cout<<"SHaxsning familiyasi- "<
cout<<"Shaxsning ismi- "<
cout<<"Jinsi- "<
cout<<"Shaxsning millati- "<
cout<<"Shaxsning yoshi- "<
cout<<"SHaxsning familiyasi- "<
cout<<"Shaxsning ismi- "<
cout<<"Jinsi- "<
cout<<"Shaxsning millati- "<
cout<<"Shaxsning yoshi- "<
cout<<"SHaxsning familiyasi- "<
cout<<"Shaxsning ismi- "<
cout<<"Jinsi- "<
cout<<"Shaxsning millati- "<
cout<<"Shaxsning yoshi- "<
cout<<"SHaxsning familiyasi- "<
cout<<"Shaxsning ismi- "<
cout<<"Jinsi- "<
return 0;
}
3.Silindir sinfi yaratilsin va konstruktor e’lon qilinsin . Unda kamida uchta maydon va ularni ekranga chiqaruvchi va qayta ishlovchi sinf metodlarini yarating.
#include
#include
using namespace std;
class silindr
{
private:
int a,b;
public:
silindr()
{
cout<< "konstruktor ishlayapti"<
}
silindr(int r,int h){
a=r;
b=h;
}
double yon_sirti(int r,int h)
{
double s;
s=2*M_PI*r*h;
return s;
}
double tola_sirt(int r,int h)
{
double S;
S=2*M_PI*r*(r+h);
return S;
}
double hajm(int r,int h)
{
double V;
V=M_PI*r*r*h;
return V;
}};
int main() {
silindr ob1,ob2,ob3;
cout<< "yon_sirti: "<
cout<< "tola_sirti:"<
cout<< "hajmi:"<
}
4.Guruxdagi o’quvchilarning familiyasi, ismi ma’lum bo’lsa, “A” va “N” xarfi bilan boshlanuvchi o’quvchilarning ro’yxatini chop etuvchi dastur tuzing.
#include
#include
#include
using namespace std;
int main (){
char satr[][50]={"Azamat",
"Nilufar", "Maqsud", "Samandar",
"Husniddin", "Alimardon", "Nizomiddin",
"Azizbek", "Narimon", "SHodmonqul"};
char A[]="A";
char N[] = "N";
for(int i=0;i<10; i++)
if(strncmp(satr[i], A, 1)==0)
cout<<"A harfi bilan boshlanadigan talabalar- "<
cout << "\n \n";
for(int i=0;i<10; i++)
if(strncmp(satr[i], N, 1)==0)
cout<<"N harfi bilan boshlanadigan oquvchilar- "<
}
Do'stlaringiz bilan baham: |