logo

Tanlash opretori (Switch) Labaratoriya

Загружено в:

08.08.2023

Скачано:

0

Размер:

550.5 KB
Labaratoriya №3
                             Mavzu: Tanlash opretori (Switch)
2.K butun soni berilgaan. Baho natijalari chiqaruvchi dastur tuzing. (1-yomon, 2-
qoniqarsiz, 3-qoniqarli, 4-yaxshi, 5-a’lo). Agar  k  soni 1-5 oraliqqa tegishli  
bo’lmasa “xato” deb chiqarilsin.
Yechish:
#include<iostream>
#include<math.h>
using namespace std;
int main ()
{  int k;
cin>>k;
switch(k)
{
case 1:cout<<"yomon";break;
case 2:cout<<"qoniqrsiz";break;
case 3:cout<<"qoniqarli";break;
case 4:cout<<"yaxshi";break;
case 5:cout<<"a'lo";break;
default:cout<<"xato";
}
        return 0;
    }
Javobi:  2. Doiraning  elementlari  quyidagi  tartibda  nomerlangan: 1-radius  R,  2-diametr 
D = 2*R, 3-uzunligi L =2*pi*R,  4-doiraing  yuzi  S=pi*R².  Shu  elementlardan  
bittasi  berilgan  qolganlarnii  topuvchi  dastur  tuzilsin.  Pi=3.14.
Yechish:
#include<iostream>
#include<math.h>
using namespace std;
int main ()
{  int k, r=3;
float d,l,s,pi=3.14;
cin>>k;
d=2*r;
l=2*pi*r;
s=pi*pow(r,2);
switch(k)
{
case 1:cout<<"radius="<<r;break;
case 2:cout<<"diametr="<<d;break;
case 3:cout<<"uzunligi="<<l;break;
case 4:cout<<"yuzi="<<s;break;
default:cout<<"xato";
}
        return 0;
    }
Javobi:  3. O’yin  kartasi  turlari  brilgan:  1-g’isht,  2-olma,  3-chillak,  4-qarg’a,  10 lik   
kartadan  katta  kartalar  quyidagi  qiymatlarni  o’zlashtirsin:  12-dama,  13-qirol,  
14-tuz.  Ikkita  butun  son  berilgan  N-karta  qiymati (6 ≤N≤14) va  M-karta  turi 
(1≤M≤4) kiritilganda  karta  nomlarini  (masalan, “olti  qarg’a”) chiqarib  beruvchi 
dastur  tuzilsin.
Yechish:
#include<iostream>
#include<math.h>
using namespace std;
int main()
{int x,y;
cin>>x>>y;
switch(x)
{
  case 6: cout<<"olti ";break;
  case 7: cout<<"yeti ";break;
  case 8: cout<<"sakkiz ";break;
  case 9: cout<<"to'qqiz ";break;
  case 10: cout<<"o'n ";break;
  case 11: cout<<"valet ";break;
  case 12: cout<<"dama ";break;
  case 13: cout<<"karol ";break;
  case 14: cout<<"tuz ";break;
  default : cout<<"xato";
}
switch(y)
{
case 1:cout<<"g'isht ";break;
case 2:cout<<"tappan ";break;
case 3:cout<<"qarg'a ";break;
case 4:cout<<"chillik ";break;
default:cout<<"xato";break; }
}
return 0;
}
Javobi:
4. 100-999 gacha  oraliqdagi  sonlarni  so’zlarda  ifodalovchi  dastur  tuzilsin.
(masalan: 123-“bir  yuz  yigirma  uch”). Yechish:
#include<iostream>
#include<math.h>
using namespace std;
int main()
{int i,n,s;
cin>>i;
n=i/100;
    switch(n)
{case 1: cout<<"bir yuz ";break;
  case 2: cout<<"ikki yuz";break;
  case 3: cout<<"uch yuz";break;
  case 4: cout<<"to’rt yuz";break;
  case 5: cout<<"besh yuz";break;
  case 6: cout<<"olti yuz";break;
  case 7: cout<<"yetti yuz";break;
  case 8: cout<<"sakkiz yuz";break;
  case 9: cout<<"to’qqiz yuz";break;
  default : cout<<"uch xonali son kiriting";
}
n=i/10;
s=n%10;
  switch(s){
case 1:cout<<" o’n";break;
case 2:cout<<" yigirma";break;
case 3:cout<<" o’ttiz";break;
case 4:cout<<" qirq";break;
case 5:cout<<" ellik";break;
case 6:cout<<" oltmish";break;
case 7:cout<<" yetmish";break;
case 8:cout<<" sakson";break; case 9:cout<<" to’qson";break;
}
    i=i%10;
switch(i)
{case 1:cout<<" bir";break;
  case 2:cout<<" ikki";break;
  case 3:cout<<" uch";break;
  case 4:cout<<" to’rt";break;
  case 5:cout<<" besh";break;
  case 6:cout<<" olti";break;
  case 7:cout<<" yetti";break;
  case 8:cout<<" sakkiz";break;
  case 9:cout<<" to’qqiz";break;
}
return 0;}
Javobi: 5. Yoshli  yillarda  aniqlovchi  20-69 gacha  butun  son  berilgan.  Son kiritilganda 
unga  mos  so’zlar  ifodalovchi  dastur  tuzilsin. (“yigirma  yosh”, “qirq  uch  yosh”
va h.k.).
Yechish:
#include<iostream>
#include<math.h>
using namespace std;
int main()
{int i,n,s;
cin>>i;
n=i/100;
    switch(n)
{case 1: cout<<"bir yuz ";break;
  case 2: cout<<"ikki yuz";break;
  case 3: cout<<"uch yuz";break;
  case 4: cout<<"to’rt yuz";break;
  case 5: cout<<"besh yuz";break;
  case 6: cout<<"olti yuz";break;
  case 7: cout<<"yetti yuz";break;
  case 8: cout<<"sakkiz yuz";break;
  case 9: cout<<"to’qqiz yuz";break;
  default : cout<<"uch xonali son kiriting";
}
n=i/10;
s=n%10;
  switch(s)
{
case 1:cout<<" o’n";break;
case 2:cout<<" yigirma";break;
case 3:cout<<" o’ttiz";break;
case 4:cout<<" qirq";break; case 5:cout<<" ellik";break;
case 6:cout<<" oltmish";break;
case 7:cout<<" yetmish";break;
case 8:cout<<" sakson";break;
case 9:cout<<" to’qson";break;
}
    i=i%10;
switch(i)
{case 1:cout<<" bir";break;
  case 2:cout<<" ikki";break;
  case 3:cout<<" uch";break;
  case 4:cout<<" to’rt";break;
  case 5:cout<<" besh";break;
  case 6:cout<<" olti";break;
  case 7:cout<<" yetti";break;
  case 8:cout<<" sakkiz";break;
  case 9:cout<<" to’qqiz";break;
}
return 0;}
Javobi:

