2-Amaliyot ishi Mavzu



Yüklə 29,03 Kb.
səhifə4/4
tarix30.11.2022
ölçüsü29,03 Kb.
#71593
1   2   3   4
Xf6Ylwqc4n9y973kh9Y6McGrqhDWW6n5Vexd0JqW

Klasslar

Klass – bu dasturchi tomonidan ixtiyoriy kiritilgan mavjud tiplar asosida yaratilgan strukturalangan toifa hisoblanadi. Klasslar lokal va global o‘zgaruvchilar va ular ustida amal bajaradigan funksiyalar to‘plamidan iborat bo‘lishi mumkin. Klasslar quyidagicha tasvirlanadi:


class klass_nomi{
;

};
Klasslarga oid misol:
#include
using namespace std;
class daraxt
{
public:
unsigned int uzunligi ;
unsigned int yoshi;
int o_sish(int i){
i++;
return i;
};
};
int main()
{
int k=2;
daraxt olma_daraxt;
olma_daraxt.uzunligi=5;
olma_daraxt.yoshi=7;
cout<
system("pause");
}
Natija: 3

Class class_name


{
Data Members;
Methods;
}
struct type_name {
member_type1 member_name1;
member_type2 member_name2;
member_type3 member_name3;
} object_names;

1.
#include


