Reja: String turidagi satrlar haqida
Download 1.3 Mb. Pdf ko'rish
|
12-Ma\'ruza. C da satrli kattaliklar v ular bilan ishlash.
1.
#include 2. void main() 3. { 4. String s1=”01234567893456ab2csef”, s2=”456”, s3=”ghk”; 5. cout<<“s1=”< 6. cout<<“s2=”< 7. cout<<“s3=”< 8. if(s2.compare(s3)>0)cout<<“s2>s3”< 9. if(s2.compare(s3)==0)cout<<“s2=s3”< 10. if(s2.compare(s3)<0)cout<<“s2 11. if(s1.compare(4,6,s2)>0)cout<<“s1[4-9]>s2”< 12. if(s1.compare(5,2,s2,1,2)==0) 13. cout<<“s1[5-6]=s2[1-2]”< 14. } 1. #include 2. #include 3. int main(int argc, char* argv[]) 4. { 5. const int FISh_uzunligi=50; 6. string * Talaba; 7. char * Satr=(char*)malloc(FISh_uzunligi ); 8. unsigned int talabalar_soni; 9. char son[3]; 10. do 11. { 12. cout<<"Talabalar sonini kiriting: "; 13. cin>>son; 14. } 15. while((talabalar_soni=atoi(son))< =0); 16. Talaba =new string[talabalar_soni]; 17. cin.ignore(); 18. for(int i=0; i 19. { 20. cout< Familya ismi sharifi: "; 21. cin.getline(Satr,50); 22. Talaba[i].assign(Satr); 23. } bool almashdi=true; 24. for(int i=0; i almashdi; i++) 25. {almashdi=false; 26. for(int j=i; j j++) 27. if(Talaba[j].compare(Talaba[j+1])> 0) 28. { 29. almashdi=true; 30. strcpy(Satr,Talaba[j].data()); 31. Talaba[j].assign(Talaba[j+1]); 32. Talaba[j+1].assign(Satr); 33. } 34. } 35. cout<<"Alfavit bo'yicha tartiblangan ro'yxat:\n"; 36. for(int i=0; i 37. cout< 38. delete [] Talaba; 39. free(Satr); 40. return 0; 41. } string sinfida satr uzunligi, uning bo‘shligini yoki egallagan xotira hajmini aniqlaydigan funksiyalar bor: unsigned int size()const; // сатр ўлчами unsigned int length()const; // сатр элементлар сони unsigned int max_size()const; // сатрнинг максимал // узунлиги(4294967295) unsigned int capacity()const;// сатр эгаллаган хотира // ҳажми bool empty()const; // true, агар сатр бўш бўлса String tipidagi o’zgaruvchilar bu dinamik massiv hisoblanib, o’zida 255 tagacha belgi saqalydi. Ushbu turdagi o’zgaruvchilarga qayta ishlov beruvchi bir nechta funksiyalar aniqlangan. Baza kompilyatorlarda bu funksiyalarning ko’rinishlari o’zgargan holda keladi, lekin uning nomidan nima vazifa qilishini aniqlab olish qiyin ish emas. Download 1.3 Mb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling