topshiriq quyidagi metodlarni izohlang begin


Download 171.2 Kb.
bet2/4
Sana18.06.2023
Hajmi171.2 Kb.
#1574281
1   2   3   4
Bog'liq
2-topshiriq. MAP (2) (2)

#include
#include
using namespace std;
int main(){
map semvol=
{{'#',35},
{'+', 43},
{'0', 48},
{'1', 49},
{'2', 50},
{'3', 51},
{'4', 52},
{'5', 53},
{'6', 54},
{'7', 55},
{'8', 56},
{'9', 57},
{'A', 65},
{'B', 66},
{'C', 67},
{'D', 68},
{'E', 69},
{'F', 70},
{'G', 71},
{'H', 72},
{'I', 73},
{'J', 74},
{'K', 75},
{'L', 76},
{'M', 77},
{'N', 78},
{'O', 79},
{'P', 80},
{'Q', 81},
{'R', 82},
{'S', 83},
{'T', 84},
{'U', 85},
{'V', 86},
{'W', 87},
{'X', 88},
{'Y', 89},
{'Z', 90},
{'a', 97},
{'b', 98},
{'c', 99},
{'d', 100},
{'e', 101},
{'f', 102},
{'g', 103},
{'h', 104},
{'i', 105},
{'j', 106},
{'k', 107},
{'l', 108},
{'m', 109},
{'n', 110},
{'o', 111},
{'p', 112},
{'q', 113},
{'r', 114},
{'s', 115},
{'t', 116},
{'u', 117},
{'v', 118},
{'w', 119},
{'x', 120},
{'y', 121},
{'z', 122}
};
int i,m; char a,b;
cout<<"nechta juftlik qo'shmoqchisiz ? "; cin>>m;
for(i=1; i<=m; i++){
cout<<"kalitni kiriting "; cin>>a;
cout<<"qiymatni kiriting "; cin>>b;
semvol.insert(pair (a,b));
}
for(auto it=semvol.begin(); it!=semvol.end(); it++)
if('A'==it->first or 'E'==it->first or 'I'==it->first or
'O'==it->first or 'U'==it->first or 'Y'==it->first or
'a'==it->first or 'e'==it->first or 'i'==it->first or
'o'==it->first or 'u'==it->first or 'y'==it->first)
cout<first<<" "<second<
}
14) Map hosil qiling. Uni elementlar bilan to’ldiring. M kalitni kiriting agar kalit mavjud, bo’lsa o’chirsin aks holda mapda bunday kalit yo’qligi haqida xabar bersin.
#include
#include
using namespace std;
int main(){
map tekshiruv;
int i,n,k,s=0; string a,b,m;
cout<<" nechta elementlar juftligini qo'shmoqchisiz ? "; cin>>n;
for(i=1; i<=n; i++){
cout<<"kalitni kiriting "; cin>>a;
cout<<"qiymatni kiriting "; cin>>b;
tekshiruv.insert(pair(a,b));
}
l:
cout<<" map da m kalit va qiymatini o'chiring m="; cin>>m;
for( auto it=tekshiruv.begin(); it!=tekshiruv.end(); it++){ s++;
if(m==it->second or m==it->first) tekshiruv.erase(it->first);}
k=tekshiruv.size();
if(s==k) cout<<"o'chirish uchun element topilmadi "<
for(auto it=tekshiruv.begin(); it!=tekshiruv.end(); it++)
cout<first<<" "<second<
goto l;
}
15) Lugat dan iborat map hosil qiling. Kalitga mos qiymatlarni kiriting. Agar tarjima to’g’ri bo’lsa, yakunida jammi ball hisoblansin. Har bir to’g’ri so’z 1 balldan baholang.
#include
#include
using namespace std;
int main(){
map tarjima=
{{"apple" , "olma"},
{"book","kitob"},
{"pen", "ruchka"},
{"teacher", "o'qituvchi"},
{"lemon","limon"},
{"horse","ot"},
{"peach", "shaftoli"},
{"home","uy"},
{"work","ish"},
{"water","suv"},
{"hello","salom"},
{"umbrella","soyabon"},
{"car","avtomabel"},
{"box", "quti"},
{"word","so'z"},
{"phone","telefon"},
{"end","tamom"},
{"fox","tulki"},
{"zebra","zebra"},
{"crocodel","timsoh"}
};
int s=0,k; string a;
k=tarjima.size();
cout<<"tarjima qiling "<
for(auto it=tarjima.begin(); it!=tarjima.end(); it++){
cout<first<<" "; cin>>a;
if(a==it->second) s++;} cout<
if(s>16) cout<<" A'LO "; else
if(s>12 and s<=16) cout<<" YAXSHI "; else
if(s>8 and s<=12) cout<<" QONIQARLI "; else
if(s>4 and s<=8) cout<<" QONIQARSIZ "; else
cout<<" QAYTA URINIB KO'RING ";
cout<<" siz "<
}
16) Matematik misollar va ularning natijasi berilgan. Agar o’quvchi masalalarni to’g’ri yechsa, 2 balldan xató yechsa 1 balldan kamaytirib umumiy ballni hisoblovchi dastur tuzing.
#include
#include
using namespace std;
int main(){
map matematika=
{{"2+3/2=", 3.5},
{"18*13-17*14=",-4},
{"Teng tomonli uchburchakning tomoni 6 ga teng.Uning peremetrini toping.", 18},
{"Ali va Valida bir necha sumdan pul bor. Agar Vali Aliga 2 sum pul bersa,"
"ularning pullari terng bo'ladi. Agar Ali Valiga 2 sum pul bersa Valining puli Alining pulidan "
" 2 marta ko'p bo'ladi. Valida qancha pul bor ? ", 14},
{"mm da ifodalang. 2dm 23sm 11mm=",441},
{"3 gektar necha sotix ? ", 300},
{"Arifmetik progressiyaning birinchi hadi 3 ga yettinchi hadi esa 15 ga teng"
" shu arifmetik progrissiyaning dastlabgi 10 ta hadi yig'indisini toping. ",120},
{"Bir quvur bo'sh hovuzni 4 soatda toldiradi. Ikkinchi quvur esa xuudi shu hovuzni 6 soatda to'ldiradi. "
" Ikkala quvur birgalikda shu hovuzni necha soatdda to'ldiradi ? ",2.4},
{"2+2=",4},
{"Raqamlari yig'indisidan 2 marta katta bo'lgan sonni toping. ",18}
};
int s=0,k; float a;
k=matematika.size();
cout<<"masalalarni javobini toping "<
for(auto it=matematika.begin(); it!=matematika.end(); it++){
cout<first<<" "; cin>>a;
if(a==it->second) {s+=2; cout<<"T"<
cout<
if(s>8) cout<<" A'LO "; else
if(s>6 and s<=8) cout<<" YAXSHI "; else
if(s>4 and s<=6) cout<<" QONIQARLI "; else
if(s>2 and s<=4) cout<<" QONIQARSIZ "; else
cout<<" QAYTA URINIB KO'RING ";
cout<<" siz "<<2*k<<" balldan "<
}
17) Shunday dastur tuzing, kiritilgan o’nlik sonni ikkilik sanoq sistemasiga aylanitirib bersin. (Mapni o’nlik va ikkilikdagi qiymati bilan to’ldiring)
1) #include
#include
using namespace std;
int ikkilik_sanoq(int a)
{
long long int b,s=0,k=0;
for(;;){
s=s+a%2*pow(10,k); k++; a=a/2;
if(a<2) {s=s+a*pow(10,k); break;}
} return s;
}
int main()
{
long long int k,a;
cout<<"o'nlikda a="; cin>>a;
k=ikkilik_sanoq(a);
cout<<"k="<
}
2) #include
#include
using namespace std;
int main()
{
map ikkilik=
{{0,0},
{1,1},
{2,10},
{3,11},
{4,100},
{5,101},
{6,110},
{7,111},
{8,1000},
{9,1001},
{10,1010},
{11,1011},
{12,1100},
{13,1101},
{14,1110},
{15,1111}
};
int a;
cout<<"ikkilik sanoq sistemsiga o'tkazing "; cin>>a;
for(auto it=ikkilik.begin(); it!=ikkilik.end(); it++)
if(a==it->first) cout<second;
}
18) Map hosil qiling va pifogor jadvali bilan to’ldiring. Ixtiyoriy kiritilgan n karaning jadvalini chop eting.
#include
#include
using namespace std;
int main()
{
multimap pifagor;
int a,i,j;
for(i=1; i<=10; i++)
for(j=1; j<=10; j++)
pifagor.insert(pair (i,j));
cout<<"Necha karra jadvali kerak ? "; cin>>a;
for(auto it=pifagor.begin(); it!=pifagor.end(); it++)
if(a==it->second) cout<second<<"*"<first<<"="<first*it->second<
}
19) Map hosil qiling va uni n ta juftlik bilan to’ldiring. Kalit va qiymatni almashtirib, chop eting.
#include
#include
using namespace std;
int main()
{
map xesh;
int i,n,b; string a;
cout<<" nechta juftlikdan iborat map yaratmoqchisiz ? "; cin>>n;
for(i=1; i<=n; i++){
cout<<"kalitni kiriting "; cin>>a;
cout<<"qiymatni kiriting "; cin>>b;
xesh.insert(pair (a,b));
}
for(auto it=xesh.begin(); it!=xesh.end(); it++)
cout<second<<" "<first<
}
20) O’quvchi mapda mavjud bo’lgan inglizcha so’zni kiritsa, o’zbekcha tarjimasini, o’zbekcha kiritsa esa inglizchasini chiqaruvchi dastur tuzing.
#include
#include
using namespace std;
int main()
{
maptarjima=
{{"apple" , "olma"},
{"book","kitob"},
{"pen", "ruchka"},
{"teacher", "o'qituvchi"},
{"lemon","limon"},
{"horse","ot"},
{"peach", "shaftoli"},
{"home","uy"},
{"work","ish"},
{"water","suv"},
{"hello","salom"},
{"umbrella","soyabon"},
{"car","avtomabel"},
{"box", "quti"},
{"word","so'z"},
{"phone","telefon"},
{"end","tamom"},
{"fox","tulki"},
{"zebra","zebra"},
{"crocodel","timsoh"}
};
string a;
cout<<"o'zbekcha yoki inglizcha so'z kiriting "; l: cin>>a;
for(auto it=tarjima.begin(); it!=tarjima.end(); it++)
if(a==it->first ) cout<second<if(a==it->second) cout<first<goto l;
}
21) Jurnaldagi o’quvchilarning ro’yxatidagi ism familyasi va tartibi bilan kirtilgan. Ixtiyoriy tartib raqam kiritilsa undan avvalgi va undan keyingi o’quvchining ism familyasini chop eting.
#include
#include
using namespace std;
int main()
{
maptarjima=
{{1,"Pardayev Maxsudbek"},
{2,"Hakimjonova Marjona"},
{3,"Qurbonov Javohir"},
{4,"Bobonazarov Mo'min"},
{5,"To'rayev Behruz"},
{6,"Eshmuminov Farrux"},
{7,"Xushvaqtova Malohat"},
{8,"Olimov Otabek"},
{9,"Safarov, Jahonzeb"},
{10,"Zayniddinov Sherbek"},
{11,"Umurov Amanjon"},
{12,"Islomov Dilmurod"},
{13,"Xo'rozov Jamol"},
{14,"Umarov Tohir"},
{15,"Abdusodiqov Bobur"},
{16,"G'afurov Sherozbek"},
{17,"Abdullayev Mukammal"},
{18,"Xamedova Ruxshona"},
{19,"Tursinov Mirsodiq"},
{20,"Yangiboyev Islom"},
{21,"Jontemirov Axmad"},
{22,"Omonova Afro'za"},
{23,"Zoirov Behruz"},
{24,"Otamurodov Boymurod"},
{25,"Abdullayev Diyorbek"},
{26,"Abdullayev Abdulaziz"}
};
int a,k=0;
cout<<"tartib raqamni kiriting "; cin>>a;
for(auto it=tarjima.begin(); it!=tarjima.end(); it++){ k++;
if(a-1==k or a+1==k) cout<second<
}
22) Telefon raqamlar kitobchasi berilgan. Raqam egasining, ismi kirtilgach uning telefon raqamini chop eting.
#include
#include
using namespace std;
int main()
{
maptelefon_kitobi=
{{"Maxsudbek",904570708},
{"Marjona",945494436},
{"Javohir",938304405},
{"Mo'min",995768896},
{"Behruz",993327310},
{"Farrux",908923604},
{"Malohat",916912283},
{"Otabek",990712449},
{"Jahonzeb",915142379},
{"Sherbek",936625590},
{"Amanjon",907124640},
{"Dilmurod",935858397},
{"Jamol",945777269},
{"Tohir",882831503},
{"Bobur",934620704},
{"Sherozbek",932003849},
{"Mukammal",931437802},
{"Ruxshona",886840407},

Download 171.2 Kb.

Do'stlaringiz bilan baham:
1   2   3   4




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