6-Variant
1-jadval.
6. Berilgan satrda, berilgan so’zni satr boshiga qo’shadigan dastur tuzing.
#include
#include
#include
using namespace std;
int main() {
string a,b;
getline(cin,a);
getline(cin, b);
cout << b << " " << a << endl;
return 0;
}
2-jadval.
6. char turidagi A satrni har N- soʻzini katta harfga oʻzgartiruvchi va ushbu soʻzlarni teskari holatga oʻzagrtiruvchi dastur tuzing.
#include
#include
#include
using namespace std;
int main() {
char a[255];
cin >> a;
char b[strlen(a)];
int n;
cin >> n;
for (int i=1; i<=strlen(a); i++)
{
if (i%n==0)
{
b[i-1] = toupper(a[i-1]);
}
else
{
b[i-1] = a[i-1];
}
}
for (int i=strlen(b)-1; i>=0; i--)
{
cout << b[i];
}
return 0;
}
3-jadval.
6. String turidagi Satr berilgan. Undagi elementlarni byte turidagi A massivga joylashtirib, toq elementlarini B massivga, juftlarni C massivga joylashtiruvchi dastur tuzing.
#include
#include
using namespace std;
class Museum {
};
int main() {
string d;
getline(cin,d);
unsigned char a[d.length()+1];
char b[100],c[100];
for (int i=0; ia[i] = d[i];
cout << a << endl;
int j=0, k=0;
for (int i=0; i{
if (i%2==0){
b[j]=a[i];
j++;
}
if (i%2!=0){
c[k]=a[i];
k++;
}
}
cout << b << endl;
cout << c << endl;
return 0;
}
4-jadval.
6. Muzeylar haqida, String turida ma’lumotlar berilgan(class Museum). Ixtiyoriy muzeyni 6 ta parametri boʻyicha qidirib topuvchi dastur tuzing.
#include
#include
#include
using namespace std;
class Museum {
public:
string name;
string type;
string price;
string city;
MyMethod() {
cout << name << " " << type << " " << price << " " << city << endl;
}
};
int main() {
Museum muse[2];
for (int i=0; i<2; i++)
{
cout << "Museum nomini kiriting: ";
cin >> muse[i].name;
cout << "Museum turini kiriting: ";
cin >> muse[i].type;
cout << "Museum narxini kiriting: ";
cin >> muse[i].price;
cout << "Museum shahrini kiriting: ";
cin >> muse[i].city;
}
cout << "Sozni kiriting: ";
string a;
cin >> a;
for (int i=0; i<2; i++)
{
if(a==muse[i].type||a==muse[i].city||a==muse[i].price)
{
cout << muse[i].name << endl;
}
}
return 0;
}
5-jadval.
6. String turidagi N ta soʻz berilgan. Ushbu soʻzlarning eng uzunini va eng kaltasini aniqlovchi dastur tuzing.
Dasturi.
C++.
#include
#include
using namespace std;
void minMaxLengthWords(string input, string &minWord, string &maxWord)
{
int len = input.length();
int si = 0, ei = 0;
int min_length = len, min_start_index = 0, max_length = 0, max_start_index = 0;
while (ei <= len)
{
if (ei < len && input[ei] != ' ')
ei++;
else
{
int curr_length = ei - si;
if (curr_length < min_length)
{
min_length = curr_length;
min_start_index = si;
}
if (curr_length > max_length)
{
max_length = curr_length;
max_start_index = si;
}
ei++;
si = ei;
}
}
minWord = input.substr(min_start_index, min_length);
maxWord = input.substr(max_start_index, max_length);
}
int main()
{
string a = "Assolomu alaykum bo'lajak dasturchilar";
string minWord, maxWord;
minMaxLengthWords(a, minWord, maxWord);
cout << "Minimum length word: "
<< minWord << endl
<< "Maximum length word: "
<< maxWord << endl;
}
Dastur natijasi:
Do'stlaringiz bilan baham: |