713-20-guruh talabasi
Abdulhakimov Abdulaziz
2-labaratoriya ishi
18-variant
18
VECTOR hosil qiling va uning toq qiymatdagi elementlarini yig’indisini toping
#include
using namespace std ;
int main()
{
int n;
cout << "Vector elementlari sonini kiriting: ";
cin >> n;
cout << "Vector elementlarini kiriting: ";
vector v;
for(int i = 1; i <= n; i ++)
{
int x;
cin >> x;
v.push_back(x);
}
cout << "Vektorning toq qiymatdagi elementlari yig'indisi: ";
int k = 0;
for(int i = 0; i < v.size(); i ++)
{
if(v[i] % 2 == 1)
k += v[i];
}
cout << k;
}
6-variant
6
Stek birinchi va oxirgi elementlari o‘rni almashtirilsin.
#include
using namespace std;
void rev(stack&x){
int sz=x.size(),mytop,mybottom;
mytop=x.top();
x.pop();
int tmp[sz-1],i=0;
while(!x.empty()){
mybottom=x.top();
tmp[i++]=mybottom;
x.pop();
}
stack returnIt;
returnIt.push(mybottom);
for(i=0;i<=sz-3;i++){
returnIt.push(tmp[i]);
}
returnIt.push(mytop);
while(!returnIt.empty()){
int tt=returnIt.top();
x.push(tt);
returnIt.pop();
}
}
int main() {
// your code goes here
stackx;
x.push(1);
x.push(2);
x.push(3);
x.push(4);
x.push(5);
stacky=x;
cout<<"Stackning dastlabki holati : ";
while(!y.empty()){
int tt=y.top();
cout<
y.pop();
}
rev(x);
cout<<"\nStackning keyingi holati : ";
while(!x.empty()){
cout<
x.pop();
}
return 0;
}
18-variant
18
Berilgan char turidagi to’plamning kata harfdan iborat elementlarini o’chiruvchi va kichik harfdan iborat elementidan 2- to’plamni hosil qiluvchi hamda ularni ekranga chiqaruvchi dastur tuzing.
#include
#include
#include
using namespace std;
int main()
{
char s[]="HelLo";
char t,j;
int q=0,r=0;
cout << "Dastlabki toplam:" << endl;
for(int i=0;i
{cout << s[i];} cout << endl;
for(int i = 0;i
{
if(s[i]>=97 &&s[i]<=122)
{t = s[i];
cout << t << " ";
}
}
cout << endl;
for(int i = 0;i
{
if(s[i]>=65 &&s[i]<=92) {
j = s[i];
cout << j << " ";
}
}
return 0;
}
18
Talabalar haqida (familiya, ismi, sharfi, viloyat, tuman va qishloq) to’plam berilgan. Har bir viloyatda nechta talaba borligini aniqlovchi va viloya , tuman bo’yich talabalarni qidiruvchi dastur tuzing.
#include
using namespace std;
class talaba {
public:
string familiya ;
string ismi;
string sharifi;
string viloyat;
string tuman;
string qishloq;
void show(){
cout<
}
};
int main() {
talaba t[100];
map mp;
ifstream infile("talaba.txt");
int z=0;
string line;
while (getline(infile, line))
{
istringstream iss(line);
if (!(iss >> t[z].familiya >> t[z].ismi>>t[z].sharifi>>t[z].viloyat>>t[z].tuman>>t[z].qishloq)) { break; }
z++;
}
for(int i=0; i
mp[i+1] = t[i];
}
map::iterator it = mp.begin();
cout<<"--------------------Berilgan Talabalr ro'yhat----------------------\n\n";
cout<<"No | Familiya | Ism | Sharifi | viloyati | tuman | qishlog'i \n";
cout<<"--------------------------------------------------------------------------------------------------------------\n";
while (it != mp.end())
{ int n = it->first;
talaba a = it->second;
cout<
a.show();
it++;
}
cout<<"--------------------------------------------------------------------------------------------------------------\n";
int tosh=0, qash=0, sur=0, sir=0, sam=0, jiz=0, nam=0, an=0, far=0, nav=0, xora=0, bux=0;
map::iterator it2 = mp.begin();
while (it2 != mp.end())
{ int n = it2->first;
talaba a = it2->second;
if(a.viloyat=="Toshkent"){
tosh++;
} else if(a.viloyat=="Qashqadaryo"){
qash++;
} else if(a.viloyat=="Surxandaryo"){
sur++;
}else if(a.viloyat=="Sirdaryo"){
sir++;
} else if(a.viloyat=="Samarqand"){
sam++;
}else if(a.viloyat=="Jizzax"){
jiz++;
} else if(a.viloyat=="Namangan"){
nam++;
}else if(a.viloyat=="Farg'ona"){
far++;
} else if(a.viloyat=="Andijon"){
an++;
}else if(a.viloyat=="Navoiy"){
nav++;
} else if(a.viloyat=="Xorazm"){
xora++;
}else if(a.viloyat=="Buxoro"){
bux++;
}
it2++;
}
cout<<"\nViloyatlar kesimida talabalar soni: \n";
cout<<"Toshkent: "<
cout<<"Qashqadaryo: "<
cout<<"Surxandaryo: "<
cout<<"Buxoro: "<
cout<<"Sirdaryo: "<
cout<<"Samarqand: "<
cout<<"Jizzax: "<
cout<<"Namangan: "<
cout<<"Farg'ona: "<
cout<<"Andijon: "<
cout<<"Navoiy: "<
cout<<"Xorazm: "<
string vil, tum;
cout<<"\nqidirilayotgan Talabaning viloyati: "; cin>>vil;
cout<<"qidirilayotgan Talabaning tumani : "; cin>>tum;
map::iterator it1 = mp.begin();
cout<<"--------------------Topilgan Talabalr ro'yhat----------------------\n\n";
cout<<"No | Familiya | Ism | Sharifi | viloyati | tuman | qishlog'i \n";
cout<<"--------------------------------------------------------------------------------------------------------------\n";
while (it1 != mp.end())
{ int n = it1->first;
talaba a = it1->second;
if(a.viloyat==vil || a.tuman==tum ){
cout<
a.show();
}
it1++;
}
cout<<"--------------------------------------------------------------------------------------------------------------\n";
return 0;
}
Do'stlaringiz bilan baham: