Muhammad al-Xorazmiy nomidagi Toshkent axborot texnologiyalari universitetining swd016-2 guruh talabasi Normuminov Bunyodning Dasturlash fanidan bajargan laboratoriya topshirig’i


Download 31.52 Kb.
Sana06.05.2023
Hajmi31.52 Kb.
#1432860
Bog'liq
DASTURLASH.3



Muhammad al-Xorazmiy nomidagi
Toshkent axborot texnologiyalari
universitetining SWD016-2 guruh
talabasi Normuminov Bunyodning
Dasturlash fanidan bajargan
laboratoriya topshirig’i

1-Topshiriq

Stek eng katta elementi topilsin va undan keyin 0 joylashtirilsin.

#include "iostream"


#include "stack"
#include
using namespace std;
int main()
{ stack stek;
srand(time(0));
int imax,max,n,son;
cout<<"Stack elementlari sonini kiriting: ";
cin>>n;
for(int i=0;i{
son=rand()%100;
stek.push(son);
cout<}
int biggest = stek.top();
stek.pop();
cout<<"Stackning maximal elementi = "<stek.push(0);
while (!stek.empty()) {
cout << stek.top() << " ";
stek.pop();
}
return 0;
}


DASTUR NATIJALARI:




2-topshiriq
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() {


string input;
cout << "Matn kiriting: ";
getline(cin, input);

// Katta harflarni o'chirish


input.erase(remove_if(input.begin(), input.end(), ::isupper), input.end());

// Ikkita to'plam yaratish: biri katta harflar bilan, boshqa esa kichik harflar bilan


string kattaHarflar;
string kichikHarflar;
for (char c : input) {
if (isupper(c)) {
kattaHarflar += c;
} else {
kichikHarflar += c;
}
}
// Ikki to'plamni ekranga chiqarish
cout << "Katta harflar: " << kattaHarflar << endl;
cout << "Kichik harflar: " << kichikHarflar << endl;

return 0;


}
Dastur natijasi!





  1. Topshiriq

Mobil telefonlar haqida (nomi, turi, versiyasi, hajmi, foydalilik darajasi,
yadrosi, kamera o’lchami) to’plam berilgan. Mobil telefonlarning nomi bir
xillardan 2- to’plamni, turi bir xillaridan 3- to’plamni, yadrosi bir xillaridan
4- to’plamni tashkil qiluvchi hamda Mobil telefonni nomi, turi, versiyasi,
hajmi, foydalilik darajasi, yadrosi, kamera o’lchami bo’yicha qidiruvchi
hamda topilgan natijani faylga saqlashni taklif qiladigan dastur tuzing
#include
#include
#include
#include

using namespace std;

struct Phone {
string name;
string type;
int version;
int memory;
int usability;
string processor;
float camera_size;
};

void print_phone(Phone phone) {


cout << "Name: " << phone.name << endl;
cout << "Type: " << phone.type << endl;
cout << "Version: " << phone.version << endl;
cout << "Memory: " << phone.memory << "GB" << endl;
cout << "Usability: " << phone.usability << "%" << endl;
cout << "Processor: " << phone.processor << endl;
cout << "Camera Size: " << phone.camera_size << "MP" << endl;
cout << endl;
}

void save_to_file(vector


phones) {
ofstream file("phones.txt");
if (file.is_open()) {
for (Phone phone : phones) {
file << "Name: " << phone.name << endl;
file << "Type: " << phone.type << endl;
file << "Version: " << phone.version << endl;
file << "Memory: " << phone.memory << "GB" << endl;
file << "Usability: " << phone.usability << "%" << endl;
file << "Processor: " << phone.processor << endl;
file << "Camera Size: " << phone.camera_size << "MP" << endl;
file << endl;
}
file.close();
cout << "Phones saved to file." << endl;
}
else {
cout << "Unable to open file." << endl;
}
}

int main() {


vector
phones;

Phone phone1 = {"iPhone", "Smartphone", 12, 128, 90, "A14 Bionic", 12.0};


Phone phone2 = {"Samsung Galaxy", "Smartphone", 21, 256, 85, "Exynos 2100", 64.0};
Phone phone3 = {"OnePlus", "Smartphone", 9, 128, 80, "Snapdragon 888", 48.0};
Phone phone4 = {"Google Pixel", "Smartphone", 6, 64, 75, "Snapdragon 845", 12.2};
Phone phone5 = {"Motorola", "Feature Phone", 1, 8, 50, "Snapdragon 210", 2.0};

phones.push_back(phone1);


phones.push_back(phone2);
phones.push_back(phone3);
phones.push_back(phone4);
phones.push_back(phone5);

for (Phone phone : phones) {


print_phone(phone);
}

save_to_file(phones);



return 0;
}
DASTUR NATIJALARI:



Download 31.52 Kb.

Do'stlaringiz bilan baham:




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