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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[YTU]_2576( 虚函数练习:动物2)

發(fā)布時間:2025/4/16 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [YTU]_2576( 虚函数练习:动物2) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題目描述

長期的物種進(jìn)化使自然界出現(xiàn)了生活在陸地上的陸生動物和生活在水中的水生動物。根據(jù)已有主函數(shù)編寫動物類,陸生動物類和水生動物類。

輸入

動物的體長,體重,性別;

水生動物的體長,體重,性別,游泳速度;

陸生動物的體長,體重,性別,奔跑速度;

輸出

動物的體長,體重,性別;

水生動物的體長,體重,性別,游泳速度;

陸生動物的體長,體重,性別,奔跑速度;

樣例輸入

52 22 f 62 32 m 122 72 42 m 102

樣例輸出

height:52 weight:22 sex:f height:62 weight:32 sex:m swimming_speed:122 height:72 weight:42 sex:m running_speed:102#include <iostream> using namespace std; class animal {public:animal(int h,int w,char s):height(h),weight(w),sex(s){}virtual void display(){cout<<"height:"<<height<<endl<<"weight:"<<weight<<endl<<"sex:"<<sex<<endl;} protected:int height,weight;char sex; }; class aqu_animal:public animal {public:aqu_animal(int h,int w,char s,int s_p):animal(h,w,s),swimming_speed(s_p){}void display(){cout<<"height:"<<height<<endl<<"weight:"<<weight<<endl<<"sex:"<<sex<<endl<<"swimming_speed:"<<swimming_speed<<endl;}protected:int swimming_speed; }; class ter_animal:public animal { public:ter_animal(int h,int w,char s,int r_p):animal(h,w,s),running_speed(r_p){}void display(){cout<<"height:"<<height<<endl<<"weight:"<<weight<<endl<<"sex:"<<sex<<endl<<"running_speed:"<<running_speed<<endl;} protected:int running_speed; }; int main() {int a,b,s,r;char c;animal *p;cin>>a>>b>>c;animal pa(a,b,c);p=&pa;p->display();cin>>a>>b>>c>>s;aqu_animal pb(a,b,c,s);p=&pb;p->display();cin>>a>>b>>c>>r;ter_animal pc(a,b,c,r);p=&pc;p->display();return 0; }

總結(jié)

以上是生活随笔為你收集整理的[YTU]_2576( 虚函数练习:动物2)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。