日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

1477: 多重继承派生(1)--家具、床、沙发和沙发床

發(fā)布時間:2024/1/8 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 1477: 多重继承派生(1)--家具、床、沙发和沙发床 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1477: 多重繼承派生(1)--家具、床、沙發(fā)和沙發(fā)床

Description

家具類Furniture包含3個私有成員數據:家具類型(string type),家具主材料(string mat)和家具價格(int price)。成員函數包括構造函數(家具類型默認為unknown),三個獲取私有成員數據的函數(GetType,GetMat,GetPrice)和輸出家具類各成員數據函數show(輸出格式詳見Sample Output)。 床類Bed由Furniture類公有派生而來,包含1個私有成員數據:床類型(string bedtype)。成員函數包括構造函數(家具類型默認為“床”),獲取私有成員數據床類型的函數GetBedType和輸出床的各成員數據值的函數Show(輸出格式詳見Sample Output)。 沙發(fā)類Sofa由Furniture類公有派生而來,包含1個私有成員數據:座位數(int seats)。成員函數包括構造函數(家具類型默認為“沙發(fā)”),獲取私有成員數據座位數的函數GetSeats和輸出沙發(fā)的各成員數據值的函數Show(輸出格式詳見Sample Output)。 沙發(fā)床類SofaBed由Sofa類和Bed類公有派生,包含2個成員函數:構造函數(家具類型默認為“沙發(fā)床”),輸出沙發(fā)床的各成員數據值的函數Show(輸出格式詳見Sample Output)。 完成上述各類的設計。main函數已給定(如下所示),提交時只需要提交main函數外的代碼部分。 int main() { string mat,bedtype; int price,seats,cas=0; while(cin>>mat>>price>>bedtype>>seats) { cas++; cout<<"Case #"<<cas<<":"<<endl; Furniture furniture(mat,price); Bed bed(bedtype,mat,price); Sofa sofa(seats,mat,price); SofaBed sofabed(seats,bedtype,mat,price); cout<<"Furniture:"; ? ?furniture.Show(); cout<<"Bed:"; ? ? ? ? ?bed.Show(); cout<<"Sofa:"; ? ? ? ? sofa.Show(); cout<<"SofaBed:"; ? ? ?sofabed.Show(); } return 0; }

Input

包含多組數據(數據均正確合法) 每組測試數據1行,每行包含4個數據,第一個數據是字符串(表示家具主材料),第二個是整數(表示家具價格),第三個數據是字符串(表示床的類型),第4個數據是整數(表示座位數)。

Output

每組測試數據輸出具體格式詳見Sample Output。

Sample Input?

木材 870 雙人床 2 鋼材 410 單人床 1

Sample Output

Case #1: Function #1 is called! Function #1 is called! Function #3 is called! Function #1 is called! Function #5 is called! Function #1 is called! Function #5 is called! Function #3 is called! Function #7 is called! Furniture:unknown/木材/870 Function #2 is called! Bed:床/木材/雙人床/870 Function #4 is called! Sofa:沙發(fā)/木材/2/870 Function #6 is called! SofaBed:沙發(fā)床/雙人床/木材/2/870 Function #8 is called! Case #2: Function #1 is called! Function #1 is called! Function #3 is called! Function #1 is called! Function #5 is called! Function #1 is called! Function #5 is called! Function #3 is called! Function #7 is called! Furniture:unknown/鋼材/410 Function #2 is called! Bed:床/鋼材/單人床/410 Function #4 is called! Sofa:沙發(fā)/鋼材/1/410 Function #6 is called! SofaBed:沙發(fā)床/單人床/鋼材/1/410 Function #8 is called

代碼:

#include <iostream>
#include <string>
using namespace std;


class Furniture
{
public:
Furniture(string m,int p,string t="unknown"):mat(m),price(p),type(t)
{
cout<<"Function #1 is called!"<<endl;
}
string GetType()
{
return type;
}
string GetMat()
{
return mat;
}
int GetPrice()
{
return price;
}
void Show()
{
cout<<type<<"/"<<mat<<"/"<<price<<endl;
cout<<"Function #2 is called!"<<endl;
}
private:
string type,mat;
int price;
};


class Bed:virtual public Furniture
{
public:
Bed(string b,string m,int p):Furniture(m,p,"床"),bedtype(b)
{
cout<<"Function #3 is called!"<<endl;
}
string GetBedType()
{
return bedtype;
}
void Show()
{
cout<<"床"<<"/"<<GetMat()<<"/"<<GetBedType()<<"/"<<GetPrice()<<endl;
cout<<"Function #4 is called!"<<endl;
}
private:
string bedtype;
};