Labaratoriya №3 Mavzu: Tanlash opretori (Switch) 2.K butun soni berilgaan. Baho natijalari chiqaruvchi dastur tuzing. (1-yomon, 2- qoniqarsiz, 3-qoniqarli, 4-yaxshi, 5-a’lo). Agar k soni 1-5 oraliqqa tegishli bo’lmasa “xato” deb chiqarilsin. Yechish: #include<iostream> #include<math.h> using namespace std; int main () { int k; cin>>k; switch(k) { case 1:cout<<"yomon";break; case 2:cout<<"qoniqrsiz";break; case 3:cout<<"qoniqarli";break; case 4:cout<<"yaxshi";break; case 5:cout<<"a'lo";break; default:cout<<"xato"; } return 0; } Javobi:

2. Doiraning elementlari quyidagi tartibda nomerlangan: 1-radius R, 2-diametr D = 2*R, 3-uzunligi L =2*pi*R, 4-doiraing yuzi S=pi*R². Shu elementlardan bittasi berilgan qolganlarnii topuvchi dastur tuzilsin. Pi=3.14. Yechish: #include<iostream> #include<math.h> using namespace std; int main () { int k, r=3; float d,l,s,pi=3.14; cin>>k; d=2*r; l=2*pi*r; s=pi*pow(r,2); switch(k) { case 1:cout<<"radius="<<r;break; case 2:cout<<"diametr="<<d;break; case 3:cout<<"uzunligi="<<l;break; case 4:cout<<"yuzi="<<s;break; default:cout<<"xato"; } return 0; } Javobi:

3. O’yin kartasi turlari brilgan: 1-g’isht, 2-olma, 3-chillak, 4-qarg’a, 10 lik kartadan katta kartalar quyidagi qiymatlarni o’zlashtirsin: 12-dama, 13-qirol, 14-tuz. Ikkita butun son berilgan N-karta qiymati (6 ≤N≤14) va M-karta turi (1≤M≤4) kiritilganda karta nomlarini (masalan, “olti qarg’a”) chiqarib beruvchi dastur tuzilsin. Yechish: #include<iostream> #include<math.h> using namespace std; int main() {int x,y; cin>>x>>y; switch(x) { case 6: cout<<"olti ";break; case 7: cout<<"yeti ";break; case 8: cout<<"sakkiz ";break; case 9: cout<<"to'qqiz ";break; case 10: cout<<"o'n ";break; case 11: cout<<"valet ";break; case 12: cout<<"dama ";break; case 13: cout<<"karol ";break; case 14: cout<<"tuz ";break; default : cout<<"xato"; } switch(y) { case 1:cout<<"g'isht ";break; case 2:cout<<"tappan ";break; case 3:cout<<"qarg'a ";break; case 4:cout<<"chillik ";break; default:cout<<"xato";break;