Problem C: 给我一台计算机吧!

网友投稿 647 2022-11-29

Problem C: 给我一台计算机吧!

Problem C: 给我一台计算机吧!

Problem C: 给我一台计算机吧!

Description

CPU主频和主存容量是衡量一台计算机性能主要指标。请定义:

1. CPU类:只有一个int类型的数据成员以表示其主频,并请根据输出和给定的main()函数编写必要的成员函数(包括构造函数)。

2. Memory类:只有一个int类型的数据成员以表示其容量,并请根据输出和给定的main()函数编写必要的成员函数(包括构造函数)。

3. Computer类:

(1)三个数据成员分别为CPU的对象、Memory的对象和一个字符串(表示该计算机属于谁的)。

(2)根据输出和给定的main()函数编写必要的成员函数(包括构造函数)。

(3)void show()方法,用于按照样例输出格式输出该计算机的信息。

Input

输入有2行。每行包括2个整数和1个字符串,分别表示CPU的主频、内存容量和计算机主人姓名。

Output

见样例。

#include #include using namespace std;class CPU {private: int x;public: CPU(int x) : x(x) {} CPU(const CPU &c) { x = c.x; } int getx() { return x; }};class Memory {private: int x;public: Memory(int x) : x(x) {} Memory(const Memory &m) { x = m.x; } int getx() { return x; }};class Computer {private: CPU c; Memory m; string s;public: Computer(CPU x, Memory y, string s) : c(x), m(y), s(s) {} Computer(int x, int y, string s) : c(x), m(y), s(s) {} void show() { cout << "This is " << s << "' computer with CPU = " << c.getx() << "GHz, memory = " << m.getx() << "MB." << endl; }};int main(){ int c, m; string n; cin>>c>>m>>n; CPU cpu(c); Memory mem(m); Computer com1(cpu, mem, n); cin>>c>>m>>n; Computer com2(c, m, n); com1.show(); com2.show(); return 0;}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:SpringBoot中Starter的作用小结
下一篇:UVa 11729 Commando War——贪心
相关文章

 发表评论

暂时没有评论,来抢沙发吧~