C++程序题.doc

上传人:yyf 文档编号:8635881 上传时间:2020-12-09 格式:DOC 页数:3 大小:16KB
返回 下载 相关 举报
C++程序题.doc_第1页
第1页 / 共3页
C++程序题.doc_第2页
第2页 / 共3页
C++程序题.doc_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《C++程序题.doc》由会员分享,可在线阅读,更多相关《C++程序题.doc(3页珍藏版)》请在三一文库上搜索。

1、.1.有两个长方柱,其长.宽.高分别是(1)12,20,25;(2)10,14,20;求它们的体积,编写一个基于对象的程序,在类中用带参数的构造函数对数据成员初始化。#include using namespace std;class Boxpublic: Box(int,int,int); int volume();private: int height; int width; int length;Box:Box(int h,int w,int len)height=h;width=w;length=len;int Box:volume()return(height*width*lengt

2、h);int main()Box box1(12,25,30);coutThe volume of box1 is box1.volume()endl;Box box2(15,30,21);coutThe volume of box2 is box2.volume()endl;return 0;2.声明一个基类学生,在声明基类的公用派生类研究生,用指向基类对象的指针输出数据。#include #include using namespace std;class Studentpublic:Student(int ,string ,float); void display();private:i

3、nt num;精品.string name;float score; ;Student:Student(int n,string nam ,float s)num=n;name=nam;score=s;void Student:display()coutendlnum:numendl;coutendlname:nameendl;coutendlscore:scoreendl;class Graduate: public Studentpublic:Graduate(int ,string ,float,float );void display();private:float wage;Graduate:Graduate(int n,string nam,float s,float w):Student(n,nam,s),wage(w)Void Graduate:display() Student:display()Cout”wage=”wagedisplay();pt=&gra1;pt-display(); 如有侵权请联系告知删除,感谢你们的配合!精品

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1