class Sofa:virtual public Furniture
{
public:
Sofa(int s,string m,int p):Furniture(m,p,"沙發(fā)"),seats(s)
{
cout<<"Function #5 is called!"<<endl;
}
int GetSeats()
{
return seats;
}
void Show()
{
cout<<"沙發(fā)"<<"/"<<GetMat()<<"/"<<GetSeats()<<"/"<<GetPrice()<<endl;
cout<<"Function #6 is called!"<<endl;
}
private:
int seats;
};


class SofaBed:public Sofa,public Bed
{
public:
SofaBed(int s,string b,string m,int p):Furniture(m,p),Sofa(s,m,p),Bed(b,m,p)
{
cout<<"Function #7 is called!"<<endl;
}
void Show()
{
cout<<"沙發(fā)床"<<"/"<<GetBedType()<<"/"<<Furniture::GetMat()<<"/"<<GetSeats()<<"/"<<Furniture::GetPrice()<<endl;
cout<<"Function #8 is called!"<<endl;
}
};
int main()
{
? ? string mat,bedtype;
? ? int price,seats,cas=0;
? ? while(cin>>mat>>price>>bedtype>>seats)
? ? {
? ? ? ? cas++;
? ? ? ? cout<<"Case #"<<cas<<":"<<endl;
? ? ? ? Furniture furniture(mat,price);
? ? ? ? Bed bed(bedtype,mat,price);
? ? ? ? Sofa sofa(seats,mat,price);
? ? ? ? SofaBed sofabed(seats,bedtype,mat,price);
? ? ? ? cout<<"Furniture:";? ? furniture.Show();
? ? ? ? cout<<"Bed:";? ? ? ? ? bed.Show();
? ? ? ? cout<<"Sofa:";? ? ? ? ?sofa.Show();
? ? ? ? cout<<"SofaBed:";? ? ? sofabed.Show();
? ? }
? ? return 0;
}

總結

以上是生活随笔為你收集整理的1477: 多重继承派生(1)--家具、床、沙发和沙发床的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: av电影网站在线观看 | 国产免费一区二区 | jizz俄罗斯 | 成年人黄色片网站 | 婷婷色中文字幕 | 国产二区在线播放 | 欧美网站免费 | 五月天六月色 | 久久久久久久久蜜桃 | 黄色大片免费的 | 亚洲色图综合 | 国产成人免费视频网站 | 特色特色大片在线 | 伊人免费在线观看高清版 | 噜噜噜噜噜色 | 污污内射久久一区二区欧美日韩 | 不卡的av在线播放 | 欧美r级在线观看 | 五月天最新网址 | 亚洲蜜桃精久久久久久久久久久久 | hitomi一区二区三区精品 | 亲切的金子餐桌片段的金子 | 亚洲青色在线 | 亚洲天堂区 | 96毛片| 97影院手机版 | 性色影院 | 香蕉狠狠爱视频 | 特级精品毛片免费观看 | 国产性―交―乱―色―情人 | 欧美综合图片 | 欧美又大粗又爽又黄大片视频 | 国产按摩一区二区三区 | 人人澡人人添 | 久久久91| 性大片潘金莲裸体 | 51国产在线| 色婷婷久久久亚洲一区二区三区 | 少妇做爰免费视看片 | 国产成年网站 | 激情宗合 | 在线午夜电影 | 三级欧美视频 | 色一情一区二区三区 | 爱上av| 久久8| 插吧插吧综合网 | 亚洲国产伊人 | 男女一区二区三区 | 小sao货大ji巴cao死你 | 国产精品传媒视频 | 国产一区二区三区在线视频观看 | 亚洲精品91在线 | 蜜桃臀av | 日韩视频不卡 | 日日摸日日碰 | 少妇被爽到高潮动态图 | 亚洲视频在线观看网站 | 91麻豆影视| 国产精品一级片在线观看 | 一区二区三区在线播放视频 | 国产精品制服丝袜 | 免费观看nba乐趣影院 | 免费性情网站 | 国产精品jizz视频 | 高潮白浆女日韩av免费看 | av一卡 | 精品女同一区二区三区 | 老女人黄色片 | 亚洲久久在线 | 69热在线观看 | 大奶av| 操操久久| 在线观看日本一区二区 | 美日韩一区二区三区 | 久久久久久草 | 色肉色伦交av色肉色伦 | 久久久久女教师免费一区 | 中国毛片在线 | 玖玖玖精品 | 99自拍偷拍 | 国产精品久久久久久在线观看 | 绿帽在线 | 国产精品白丝喷水在线观看 | 久久久久无码精品国产 | av网站久久 | 少妇高潮大叫好爽喷水 | 2020国产在线 | 91美女啪啪 | 国产女人与zoxxxx另类 | 亚洲欧美www| 亚洲二区在线播放视频 | www,av在线| 99视频热| 91香蕉在线视频 | 123超碰| 国产中文字幕三区 | 亚洲男人的天堂在线观看 | 日本在线观看免费 |