using namespace std;
class Qurilmalar{
public:
int serias = 123456789;
int parol = 1;
void kirish(int p){
if(p == parol){
cout<}else{
cout<<"Xato parol";
}
}
};
class Kom:public Qurilmalar{
public:
void print(){
cout<<"Windows 10 tizimi\n";
}
};
class Tel:public Qurilmalar{
public:
void print(){
cout<<"android tizimi\n";
}
};
int main()
{
Kom obj;
Tel obj1;
obj.print();
obj1.print();
obj1.kirish(1);
obj.kirish(2);
return 0;
}
36. Device (Qurilma) nomli ajdod sinf hosil qiling. Uning tarkibida qurilma seril raqami va paroli xossalari bo’lsin. Computer va Telephone avlod sinflarini hosil qilib, uning qaysi operatsion sistemadan foydalanayotgani haqida xabarni chop etuvchi metodlarini yarating. Agar qurilma paroli to’g’ri kiritilganda tizim tushgani xabar chop etilsin.
#include
#include
using namespace std;
class Qurilmalar{
public:
int serias = 123456789;
int parol = 1;
void kirish(int p){
if(p == parol){
cout<}else{
cout<<"Xato parol";
}
}
};
class Kom:public Qurilmalar{
public:
void print(){
cout<<"Windows 10 tizimi\n";
}
};
class Tel:public Qurilmalar{
public:
void print(){
cout<<"android tizimi\n";
}
};
int main()
{
Kom obj;
Tel obj1;
obj.print();
obj1.print();
obj1.kirish(1);
obj.kirish(2);
return 0;
}
70. Farmer (Fermer) nomli sinf hosil qiling. Uning FISH, fermer xo’jalik nomi, hosil miqdori nomli maydonlari bo’lsin. Sinfdan tashqarida hosil miqdorini taqqoslaydigan funksiya hosil qiling. 10 ta fermerlar ichida eng ko’p hosil yetishtirgan fermerni aniqlang. Sinf shablonidan foydalaning.
#include
using namespace std;
class Fermaer{
public:
int miqdor[10],max=0,min=0;
string fio[10],nomi[10];
void ins(){
for(int i=0;i<10;i++){
cin>>fio[i]>>nomi[i]>>miqdor[i];
}
}
int sort(){
max = miqdor[0];
for(int i=0;i<10;i++){
if(maxmax = miqdor[i];
}
}
return max;
}
};
int main(){
Fermaer A;
A.ins();
A.sort();
}
74. ax+b=0 chiziqli tenglama yechimini topishda yuz beradigan istisnoli holatlarni generatsiya qiling.
#include
using namespace std;
string solveEquation(string equation)
{
int n = equation.size(), sign = 1, coeff = 0;
int total = 0, i = 0;
for (int j = 0; j < n; j++) {
if (equation[j] == '+' || equation[j] == '-') {
if (j > i)
total += sign * stoi(equation.substr(i, j - i));
i = j;
}
else if (equation[j] == 'x') {
if ((i == j) || equation[j - 1] == '+')
coeff += sign;
else if (equation[j - 1] == '-')
coeff -= sign;
else
coeff += sign * stoi(equation.substr(i, j - i));
i = j + 1;
}
else if (equation[j] == '=') {
if (j > i)
total += sign * stoi(equation.substr(i, j - i));
sign = -1;
i = j + 1;
}
}
if (i < n)
total += sign * stoi(equation.substr(i));
if (coeff == 0 && total == 0)
return "Infinite solutions";
if (coeff == 0 && total)
return "No solution";
int ans = -total / coeff;
return "x=" + to_string(ans);
}
int main()
{
string equation = "x+5-3+x=6+x-2";
cout << solveEquation(equation);
return 0;
}
91. Trapezia (Trapetsiya) nomli sinf yozing. Uning yuzasi va perimetrini aniqlash metodlari bo’lsin. N ta trapetsiya uchun natijalarni faylga yozing.
#include
using namespace std;
class Trapetsiya{
public:
int s,p;
int yuza(int h, int ur){
s = h*ur;
return s;
}
int parametr(int a,int b,int c, int d){
p = a+b+c+d;
return p;
}
};
int main(){
Trapetsiya A;
ofstream read("text.txt");
int n,h,ur,a,b,c,d;
cin>>n;
for(int i=1;i<=n;i++){
cout<<"balandligi : "; cin>>h;
cout<<"Urta chizig`i : "; cin>>ur;
cout<<" Tomonlari : "; cin>>a>>b>>c>>d;
read << A.yuza(h,ur);
read << A.parametr(a,b,c,d);
}
}
Do'stlaringiz bilan baham: