C++定义一个简单的Computer类
/*定义一个简单的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;
}
- 测试截图

C++定义一个简单的Computer类的更多相关文章
- python+selenium之自定义封装一个简单的Log类
python+selenium之自定义封装一个简单的Log类 一. 问题分析: 我们需要封装一个简单的日志类,主要有以下内容: 1. 生成的日志文件格式是 年月日时分秒.log 2. 生成的xxx.l ...
- Python之自定义封装一个简单的Log类
参考:http://www.jb51.net/article/42626.htm 参考:http://blog.csdn.net/u011541946/article/details/70198676 ...
- VC++ 一个简单的Log类
在软件开发中,为程序建立Log日志是很必要的,它可以记录程序运行的状态以及出错信息,方便维护和调试. 下面实现了一个简单的Log类,使用非常简单,仅供参考. // CLogHelper.h : hea ...
- Python+Selenium中级篇之8-Python自定义封装一个简单的Log类《转载》
Python+Selenium中级篇之8-Python自定义封装一个简单的Log类: https://blog.csdn.net/u011541946/article/details/70198676
- CREATE OPERATOR CLASS - 定义一个新的操作符类
SYNOPSIS CREATE OPERATOR CLASS name [ DEFAULT ] FOR TYPE data_type USING index_method AS { OPERATOR ...
- 一个简单的c++类的定义和实例化
#include "iostream" #include <string> using namespace std; class mycoach { private: ...
- lua定义一个简单的类
classA.lua: classA = { a = , b = , --__index = classA; }; classA.__index = classA; function classA:n ...
- [转贴]从零开始学C++之STL(二):实现一个简单容器模板类Vec(模仿VC6.0 中 vector 的实现、vector 的容量capacity 增长问题)
首先,vector 在VC 2008 中的实现比较复杂,虽然vector 的声明跟VC6.0 是一致的,如下: C++ Code 1 2 template < class _Ty, cl ...
- 自己写的一个简单的Tab类
//------------- PS_DOM 功能函数 start----------------var PS_DOM ={ indexOf: function(arr, e){ for(var i= ...
随机推荐
- info.plist 安全登录
设置info.plist 安全登录 App Transport Security Settings dictionary Allow Arbitrary Loads Boolean YES
- vue——指令系统
指令系统,可以联想咱们的cmd命令行工具,只要我输入一条正确的指令,系统就开始干活了. 在vue中,指令系统,设置一些命令之后,来操作我们的数据属性,并展示到我们的DOM上. 在vue中提供了一套为数 ...
- Python爬虫之requests模块(2)
一.今日内容 session处理cookie proxies参数设置请求代理ip 基于线程池的数据爬取 二.回顾 xpath的解析流程 bs4的解析流程 常用xpath表达式 常用bs4解析方法 三. ...
- Android XMPP 例子(Openfire+asmack+spark) 出现登陆连接错误
Android XMPP 例子(Openfire+asmack+spark) 运行出来没问题,但是登陆的时候出现如下错误: 出现错误: 09-17 15:24:16.388: E/AndroidRun ...
- CSS3控制单行文本的溢出
text-overflow用来设置是否使用一个省略标记(...)标示对象内文本的溢出.语法: 但是text-overflow只是用来说明文字溢出时用什么方式显示,要实现溢出时产生省略号的效果,还须定义 ...
- wxpython 简单表格控件
import wx, wx.grid class GridData(wx.grid.PyGridTableBase): _cols = "a b c".split() _data ...
- uwsgi特性
uwsgi 特性 官网参考 X-Sendfile仿真 即使前端 代理/webserver 不支持X-Sendfile (或者不能访问静态资源),可以使用 uwsgi 内部的 offloading 来模 ...
- Linux学习笔记之Linux第一课-基本介绍
Linux简介 Linux内核最初只是由芬兰人李纳斯·托瓦兹(Linus Torvalds)在赫尔辛基大学上学时出于个人爱好而编写的. Linux是一套免费使用和自由传播的类Unix操作系统,是一个基 ...
- MySQL几个join
1.因为关系型数据库的基本原理,是基于“关系代数”.最重要的一类关系代数,就是2个集合之间的运算. 从集合运算的视角,去理解SQL中的几个常用join (1)inner join (2)left jo ...
- [Err] 1214 - The used table type doesn't support FULLTEXT indexes
-- -- Table structure for table `film_text` -- -- InnoDB added FULLTEXT support in 5.6.10. If you us ...