Sharof rashidov nomidagi samarqand davlat universiteti dasturlash asoslari


Download 0.53 Mb.
bet5/5
Sana13.04.2023
Hajmi0.53 Mb.
#1355114
1   2   3   4   5
Bog'liq
Tursunov Aziz (Dasturlash asoslari fanidan mustaqil ish)

  • struct Talaba
  • {
  • char FISh[30];
  • unsigned int Tug_yil;
  • unsigned int Kurs;
  • char Yunalish[50];
  • float Reyting;
  • char Jinsi[6];
  • char Manzil[50];
  • bool status;
  • };
  • Struktura funksiya argumenti sifatida
  • void Talaba_Manzili(Talaba);
  • int main()
  • {
  • Talaba talaba;
  • talaba.Kurs=2;
  • talaba.Tug_yil=1992;
  • strcpy(talaba.FISh,"Abdullaev A.A.");
  • strcpy(talaba.Yunalish,“Kompyuter injiniring");
  • strcpy(talaba.Jinsi,"Erkak");
  • strcpy(talaba.Manzil,"Toshkent, Yunusobod …");
  • talaba.Reyting=123.52;
  • Talaba_Manzili(talaba);
  • }
  • void Talaba_Manzili(Talaba t)
  • {
  • cout<<"Talaba FISH: "<
  • cout<<"Manzili: "<
  • getch();
  • }
  • Strukturalar massivi (misol)
  • const int n=25;
  • struct Talaba
  • {
  • char FISh[30];
  • unsigned int Tug_yil;
  • unsigned int Kurs;
  • char Yunalish[50];
  • float Reyting;
  • char Jinsi[6];
  • char Manzil[50];
  • bool status;
  • };
  • void Talaba_Kiritish(Talaba t[]);
  • void Talabalar_FISh(Talaba t[]);
  • int main()
  • {
  • Talaba talabalar[n];
  • Talaba_Kiritish(talabalar);
  • Talabalar_FISh(talabalar);
  • getch();
  • return 0;
  • }
  • Strukturalar massivi (misol)
    • void Talabalar_FISh(Talaba t[]){
    • for(int i=0; i
    • cout<
    • }
    • void Talaba_Kiritish(Talaba t[])
    • { for(int i=0; i
    • cout<
    • cout<<"Talaba FISh :";cin.getline(t[i].FISh,30);
    • cout<<"Kurs:"; cin>>t[i].Kurs;
    • cout<<"Reyting bali:";
    • cin>>t[i].Reyting;
    • cout<<"Tugilgan yili:";
    • cin>>t[i].Tug_yil;
    • cout<<"Talim yonalishi:";
    • cin.getline(t[i].Yunalish,50);
    • cout<<"Jinsi(erkak,ayol):";
    • cin.getline(t[i].Jinsi,6);
    • cout<<"Yashash manzili:";
    • cin.getline(t[i].Manzil,50);
    • }
    • }
  • Razryadli maydon
  • include
  • #include
  • struct bit
  • {
  • unsigned int i:1;
  • };
  • unsigned printbits(int c, struct bit pp[])
  • {
  • unsigned int i;
  • unsigned k = 8*sizeof(int);
  • for(i = 0; i < k; i++)
  • {
  • pp[i].i = c&1; printf(" %d", c&1);
  • c>>= 1; } return k; }
  • Razryadli maydonlar ixtiyoriy butun tipga tegishli bo’lishi mumkin. Razryadli maydonlar adresini olish mumkin emas. Xotirada razryadli maydonlarni joylashtirish kompilyator va apparaturaga bog’liq.
  • Razryadli maydonlar yordamida razryadli massivlar hosil qilish mumkin. Yuqorida ko’rilgan son hamma bitlarini chiqarish dasturini quyidagicha yozish mumkin:
  • Razryadli maydon
  • int main()
  • {
  • unsigned int k, i;
  • struct bit pp[100];
  • k = printbits(-5, pp);
  • printf("\n");
  • for(i = k-1; i > 0; i--)
  • printf("%d ", pp[i].i);
  • printf("%d ", pp[0].i);
  • getch();
  • return 0;
  • }
  • #include
  • #include
  • #include
  • int main ()
  • {
  • unsigned char k; int m,n;
  • void binar(unsigned char); /* funksiya prototipi */
  • unsigned char cod(int,int); /* funksiya prototipi */
  • printf("\n m= ");
  • scanf("%d",&m);
  • printf(" n= ");
  • scanf("%d",&n);
  • k=cod(m,n);
  • printf(" cod=%u",k);
  • binar(k);
  • }
  • Dastur matni
  • /* Ikkita butun sonni 16 ga bo’lgandagi qoldiqni baytga o’tkazish */
  • unsigned char cod(int a, int b)
  • {
  • union
  • {
  • unsigned char z;
  • struct
  • {
  • unsigned int x : 4; //Kichik bitlar
  • unsigned int y : 4; //Katta bitlar
  • } hh;
  • } un ;
  • un.hh.x=a%16;
  • un.hh.y=b%16;
  • return un.z;
  • }
  • /* binar - baytni ikkilikda tasvirlash */
  • int binar(unsigned char ch)
  • {
  • union
  • {
  • unsigned char ss;
  • struct
  • {
  • unsigned a0 :1; unsigned a1 :1;
  • unsigned a2 :1; unsigned a3 :1;
  • unsigned a4 :1; unsigned a5 :1;
  • unsigned a6 :1; unsigned a7 :1;
  • } byte;
  • } cod ;
  • cod.ss=ch;
  • printf("\n Bit raqami: 7 6 5 4 3 2 1 0") ;
  • printf("\n Bitdagi qiymarlari: %d %d %d %d %d %d %d %d",
  • cod.byte.a7, cod.byte.a6, cod.byte.a5,
  • cod.byte.a4, cod.byte.a3, cod.byte.a2,
  • cod.byte.a1, cod.byte.a0);
  • getch(); return 0;
  • }

Download 0.53 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling