Berilgan matnda nechta so’z mavjudligini aniqlash dasturini tuzing



Yüklə 39,34 Kb.
tarix30.09.2023
ölçüsü39,34 Kb.
#151039
DASTUR.LABARATORIYA.


Satrlar
/*1.Berilgan matnda nechta so’z mavjudligini aniqlash dasturini tuzing.*/
#include
#include
using namespace std;
int main()
{ string s; int n, k=0;
getline(cin,s);
n=s.length();
for(int i=0; iif(s.at(i)==32) k++;
cout << k+1<<" ta so`z bor" << endl;
return 0;
}
/*2. Matn berilgan. Ushbu matnda “A” harfi bilan boshlanuvchi
so’zlar miqdorini aniqlash dasturini tuzing*/
#include
#include
using namespace std;

int main()


{ string s; int n, k=0;
getline(cin,s);
n=s.length();
for(int i=0; iif(s.at(i)==65) k++;
cout << k<<" ta A harfi bor" << endl;
return 0;
}
/*3. Matn berilgan. Ushbu matnda nechta gap borligini
aniqlash dasturini tuzing*/
#include
#include
using namespace std;
int main()
{ string s; int n, k=0;
getline(cin,s);
n=s.length();
for(int i=0; iif(s.at(i)=='.' or s.at(i)=='?' or s.at(i)=='!') k++;
cout << k<<" ta gap bor" << endl;
return 0; }
/*4. Berilgan matnda nechta unli qatnashganini aniqlang*/
#include
#include
using namespace std;
int main()
{ string s; int n, k=0;
getline(cin,s);
n=s.length();
for(int i=0; iif(s.at(i)=='a' or s.at(i)=='A' or s.at(i)=='o' or s.at(i)=='O' or s.at(i)=='i' or s.at(i)=='I' or s.at(i)=='u' or s.at(i)=='U' or s.at(i)=='e' or s.at(i)=='E' ) k++;
cout << k<<" ta unli harf bor" << endl;
return 0; }
/*6. Berilgan ikkita satrlarni birlashtirish dasturing tuzing*/
#include
#include
using namespace std;
int main()
{ string a,b;
cout<<"birinchi satirni kiriting"<getline(cin,a);
cout<<"ikkinchi satirni kiriting"<getline(cin,b);
cout << a+" "+b<< endl;
return 0; }
/*8. Matn faqat bitta so’zdan tashkil topgan. Matn uzunligi,
matndagi unlilar soni, undoshlar soni aniqlansin.*/
#include
#include
using namespace std;
int main()
{ char a[100]; int b, k=0; string n;
cout<<"so`zni kiriting"<cin.getline(a,100);
b=strlen(a);
for(int i=0; iif(n.at(i)=='a' or n.at(i)=='A' or n.at(i)=='o' or n.at(i)=='O' or n.at(i)=='i' or n.at(i)=='I' or n.at(i)=='e' or n.at(i)=='E' or n.at(i)=='u' or n.at(i)=='U' ) k++;
cout<< b << " ta harf bor "<return 0; }
/*10. Ikkita satr berilgan. Bu satrlarning uzunligini solishtiring.*/
#include
#include
using namespace std;
int main(){
char S1[100] = "Satr1";
char S2[100] = "Satr2";
cout << "Birinchi matn: " << S1 << "\n";
cin.getline(S1,100);
cout << "Ikkinchi matn: " << S2 << "\n";
cin.getline(S2,100);
cout< return 0; }

/*11. Matn berilgan. Berilgan matnda qaratqich kelishigi


necha marta qatnashganini aniqlang.*/
#include
#include
using namespace std;
int main()
{string s; int n, k=0;
getline(cin,s);
n=s.length();
for(int i=0; iif(s.at(i)=='n' && s.at(i+1)=='i' && s.at(i+2)=='n' && s.at(i+3)=='g') k++;
cout << k << endl;
return 0;
}/*13. “Berilgan matndagi barcha “bo’sh” joylarni o’chiring.)*/
#include
#include
using namespace std;
int main()
{ string s;
int n, k=0;
cout<<"so'z kiriting"<getline(cin,s);
n=s.length();
for(int i=1; i{ if(s.at(i)==' ') k++; }
cout<return 0;}
/*14. Berilgan satrning uzunligini va xotira hajmini aniqlang*/
#include
#include
using namespace std;
int main()
{
string s;
int n;
cout<<"so'z kiriting"<getline(cin,s);
n=s.length();
cout<<"uzunligi"<cout<<"hajmi"<return 0; }
/*15. Satr berilgan. Nechta so’z ko’plik shaklida ekanligini aniqlang*/
#include
#include
using namespace std;
int main(){
string s;
int n, k=0;
cout<<"gap kiriting"<getline(cin,s);
n=s.length();
for(int i=0; iif(s.at(i)=='l' && s.at(i)=='a' && s.at(i)=='r') k++; }
cout<return 0; }
/*17. S1 va S2 lar berilgan. Bu ikki satrning uzunliklarini taqqoslang*/
#include
#include
using namespace std;
int main()
{
char S1[100], S2[100];
cout<<"1-satir"<cin.getline(S1,100);
cout<<"2-satir"<cin.getline(S1,100);
cout<return 0; }
/*18. S1 va S2 satrlar berilgan. Bu ikki satrni birlashtirish natijasida uchinchi satrni hosil qiling.*/
#include
#include
using namespace std;
int main(){
string s1, s2;
cout<<"1-satir"<getline(cin,s1);
cout<<"2-satir"<getline(cin,s2);
cout<return 0; }
/*23. Matnda ismlar ro’yxati berilgan. Ushbu ro’yxatda nechta ism berilganligini va qandaydir ism mavjudligini tekshiring.*/
#include
#include
using namespace std;
int main(){
string s1;
int k=0, n;
cout<<"satirni kiriting"<getline(cin,s1);
n=s1.length();
for(int i=0; iif(s1.at(i)=='65' || s1.at(i)=='90') k++; }
cout<return 0; }

KO’RSATKICHLAR


masala_1
#include
using namespace std;
void adres(int a){
int *manzil = &a ;
cout <<"kiritgan son manzili --> " << manzil ;
}
int main(){
int a ;
cin >> a ;
adres(a) ; }
masala_3
#include
#include
using namespace std;
int main(){
int a , b , c , D , x1 , x2 ;
cin >> a >> b >> c ;
D = pow(b,2)-4*a*c;
if(D>0){
x1 = (-b - D)/(2*a);
x2 = (-b + D)/(2*a);
int *manzil = &x1 ;
int *manzil2 = &x2 ;
cout << manzil << endl ;
cout << manzil2 ; }
if(D==0){
x1 = (-b-D)/(2*a);
int *manzil = &x1 ;
cout << x1 ; }
if(D<0){
cout << "Bo'sh to'plam" ; } }

masala_5
#include


#include
using namespace std;
void triangle(float *a , float *b , float *x){
if((-(*b / *a))>0){
cout << sqrt(-( *b / *a)) ;
}
else
cout << NULL; }
int main (){
float a , b , x ;
cin >> a >> b >> x ;
triangle(&a , &b , &x); }
masala_7
#include
#include
using namespace std;
void triangle(int n , int max , int s , int m){
cout << "Jami sarflangan pul ---> " << s << "$"< cout << "O'rtacha maosh ---> " << s / n <<"$"<< endl ;
cout << "Eng katta maosh ---> " << max <<"$"<int main(){
int n , max=0 , s=0 , m ;
cin >> n ;
for(int i=0; i cout << "Ishchining maoshi : " ; cin >> m ;
s += m ;
if(max max=m; } }
triangle(n , max , s , m) ;
}

masala_9
#include


#include
using namespace std;

int main()


{
int *a, *b, *c, *d, *h, i, j, k , l , m;
cout << "i = " ; cin >> i ;
cout << "j = " ; cin >> j ;
cout << "k = " ; cin >> k ;
cout << "l = " ; cin >> l ;
cout << "m = " ; cin >> m ;
a = &l;
b = &i;
c = &j;
d = &k;
h = &m;
cout << "i = " << a << endl;
cout << "j = " << b << endl;
cout << "k = " << c << endl;
cout << "l = " << d << endl;
cout << "m = " << h << endl;
}
masala_11
#include
using namespace std;
int main(){
int n ;
cin >> n ;
int A[n];
for(int i=1 ; i<=n ; i++){
cout << "A["<> A[i] ;
}

Int m = 0 ;


int B[n];
for(int i=0; i<=n ; i++){
if(A[i] % 3 == 0 && A[i] % 5 == 0){
m++;
B[m] = A[i] ; }}
for(int i=1 ; i<=m ; i++){
cout << B[i] << endl ;
} }
masala_13
#include
using namespace std;
void comp(float *a , float *b , float *c){
cout << "Eng yaxshi natija " << max(max(*a , *b) ,*c) << " ball" ;
}
int main(){
float a , b , c ;
cin >> a >> b >> c ;
comp( &a , &b , &c) ;
}
masala_17
#include
using namespace std;
void adres(float a){
float *b = &a ;
cout << "kiritgan soningiz manzili " << b ; }
int main(){
float a ;
cin >> a ;
adres(a) ;
}
masala_19
#include
#include
using namespace std;

void triangle(float *a , float *b , float *c){


float *p , *S , *P ;
*p = (*a + *b + *c)/2 ;
*S = sqrt((*p - *a) * ( *p - *b) * ( *p - *c ) );
P = a + b + c ;
cout << "uchburchak perimetri ---> " << P << endl ;
cout << "uchburchak yuzi ---> " << S << endl ; }
int main (){
float a , b , c ;
cout << "a = " ; cin >> a ;
cout << "b = " ; cin >> b ;
cout << "c = " ; cin >> c ;
triangle( &a , &b , &c) ; }
masala_21
#include
#include
using namespace std ;
int main(){
ofstream file("21savol.txt");
int n , s=0 , m;
cin >> n ;
for(int i=1 ; i<=n; i++){
cin >> m;"\n";
file << m << endl ;
ofstream fayl("21savol2.txt");
s = s + m ;
fayl << s ; }}
masala_23
#include
#include
#include
using namespace std ;
int main(){
ofstream file("23savol.txt");
int n , s=0 , m;
cin >> n ;
for(int i=1 ; i<=n; i++){
cin >> m;"\n";
file << m << endl ;
ofstream fayl("23savol2.txt");
s = s + pow(m,2) ;
fayl << s ;
}
cout << s ; }
masala_25
#include
#include
using namespace std ;
int main(){
ofstream file("25savol.txt");
int n , m , max=0;
cin >> n ;
for(int i=1 ; i<=n; i++){
cin >> m;"\n";
file << m << endl ;
ofstream fayl("25savol2.txt");
if(max max = m ;
}
fayl << max ;
}
cout <<"max = " << max ;
}
masala_27
#include
#include
#include
using namespace std ;
int main(){
ofstream file("13savol.txt");
int n , m , a , b , c ;
cin >> n ;
if(n<=27){
for(int i=100 ; i<=999; i++){
a = i % 10 ;
b = (i / 10) % 10 ;
c = (i / 100) ; // 1-raqam
if((a+b+c)==n){
cout << i << endl ;
file << i << endl ; }
} } }
Fayillar
/*. Ikkita natural sonning EKUK , EKUB va ikkita sonning o’zini “natija.txt”
fayliga yozing. Bunda 20 ta satrdan iborat natijalar faylga yozilsin.*/
#include
#include
using namespace std;
int main(){
ofstream natija("C:\\Users\\User\\Desktop\\natija.txt");
int a, b, ekub, ekuk;
cin>>a>>b;
for(int i=1; i<=10; i++){
ekuk=a;
while(ekuk%a!=0 || ekuk%b!=0) {
ekuk++; }
natija<natija.width(10);
natija<<"ekuk="<int N;
cin>>N;
for(int i=1; i<=N; i++)
{
if(N%i==0) natija<}
// cout << "Hello world!" << endl;
return 0;
}
/*Berilgan sonning eng katta raqamini va sonning o’zining
“MaxNumber.txt” fayliga yozing. 10 ta qatordan iborat natijalar faylga yozilsin.*/
#include
#include
using namespace std;
int main()
{int s=0, s1, n;
ofstream file("C:\\Users\\User\\Desktop\\natija.txt");
if(file.is_open())
{
for(int i=0; i<10; i++)
{
cout<<"n="; cin>>n;
file<<"n="<int p=n;
while(n<0);
{
s1=n%10;
if(s1>s)
s=s1;
n=n/10;
}
cout<<"eng katta raqam="<file<<"eng katta raqam="<s=0;
}
}
else{
cout<<"fayl ochilmadi! "<return -1;
} }
/*O’ttizta son yozilgan turlashgan fayl mavjud. Boshqa faylga mavjud faylni
teskari tartibda yozilsin.
*/
#include
#include
using namespace std;

int main()


{ int m=1, n, a[30];
ifstream file("C:\\Users\\User\\Desktop\\natija.txt");
ofstream file1("C:\\Users\\User\\Desktop\\natija1.txt");
if(file.is_open())
{ while(!file.eof())
{ file>>n;
a[m]=n;
m++;
}
for(int i=30; i>0; i--)
file1<cout<<"fayl muvaffaqiyatli yozildi";
}
else
cout<<"fayl ochilmadi"<return -1;


}
STRUCTURALAR
/*2. Mashina egasining familyasi, rangi, rusumi va davlat nomeriga
ega bo‘lgan struktura yarating va faqat oq rangli mashinalar egalarining familyasini ekranga chiqaring.*/
#include
#include
using namespace std;
int main()
{ struct haydovchi {
string familya;
string rang;
string rusum;
int nomer; };
haydovchi Yoldoshev={"Yoldoshev", "oq", "nexia", 556};
haydovchi Asadov={" Asadov", "oq", "nexia", 556};
haydovchi Ahmedov={"Ahmedov", "qora", "nexia", 556};
if(Yoldoshev.rang=="oq") cout<<"Yoldoshev"<if(Asadov.rang=="oq") cout<<"Asadov"<if(Ahmedov.rang=="oq") cout<<"Ahmedov"<return 0;
}/*4. Tog‘ cho‘qqilarining nomi, balandligi, joylashgan davlat
nomi haqida structura yarating. Eng baland cho‘qqi joylashgan davlat
nomi, cho‘qqi nomi va balandligini aniqlang.*/
#include
#include
using namespace std;
int main()
{ int a;
struct tog
{
string nom;
int balandlik;
string davlat;
};
tog jomalungma={"jomolungma", 8848, "hindiston"};
tog klimanjiro={"klimanjiro", 5568, "kongo"};
tog monblan={"monblan", 6829, "rossiya"};
a=max(max(jomalungma.balandlik, klimanjiro.balandlik),monblan.balandlik);
if(a==jomalungma.balandlik) cout<
if(a==klimanjiro.balandlik) cout<
if(a==monblan.balandlik) cout<
//cout << "Hello world!" << endl;
return 0;
}
/*6. Mehmonxonalar nomi, narxi, joylashgan ko‘cha nomi haqida structura yarating.
Eng arzon mehmonxona nomi va ko‘cha nomini aniqlang.*/
#include
#include
using namespace std;
int main()
{int a;
struct mehmonxona
{
string nom;
int narx;
string kocha;
};
mehmonxona safiya={"safiya", 100000, "zayniddin"};
mehmonxona sulton={"ulton", 150000, "navoiy"};
mehmonxona sarbon={"sarbon", 130000, "ulugbek"};
mehmonxona karvon={"karvon", 330000, "farovon"};
a=min(min(min(safiya.narx, sulton.narx),sarbon.narx),karvon.narx);
if(a==safiya.narx) cout<<"eng arzon mehmonxona nomi "<if(a==sulton.narx) cout<<"eng arzon mehmonxona nomi "<if(a==sarbon.narx) cout<<"eng arzon mehmonxona nomi "<if(a==karvon.narx) cout<<"eng arzon mehmonxona nomi "<return 0;
}
/*8. Talabalar familyasi, ismi, kursi, reyting bali haqida structura yarating.
X kursdagi eng a‘lochi talabani familya va ismini aniqlang.*/
#include
#include
using namespace std;
int main()
{ int a;
struct talaba
{
string familya;
string ism;
int kursi;
int ball;
};
talaba Ali={"Naimov","Ali", 2 , 63 };
talaba Vali={"Hakimov", "Vali", 2, 69};
talaba Ikrom={"Zohidov", "Ikrom", 2, 60};
talaba Shavkat={"Asadov", "Shavkat", 2, 73};
a=max(max(max(Ali.ball, Vali.ball),Ikrom.ball),Shavkat.ball);
if(a==Ali.ball) cout<<"eng a'lochi o'quvchi "<if(a==Vali.ball) cout<<"eng a'lochi o'quvchi "<if(a==Ikrom.ball) cout<<"eng a'lochi o'quvchi "<if(a==Shavkat.ball) cout<<"eng a'lochi o'quvchi "<return 0; }
/*10. Talabalar familyasi, ismi, kursi, reyting bali haqida structura yarating.
X kursdagi 5 bahoga o‘qiydigan talabalar familya va ismini aniqlang.*/
#include
#include
using namespace std;
int main()
{ int a;
struct talaba
{
string familya;
string ism;
int kursi;
int ball;
};
talaba Ali={"Naimov","Ali", 2 , 85 };
talaba Vali={"Hakimov", "Vali", 2, 91};
talaba Ikrom={"Zohidov", "Ikrom", 2, 96};
talaba Shavkat={"Asadov", "Shavkat", 2, 99};
if( Ali.ball>=90) cout<<"eng a'lochi o'quvchi "<if( Vali.ball>=90) cout<<"eng a'lochi o'quvchi "<if(Ikrom.ball>=90) cout<<"eng a'lochi o'quvchi "<if( Shavkat.ball>=90) cout<<"eng a'lochi o'quvchi "<return 0; }
/*12. Talabalar familyasi, ismi, kursi, reyting bali haqida structura yarating.
X kursdagi 3 bahoga o‘qiydigan talabalar familya va ismini aniqlang.*/
#include
#include
using namespace std;
struct talaba
{ string familya;
string ism;
int ball; };
int main()
{ int n, i;
cout<<"Talaba sonini kiriting : "; cin>>n;
talaba Davron [n];
for(int i=0; i{
cout<>Davron[i].familya;
}
for(int j=0; j{
cout<>Davron[j].ism;
}
for(int i=0; i{
cout<>Davron[i].ball;
}
for(int i=0; iif(Davron[i].ball>60 && Davron[i].ball<73) cout<}
}
/*14. Shaxar poliklinikasining aholisi haqida familyasi, ismi, kasallik haqida struktura yarating.
Shaxar aholisi ichida kasallik mavjud bo‘lmagan odamlarning familyasi, ismi va sonini aniqlang.*/
#include
using namespace std;
struct aholi
{
string familya;
string ism;
string kasallik;
};
int main()
{ int n, m=0;
cout<<"aholi sonini kiriting : "; cin>>n;
aholi Davron [n];
for(int i=0; i{
cout<>Davron[i].familya;
}
for(int j=0; j{
cout<>Davron[j].ism;
}
for(int k=0; k{
cout<>Davron[k].kasallik;
}
for(int k=0; kif(Davron[k].kasallik=="yo'q") {m++;
cout<<"kasali yo'q aholilar soni "<cout<<"ismi "<}
}
}
/*18. O‘qituvchilarning familyasi, ismi, lavozimi, tug‘ilgan yili haqida struktura yarating.
X yoshga kirgan o‘qituvchilarning familyasi va ismini aniqlang
*/
#include
#include
using namespace std;
struct oqituvchi
{
string familya;
string ism;
string lavozim;
int yil;
};
int main()
{
int n;
oqituvchi Davron [n];
cout<<"o'qituvchi sonini kiriting "; cin>>n;
for(int i=0; i{
cout<>Davron[i].familya;
}
for(int j=0; j{
cout<>Davron[j].ism;
}
for(int f=0; f{
cout<>Davron[f].lavozim;
}
for(int i=0; i{
cout<>Davron[i].yil;
}
for(int j=0; j{
cout<<2022-Davron[j].yil<<" yoshli o'qituvchi ismi va familyasi "<< Davron[j].ism<<" "<}}

FAYLLAR AMALIYOT


/*1. Ikkita natural sonning EKUK , EKUB va ikkita sonning o’zini “natija.txt”
fayliga yozing. Bunda 20 ta satrdan iborat natijalar faylga yozilsin.*/
#include
#include
using namespace std;
int main()
{
ofstream natija("C:\\Users\\User\\Desktop\\natija.txt");
int a, b, ekub, ekuk;
cin>>a>>b;
for(int i=1; i<=10; i++){
ekuk=a;
while(ekuk%a!=0 || ekuk%b!=0)
{
ekuk++;
}
natija<natija.width(10);
natija<<"ekuk="<int N;
cin>>N;
for(int i=1; i<=N; i++)
{
if(N%i==0) natija<}
return 0;
}
4)N ta son faylga yozilgan. Ushbu fayldagi eng kichik va eng katta sonlarni qo’shish natija toping.
#include
#include
using namespace std;
int main()
{ int n, max1=0,min1=0;
ifstream file("C:\\Users\\User\\Desktop\\natija.txt");
if(file.is_open()){
while(!file.eof())
{
file>>n;
if(n>min1)
min1=n;
if(nmax1=n;
}
cout<<"eng katta son="<cout<<"eng kichik son="<cout<<"bu sonlar yig'indisi="<else{
cout<<"fayl ochilmadi"<return -1;
}}
5)
/*O’ttizta son yozilgan turlashgan fayl mavjud. Boshqa faylga mavjud faylni
teskari tartibda yozilsin.
*/
#include
#include
using namespace std;
int main()
{ int m=1, n, a[30];
ifstream file("C:\\Users\\User\\Desktop\\natija.txt");
ofstream file1("C:\\Users\\User\\Desktop\\natija1.txt");
if(file.is_open())
{ while(!file.eof())
{ file>>n;
a[m]=n;
m++;
}
for(int i=30; i>0; i--)
file1<cout<<"fayl muvaffaqiyatli yozildi";
}
else
cout<<"fayl ochilmadi"<return -1;
}
6)/*Faylga shahar nomi va uning aholisi soni yozilgan. Har bir shaharning aholisini
5% ga oshiring (aholi miqdori – har doim butun son).*/
#include
#include
using namespace std;
int main()
{ int m, n, a[30];
string s;
ifstream natija("C:\\Users\\User\\Desktop\\natija.txt");
ofstream natija1("C:\\Users\\User\\Desktop\\natija1.txt");
if(natija.is_open())
{
while(!natija.eof())
{
natija>>s;
natija>>n;
m=n*1.05;
natija1<cout<<"fayl muvofaqiyatli yozildi"<else
cout<<"fayl ochilmadi"<return -1; }}
10-11-masala
Svitafor
#include
#include
using namespace std;
int main(int argc, char* argv[])
{ initwindow(700, 700);
rectangle(100, 100, 350, 470);
for( ; ; ){
circle(220, 180, 50);
setfillstyle(1, RED);
floodfill(220, 180, WHITE);
circle(220, 290, 50);
setfillstyle(1, BLACK);
floodfill(220, 290, WHITE);

circle(220, 400, 50);


setfillstyle(1, BLACK);
floodfill(220, 400, WHITE);
delay(3000);
circle(220, 180, 50);
setfillstyle(1, 0);
floodfill(220, 180, WHITE);
circle(220, 290, 50);
setfillstyle(1, YELLOW);
floodfill(220, 290, WHITE);
circle(220, 400, 50);
setfillstyle(1, BLACK);
floodfill(220, 400, WHITE);
delay(1000);
circle(220, 180, 50);
setfillstyle(1, 0);
floodfill(220, 180, WHITE);
circle(220, 290, 50);
setfillstyle(1, BLACK);
floodfill(220, 290, WHITE);
circle(220, 400, 50);
setfillstyle(1, GREEN);
floodfill(220, 400, WHITE);
delay(4000);}
system("PAUSE");
return 0;}


Yüklə 39,34 Kb.

Dostları ilə paylaş:




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin