942 – 19 guruhi talabasi Zaripboyev Anvar 12 – tajriba ishi (mta)
Download 53.91 Kb.
|
12 - tajriba ishi
- Bu sahifa navigatsiya:
- Satrlar ustida amallar.
Satr sinf sifatida
String turi. Satrlar bilan ishlash uchun standart kutubxonaga kiruvchi string sinfidan foydalanish qulay. Bu turdan foydalanish uchun quyidagi sarlavhali faylni ulash lozim: #include string st(”BAHO \n"); //sinivollar satri bilan initsiallash string st2; // bo‘sh satr string st3(st); shu turdagi o‘zgaruvchi bilan inltslallash Satrlar ustida amallar. Satrlar ustida quy idagi amallar aniqlangan: qiymat berish (=); ikki amal ekvivalentligini tekshirish uchun (= =) va (!=); konkatenatsija yoki satrlarni ulash (+); qiyinat berib qo‘shish amali (- =) ; indeks olish ([]). Usullar. Satr uzunligini aniqlash uchun size() funksiyasidan foydalaniladi (uzunlik tugallovchi simvolni hisobga olmaydi). cout << "uzunlik" << st << ":" << st.size(); Maxsus empty() usuli agar satr bo‘sh bo‘lsa true qaytaradi, aks holda false qaytaradi: if (st.empty()) // to‘g‘ri: bo‘sh Misol: #include using namespace std; int main() { string str("fa.disney.com"); int size= str.size(); for (int ix= 0; ix if (str[ix] == '.')
str[ix] ='_'; cout< return 0; }
#include using namespace std;
struct Student {
string name; float rating; };
void Student_show(Student a) cout < cout < cout < }
int main() Student s = {"Mahmudov", 1, 3.5}; Student_show (s);
return 0; }
#include #include using namespace std; class employee
{
public: void show_employee(void); int change_salary(float);
long get_id(void); private:
string name; long employee_id;
float salary; };
employee::employee(string name, long employee_id, float salary) employee::name= name; employee::employee_id = employee_id; if(salary < 50000.0) employee::salary= salary; else
employee::salary=0.0; } void employee::show_employee(void) { cout << "Ism:" << name << endl; cout << "Nomer:" < cout << "Maosh:" << salary<< endl; }
int main() employee worker("Happy Jamsa", 101, 10101.0); worker.show_employee(); return 0; } Natija:
Ism: Happy Jamsa Nomer: 101 Maosh: 10101 Download 53.91 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling