/*定义一个简单的Computer类
有数据成员芯片(cpu)、内存(ram)、光驱(cdrom)等等,
有两个公有成员函数run、stop。cpu为CPU类的一个对象,
ram为RAM类的一个对象,cdrom为CDROM类的一个对象,
定义并实现这个类。
2018.4.3
*/
  • 代码如下

#include<iostream>
#include<string>
using namespace std;
class CPU{
public:
CPU(int sta,string tp);
CPU(const CPU &ad);
~CPU();
void details();
private:
int standard;
string brand;
};
CPU::CPU(int sta,string tp){
this->standard = sta;
this->brand = tp;
}
CPU::CPU(const CPU &ad) {
cout << endl << "Warnning:This Copy constructors.!!!" << endl;
this->brand = ad.brand;
this->standard = ad.standard;
}
CPU::~CPU(){ };
void CPU::details(){
cout << "The details of CPU:" << endl;
cout << "The brand is " << brand << endl;
cout << "The standard is " << standard << endl << endl;
}
class RAM{
public:
RAM(int mem,int bit, string tp);
RAM(RAM &ad);
~RAM();
void details();
private:
int memory;
int bits;
string brand;
};
RAM::RAM(int mem, int bit, string tp){
this->memory = mem;
this->bits = bit;
this->brand = tp;
}
RAM::RAM(RAM &ad){
cout << endl << "Warnning:This Copy constructors.!!!" << endl;
this->memory = ad.memory;
this->bits =ad.bits;
this->brand =ad.brand;
}
RAM::~RAM(){ }
void RAM::details(){
cout << "The details of RAM:" << endl;
cout << "The brand is " << brand << endl;
cout << "The memory is " << memory<< endl;
cout << "The bits are " << bits << endl << endl;
}
class CDROM
{
public:
CDROM(int st, string bra);
CDROM(CDROM &ad);
~CDROM();
void details();
private:
int standard;
string brand;
};
CDROM::CDROM(int st, string bra){
this->brand = bra;
this->standard = st;
}
CDROM::CDROM(CDROM &ad) {
cout << endl << "Warnning:This Copy constructors.!!!" << endl;
this->brand = ad.brand;
this->standard = ad.standard;
}
CDROM::~CDROM(){ }
void CDROM::details(){
cout << "The details of CDROM:" << endl;
cout << "The brand is " << brand << endl;
cout << "The standard is " << standard << endl << endl;
}
class Computer {
public:
Computer(CPU cp,RAM ra,CDROM cdro);
Computer(Computer &ad);
~Computer();
void stop();
void run();
void details();
private:
CPU cpu;
RAM ram;
CDROM cdrom;
};
Computer::Computer(CPU cp, RAM ra, CDROM cdro):cpu(cp),ram(ra),cdrom(cdro){
cout << "Computer is OK!" << endl;
}
Computer::Computer(Computer &ad): cpu(ad.cpu), ram(ad.ram), cdrom(ad.cdrom) {
cout << endl << "Warnning:This Copy constructors.!!!" << endl;
cout << "Computer is OK!" << endl;
}
Computer::~Computer() { }
void Computer::run(){
cout << "Computer is running!" << endl;
}
void Computer::stop(){
cout << "Computer stoped!" << endl;
}
void Computer::details(){
cpu.details();
ram.details();
cdrom.details();
}
int main(void){
CPU cp(1,"!@!");
RAM ra(1024,10,"!#@!$");
CDROM cd(2561,"$#%$#^");
Computer cs(cp, ra, cd);
cs.run();
cs.details();
cs.stop();
return 0;
}
  • 测试截图

最新文章

  1. 如何应对ISP乱插广告(案例分析)
  2. 邻接矩阵无向图(一)之 C语言详解
  3. VS 2013 打包程序教程
  4. Cheatsheet: 2013 12.01 ~ 12.16
  5. ubuntu安装多个qt版本--不同qt版本编译同一个程序时出现错误--解决方案
  6. new tips
  7. SpringMVC 实现邮件发送功能
  8. JRE下的rt.jar、tools.jar
  9. 【转载】 Searching过程粗略梳理
  10. Android UI ActionBar功能-Action Bar 左上角的向上或返回按钮
  11. 2014年百度之星程序设计大赛 资格赛第一题 (longlong)
  12. php中比较两个变量是否相等的最高效写法
  13. 我的第一个python web开发框架(14)——后台管理系统登录功能
  14. Actor-ES框架:Ray
  15. 基于Java的ArrayList和LinkedList的实现与总结
  16. JVM调优常用参数和注意点备忘录
  17. 第四周读书笔记——读《我是一只IT小小鸟》有感
  18. C和C指针小记(七)-整型变量范围
  19. python 传递多个参数
  20. python - requests中添加配置文件

热门文章

  1. HDU 4268 multiset
  2. 线程安全的Dictionary
  3. 有关satement与preparedstatement
  4. CSS Hack兼容
  5. Python中and和or的运算法则
  6. css居中那些事
  7. Node 的fs模块
  8. 新发布 | Azure镜像市场正式上线
  9. npm run dev运行Vue项目报错:Node Sass does not yet support your current environment
  10. 长大DeepMind第一次团队作业