O`zbekiston Respublikasi Axborot Texnologiyalari va
Kommunikatsiyalarini rivojlantirish vazirligi
Muhammad Al-Xorazmiy nomidagi Toshkent axborot texnologiyalari
universiteti
Dasturlash 2 fanidan
Topshiriq: 3-laboratoriya
Dasturiy injiniring fakulteti 314-20-guruh talabasi Nuraliyev Sherhonbek
Toshkent -2021
1-masala
Berilgan char turidagi to’plamda kata harfdan va kichik harfdan boshlanuvchi
elementlari soni aniqlovchi hamda ularni ekranga chiqaruvchi dastur tuzing.
#include
#include
"vector"
using namespace
std
;
int
main
() {
cout
<<
"Elementlar sonini kiriting"
;
int
n
;
cin
>>
n
;
cout
<<
"To'plamni kiriting:"
;
char
asd[n]
;
vector
<
char
> katta
;
vector
<
char
> kichik
;
char
a
;
for
(
int
i =
0
;
i < n
;
i++){
cin
>>
a
;
asd[i] =
a
;
}
for
(
auto
i:asd){
if
(isupper(i)){
cout
<<
i
<<
"
\n
"
;
katta.push_back(i)
;
}
else
{
cout
<<
i
<<
"
\n
"
;
kichik.push_back(i)
;
}
}
cout
<<
"Katta harflarni soni: "
<<
katta.size()
<<
endl
;
for
(
auto
i: katta){
cout
<<
i
<<
" "
;
}
cout
<<
"Kichik harflarni soni: "
<<
kichik.size()
<<
endl
;
for
(
auto
i: kichik){
cout
<<
i
<<
" "
;
}
for
(
auto
i: asd){
cout
<<
i
<<
" "
;
}
}
2-masala
#include
#include
#include
#include
#include
using namespace std;
int main()
{
setmyset;
map
mymap;
mymap[1] = "Windows,1985.11.20,16/32/64,grafik";
mymap[2] = "Mac OS,1985,16/32/64,grafik";
mymap[3] = "Linux,1991.12.17,16/32/64,open-source";
mymap[4] = "Unix,1970,16/32,multiuser";
mymap[5] = "DOS OS,1988,16,disk";
cout << "Operatsion sistemalar bazasiga hush kelibsiz!\n";
cout << "Nomi bo`yicha ma`lumot qidirish uchun 1 ni bosing.\n";
cout << "Sanasi bo`yicha ma`lumot qidirish uchun 2 ni bosing.\n";
cout << "Razryadi bo`yicha ma`lumot qidirish uchun 3 ni bosing.\n";
cout << "Turi bo`yicha ma`lumot qidirish uchun 4 ni bosing.\n";
int n; cin >> n;
string OS;
switch (n)
{
//Nomi bo`yicha qidirish;
case 1: {
cout << "Qidirayotgan OS nomini yozing.\t";
cin >> OS;
for (int i = 1; i <= mymap.size(); i++) {
string s = mymap[i];
if (s.find(OS) < s.find(",")) myset.emplace(i);
}
break;
}
//Sanasi bo`yicha qidirish
case 2: {
cout << "Qidirayotgan OS sanani yozing.\t";
cin >> OS;
for (int i = 1; i <= mymap.size(); i++) {
string s = mymap[i];
s.erase(0, s.find(",")+1);
if (s.find(OS) < s.find(",")) myset.emplace(i);
}
break;
}
//Razryadi bo`yicha
qidirish
case 3: {
cout << "Qidirayotgan OS ning razryadini yozing.\t";
cin >> OS;
for (int i = 1; i <= mymap.size(); i++) {
string s = mymap[i];
s.erase(0, s.find(",") + 1);
s.erase(0, s.find(",") + 1);
if (s.find(OS) < s.find(",")) myset.emplace(i);
}
break;
}
//Turi bo`yicha qidirish
case 4: {
cout << "Qidirayotgan OS ning turini yozing.\t";
cin >> OS;
for (int i = 1; i <= mymap.size(); i++) {
string s = mymap[i];
s.erase(0, s.find(",") + 1);
s.erase(0, s.find(",") + 1);
s.erase(0, s.find(",") + 1);
if (s.find(OS) < s.find(",")) myset.emplace(i);
}
break;
}
default: {
cout << "Not`g`ri raqam";
break;
}
}
for (auto& i : myset) {
string s = mymap[i]+",";
cout << "\n";
cout << "Nomi:\t";
int a = 0;
for (a;a
cout << s[a];
}
cout << "\nSanasi:\t";
for (a++;a
cout << s[a];
if (int(s[a + 1]) == 44)break;
}
cout << "\nRazryadi: ";
for (a+=2; a < s.size(); a++) {
cout << s[a];
if (int(s[a + 1]) == 44)break;
}
cout << "\nOS turi: ";
for (a+=2; a < s.size(); a++) {
cout << s[a];
if (int(s[a + 1]) == 44)break;
}
cout << "\n";
}
if (myset.size() == 0)cout << "Ma`lumot topilmadi.";
else {
int k;
cout << "Agar ma`lumotni faylga joylamoqchi bo`lsangiz 1 ni bosing: "; cin >> k;
if (k == 1) {
ofstream str;
str.open("str.txt");
for (auto& i : myset) {
string s = mymap[i] + ",";
str << "\n";
str << "Nomi:\t";
int a = 0;
for (a; a < s.find(","); a++) {
str << s[a];
}
str << "\nSanasi:\t";
for (a++; a < s.size(); a++) {
str << s[a];
if (int(s[a + 1]) == 44)break;
}
str << "\nRazryadi: ";
for (a += 2; a < s.size(); a++) {
str << s[a];
if (int(s[a + 1]) == 44)break;
}
str << "\nOS turi: ";
for (a += 2; a < s.size(); a++) {
str << s[a];
if (int(s[a + 1]) == 44)break;
}
Jasurbek Nurmuhammedov, [31.05.21 21:56]
str << "\n";
}
}
cout << "Ma`lumotlar str.txt fayliga saqlandi.";
}
cout << "\n\n";
return 0;
}