using namespace std;
class rectangle
{
public:
int length;
int height;
};
int main( )
{
rectangle rect;
int p;
cin>>rect.height;
cin>>rect.length;
p =rect.height + rect.length ;
cout << "perimeter of rectangle : " << p<2. #include


using namespace std;
struct student
{
char name[50];
int age;
};
int main()
{
student Group;
cout << "Enter Full name: ";
cin.get(Group.name, 50);
cout << "Enter age: ";
cin >> Group.age;
cout << "\nDisplaying Information" << endl;
cout << "Name: " << Group.name << endl;
cout <<"Age: " << Group.age << endl;
}

3. #include


using namespace std;
int sum(int a,int b){
int x=a+b;
cout<return x;
}
int main(){
int h;
h=sum(2,4);
}

4. #include


using namespace std;
int main(){
int a;
char b[12];
string v="dfdfd";
cin.getline(b,50);
cin.get(b,13);
getline(cin,v);
gets(b);
cin>>v;
cout<cout<}
5. #include
using namespace std;
int main()
{ char ch='D';
cout<<" char-"<int x=456561;
cout<<" int -"<float f=65.321;
cout<<" floa- "<double d=54.6451;
cout<<"double- "<bool b=false;
cout<<" boolean-"<return 0;}

6.
#include


using namespace std;
class Area
{
private:
int a;
int b;
public:
Area(): a(5), b(2){ }
void GetLength()
{
cout << "Enter length and height ";
cin >> a >> b;
}
int AreaCalculation() { return (a * b); }
void DisplayArea(int temp)
{
cout << "Area: " << temp;
}
};

int main()


{ Area A1, A2;
int x;
A1.GetLength();
x = A1.AreaCalculation();
A1.DisplayArea(x);

cout << endl << "Default Area when value is not taken from user" << endl;


x = A2.AreaCalculation();
A2.DisplayArea(x);
return 0;
}
7.
#include
using namespace std;
class rectangle {
private:
int a;
int b;
public:
void setvalue(){
cin>>a;
cin>>b;
}
void s ()
{
cout<<"result\t"<}
};
int main()
{ rectangle r;
int c;
r.setvalue();
r.s();
}

8.
#include


using namespace std;
class rectangle
{
public:
int length;
int height;
};

int main( )


{
rectangle rect;
int p;
cin>>rect.height;
cin>>rect.length;
p =rect.height + rect.length ;
cout << "perimeter of rectangle : " << p<}
9.
#include
#include
using namespace std;
class person
{
public:
string name;
int age;
void output()
{
cout<<"Riskaliyeva "<}
};
int main()
{ person student;
cin>>student.name;
cin>>student.age;
cout<<"Name: "<student.output();
return 0;
}

10.
#include


using namespace std;
struct Person
{ char name[50];
int age;
};
Person getData(Person);
void displayData(Person);
int main()
{
Person p;
p = getData(p);
displayData(p);
return 0;
}
Person getData(Person p)
{
cout << "Enter Full name: ";
cin.get(p.name, 50);
cout << "Enter age: ";
cin >> p.age;
return p;
}
void displayData(Person p) {
cout << "\nDisplaying Information." << endl;
cout << "Name: " << p.name << endl; cout <<"Age: " << p.age << endl;
}
11.
#include
using namespace std;
struct student
{
char name[50];
int age;
};
void dataDisplay(student f)
{
cout << "\nDisplaying Information." << endl;
cout << "Name: " << f.name << endl;
cout <<"Age: "<< f.age << endl;
}
student interData(student )
{student g;
cout << "Enter Full name:";
cin.get(g.name,50);
cout << "Enter age:";
cin >> g.age;
return g;
}
int main()
{
student h ;
dataDisplay(interData(h));
return 0;
}
12.
#include
using namespace std;
struct address {
int houseno;
char street[30];
char city[20];
char state[20];
};
struct student {
char name[20];
address a;
};
int main()
{
student student1;

cout<<"student Name: "; gets(student1.name);


cout<<"House No: "; cin>>student1.a.houseno;
cout<<"Street: "; cin>>student1.a.street;
cout<<"City: "; cin>>student1.a.city;
cout<<"State: "; cin>>student1.a.state;
cout<<"\n";
{ cout<<"\nstudent Data:\n";
cout<<"\nName: "<cout<<"\nAddress: "<cout<cout<cout<cout<<"\n";
}
}

13.
#include


using namespace std;
struct Distance
{ int feet;
float inch;
};
int main()
{
Distance *ptr, d;
ptr = &d;
cout << "Enter feet: ";
cin>> (*ptr).feet;
cout << "Enter inch: ";
cin >> (*ptr).inch;
cout << "Displaying information." << endl;
cout << "Distance = " << (*ptr).feet << " feet " << ptr->inch << " inches";
return 0;
}

14.
#include


using namespace std;
struct student
{
char name[50];
int age;
};
void dataDisplay(student);
int main()
{
student s;
cout << "Enter Full name: ";
cin.get(s.name, 50);
cout << "Enter age: ";
cin >> s.age;
dataDisplay(s);
return 0;
}
void dataDisplay(student s )
{ cout << "\nDisplaying Information." << endl;
cout << "Name: " << s.name << endl; cout <<"Age: " << s.age << endl;
}

15.
#include


using namespace std;
struct student
{
char name[50];
int age;
};
int main()
{
student Group;
cout << "Enter Full name: ";
cin.get(Group.name, 50);
cout << "Enter age: ";
cin >> Group.age;
cout << "\nDisplaying Information" << endl;
cout << "Name: " << Group.name << endl;
cout <<"Age: " << Group.age << endl;
}
MASSIV

type name [elements]; type arrayName [ arraySize ];
1.
#include
using namespace std;
int A [] = {3, 5, 8, 9, 10};
int i, S;
int main ()
{
for ( i=0 ; i<5 ; i++ )
{
S +=A[i];
}
cout << S;
}

2.
#include
using namespace std;
void print(int A[][3],int N, int M)
{ int R,C;
for (R = 0; R < N; R++)
for (C = 0; C < M; C++)
cout << A[R][C];
}
int main ()
{
int arr[4][3] ={{12, 29, 11},{25, 25, 13},{24, 64, 67},{11, 18, 14}};
print(arr,4,3);
return 0;
}



Topshiriq

Variantlar:



  1. Berilgan sonlar ketma-ketligidagi maksimal va minimal elementlarning o‘rnini almashtiring.

  2. Berilgan sonlar ketma-ketligidagi har bir elementni o‘zi, o‘zidan oldingi va o‘zidan keyingi element bilan yig‘indisiga almashtiring.

  3. k-darajagacha bo‘lgan Nyuton binomi sonlaridan vektor hosil qiling. Nyuton binomi sonlari quyidagicha aniqlanadi.

1 1
1 2 1 2
1 3 3 1 3
1 4 6 4 1 …
1 5 10 10 5 1 k

  1. nxn matritsaning yuqori chap uchburchagidagi elementlaridan vektor hosil qiling

  2. nxn matritsaning yuqori o‘ng uchburchagidagi elementlaridan vektor hosil qiling

  3. nxn matritsaning pastki o‘ng uchburchagidagi elementlaridan vektor hosil qiling

  4. nxn matritsaning pastki chap uchburchagidagi elementlaridan vektor hosil qiling

  5. Matritsani matritsaga ko‘paytiring

  6. Jadval hosil qiling va unga ma’lumotlarni kiriting, ekranga chiqaring.

  7. Talabalar ism-familiyasi, yoshi va ballaridan iborat jadval yarating va talabalarni ism-familiyasini alfavit bo‘yicha tartibga keltiring.

  8. 10-variantdagi jadvaldan bali bo‘yicha eng katta va eng kichik talabalarning o‘rnini almashtiring

  9. 2 ta bir xil tipdagi jadval berilgan. Ikkala jadvalni o‘zaro solishtiring va aynan bir xil bo‘lgan yozuvlarni o‘chiring.

  10. Birlashma tipidagi (tipda 2 ta element e’lon qiling) 2 ta o‘zgaruvchini bir-biridan farqli elementlariga qiymat bering va ularning yig‘indisini ikkala o‘zgaruvchining qiymat berilmagan elementlariga o‘zlashtiring. Har ikkala o‘zgaruvchining barcha elementlarini ekranga chiqaring va natijani tushuntiring.

  11. Avtomobil nomli klass yarating va unda turli o‘zgaruvchi va funksiyalar yarating. Ushbu klassdan foydalanib, turli markali avtomobillar uchun o‘zgaruvchilarni yaratib, ular haqida ma’lumotlar kiritib, ekranga chiqaring.

  12. Berilgan matnli fayldan simvollarni o‘qib, ekranga chiqaring va raqamlarni ajratib ko‘rsating.

  13. Berilgan matnli faylda a harfi necha marta qatnashganini sanang.

  14. Berilgan matnli fayldagi satrlar sonini aniqlang.

  15. Talabalar ism-familiyasi, yoshi va ballari maydonidan iborat klass yarating va talabalar ro‘yhatini tuzing. So‘ralayotgan talaba ro‘yhatda bor yo‘qligini aniqlang.

  16. Oy nomlaridan iborat sanaladigan toifa yarating. So‘ralayotgan oy qaysi faslga tegishliligini aniqlang.

  17. Mahsulot nomlaridan iborat elementlar va ularning qiymati sifatida narxlari kiritilgan sanaladigan toifa yarating. So‘ralayotgan narxda qanday mahsulot yoki mahsulotlar to‘plamini xarid qilsa bo‘ladi, shuni aniqlash dasturini tuzing.

  18. Kiritilgan ismning harflarini alfavit bo‘yicha tartibga keltiring.

  19. Satrli toifadagi vektor berilgan. Bir xil qiymatdagi elementlarni aniqlang, ekranga chiqaring.

  20. Berilgan ismlardan imlo qoidasiga mos ravishda familiyalar hosil qiling.

  21. Berilgan satrda nechta undosh harflar borligini aniqlang.

  22. Berilgan satrdagi sonlar yig‘indisini aniqlang.

  23. F faylda berilgan satr necha marta uchrashini aniqlang.

  24. G fayldan nusxa ko‘chiring.

  25. F fayldan matritsa hosil qiling, ya’ni fayldagi har bir qator matritsaning satri va qatordagi ‘#’ belgisi bilan ajratilgan satrlar ustunlar qilib belgilansin.

  26. Matritsaning juft va toq elementlaridan 2 ta vektor hosil qiling.

Massivdagi tub sonlarni va indekslarini ekranga chiqaring.

Yüklə 29,03 Kb.

Dostları ilə paylaş:
1   2   3   4




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin