Maxmatqulov Mashrabbek SWD007_L2 Saidov Samandar Muzzafarovich
Stol va stul class larini yarating va ularni bog’lovchi funksiyalar yarating
#include
#include
using namespace std;
namespace Mebel{
class M
{
private:
float buyi, eni, balandligi, ogirligi;
int narxi, tayyorl_yil, id;
bool yaroqliligi;
string rangi;
public:
friend void Qidirish(M m[], int n)
{
string l;
cout<<"\t\t\t\tRangi bo'yicha izlash \n rangi nomini kiriting:"; cin>>l;
for(int i=0; i if(m[i].rangi.compare(l) == 0){
m[i].get();
}
}
}
friend void Saralash(M m[], int n){
cout<<"\t\t\t\t og'irligi bo'yicha saralash\n"< M min = m[0];
for(int j=0; j for(int i=0; i if(m[i].ogirligi min=m[i];
m[i]=m[j];
m[j]=min;
}
}
}
for (int i = 0; i m[i].get();
}
cout<
}
friend void O_zgartirish(M m[], int n){
int k; string rang;
cout<<"\t\t\t\t Rangi haqidagi ma'lumotlarni o'zgartirish"< cout<<"O'zgartirmoqchi bo'lgan mebel id raqamini kiriting:"; cin>>k;
for(int i=0; i if(m[i].id == k){
cout<<"rang nomini kiriting: "; cin>>rang;
m[i].rangi =rang;
}
};
};
void get(){
cout<id<<"\t"<buyi<<"\t"<eni<<"\t"<ogirligi<<"\t\t"<rangi<<"\t"<narxi<<" so'm'\t"<<((this->yaroqliligi) ? "Yaroqli" : "\tYaroqsiz")< cout<<"--------------------------------------------------------------------------------|"< }
void set(int id,float buyi, float eni,float balandligi, float ogirligi, string rangi)
{
this->id = id;
this->buyi = buyi;
this->eni = eni;
this->balandligi = balandligi;
this->ogirligi = ogirligi;
this->rangi = rangi;
}
void setNarx(int tayyorl_yil, int hozirgi_yil)
{
this->yaroqliligi = true;
switch(hozirgi_yil - tayyorl_yil)
{
case 0: this->narxi = 300000; break;
case 1: this->narxi = 250000; break;
case 2: this->narxi = 200000; break;
case 3: this->narxi = 150000; break;
default:
{
this->yaroqliligi = false;
this->narxi = 0;
}
}
};
};
};
using namespace Mebel;
int main(){
for(int i=0; i<100; i++){
}
M a[100];
float buyi[] = {12, 13, 1};
float eni[] = {13, 14, 15};
float balandligi[] = {6, 8, 3};
float ogirligi[] = { 13.2,12, 14};
int tayyorl_yil[] = {2001, 2004, 2007};
string rangi[] = {"qizil", "sariq", "qizil"};
for(int i=0; i<3; i++){
a[i].set(i,buyi[i], eni[i], balandligi[i],ogirligi[i], rangi[i]);
a[i].setNarx(tayyorl_yil[i], 2008);
}
cout<<"\n\t\t\t\tMebellar\n\n ";
cout<<"id\t "<<"bo'yi\t"<<"eni\t"<<"Og'irlik\t"<<"rang\t"<<"Narxlari\t"<<"Yaroqliligi\n";
cout<<"--------------------------------------------------------------------------------|\n";
for(int i=0; i<3; i++){
a[i].get();
}
Qidirish(a, 3);
Saralash(a, 3);
O_zgartirish(a, 3);
for(int i=0; i<3; i++){
a[i].get();
}
return 0;
}
#include
#include
-using namespace std;
class Kitob{
protected:
string nomi;
int asl_narx;
protected:
int sahifa_soni,narxi;
public:
void set(string nomi,int sahifa_soni, int narxi)
{
this->asl_narx = narxi;
this->nomi = nomi;
this->sahifa_soni = sahifa_soni;
this->narxi = narxi;
}
};
class Kitob_dukon:public Kitob{
private:
int foiz;
public:
Kitob_dukon(int foiz){
this->foiz = foiz;
};
void get()
{
cout<<"Kitob nomi: "<nomi< cout<<"Asl narxi:"<asl_narx< cout<<"Narxi: "<narxi< cout<<"chegirma foizi:"<<((this->sahifa_soni<200)? this->foiz: 0)< cout<<"Sahifa soni: "<sahifa_soni< cout<<"-----------------------------------------------------"< }
friend void foiz_uzgart(Kitob_dukon ki){
int f;
cout<<"\n\t\t\tYangi foiz bilan hisoblash\n\n";
cout<<"chegirma foizini kiriting:"; cin>>f;
ki.foiz = f;
ki.chegirma();
ki.get();
// cout<<"\n\t\t Kitoblar ro'yxati\n\n----------------------------------------------------- \n";
//
//
// cout<<"Nomi:"<// cout<<"Narxi:"<<((ki.sahifa_soni<200) ? ki.narxi*(100-f)/100 : ki.narxi )<// cout<<"Sahifa soni"<// cout<<"-----------------------------------------------------"< }
void chegirma(){
if(this->sahifa_soni<200){
this->narxi = this->asl_narx*(100-this->foiz)/100;
}
}
};
int main(){
Kitob_dukon ki(20) ;
string nomi="Gulliverning sayohatlari";
int narxi = 13000;
int sahifa_soni= 220;
ki.set(nomi, sahifa_soni, narxi);
ki.chegirma();
cout<<"\n\t\t Kitob haqida\n\n----------------------------------------------------- \n";
ki.get();
foiz_uzgart(ki);
ki.chegirma();
return 0;
}
#include "iostream"
#include "string"
#include "time.h"
#include "stdlib.h"
using namespace std;
class inson{
protected:
string ism, turi;
int yosh;
public:
template
friend void haqimda(F a);
template
friend void Salom(T m, F a);
template
friend void Salomlashish(T m, F a);
void get(){
cout<<"Ism:"<ism< cout<<"Yosh:"<yosh< cout<<"Turi:"<turi< cout<<"--------------------------------\n";
}
void setYosh(){
srand(time(NULL));
this->yosh =rand()%21+20;
}
};
class realist :public inson{
public:
realist(string ism){
this->turi = "realist";
this->ism = ism;
this->setYosh();
}
};
class norasmiy:public inson{
public:
norasmiy(string ism){
this->turi = "norasmiy";
this->ism = ism;
this->setYosh();
}
};
class rasmiy:public inson{
public:
rasmiy(string ism){
this->turi = "rasmiy";
this->ism = ism;
this->setYosh();
}
};
template
void Salom(T m, F a){
cout< if(m.turi == "rasmiy")cout<<"Assalomu alaykum "< else if("norasmiy")cout<<"Salom "< else{
if(m.yosh >=a.yosh || a.yosh<=5)
cout<<"Salom "< else
cout<<"Assalomu alaykum "< }
}
template
void Salomlashish(T m, F a){
Salom(m, a);
Salom( a, m);
}
template
void haqimda(F a){
cout<<"-------------------"< cout<<"Salom, mening ismim "< cout<<((a.turi=="norasmiy")? "Men rasmiy so'zlashmayman" : ((a.turi == "rasmiy")? "Rasmiy usulda so'zlashishni yoqtiraman." : "Men realistman. Hayotga real qarash kerak!" ))< }
int main(){
realist Andrey("Andrey");
rasmiy Tatiana("Tatiana");
rasmiy Tamara("Tamara");
norasmiy Irina("Irina");
norasmiy Aleksandr("Aleksandr");
cout<<" Insonlar haqida ma'lumot \n------------------------------------\n";
inson A[] = {Aleksandr, Irina, Tamara, Tatiana, Andrey};
for(int i=0; i<5; i++){
A[i].get();
}
cout<<"\n\nO'zlari haqida ma'lumotlari\n\n";
for(int i=0; i<5; i++){
haqimda(A[i]);
cout<<"\n-----------------------------------\n";
}
cout<<"\n\nSalomlashish\n\n";
for(int j=0; j<5; j++){
for(int i=0; i Salomlashish(A[i], A[j]);
cout<<"\n";
}
}
}
Do'stlaringiz bilan baham: |