Problem C: 给我一台计算机吧!
来源:互联网 发布:php好找工作么 编辑:程序博客网 时间:2024/05/18 01:36
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 <iostream>#include <string>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;}
阅读全文
2 0
- Problem C: 给我一台计算机吧!(C++期末)
- Problem C: 给我一台计算机吧!
- Problem C: 给我一台计算机吧!
- Problem C: 给我一台计算机吧!
- 今天我得到了一台计算机
- 下列哪个IP地址可以分配给一台计算机?
- 每个人都是一台计算机
- 7.实现一台计算机
- 设计一台模块化计算机
- 【C#】获取"我的电脑"的名字,如This PC、这台计算机
- android自动化中的接电话case的扩展-告诉一台手机打个电话给我
- 《计算机是怎样跑起来的》——试着制造一台计算机吧
- 组装一台稳定的计算机
- 获取一台计算机的信息!
- A002-《编码》-从零开始构建一台计算机
- 发送消息给多台计算机在工作组/网络
- 请给我简单介绍一下计算机二级C语言是什么
- 专题一 Problem C
- Android之Menu解析
- 闭包与回调
- Python的import
- windows下tensorflow的安装与学习(基于anaconda的python3.5)
- rabbitmq的java调用实例
- Problem C: 给我一台计算机吧!
- Hadoop工作原理图-WordCount示例
- git将代码上传到coding分支
- 网络编程
- java学习之接口
- Hibernate入门05_一对一映射
- Oracle 事务隔离级别
- 数据挖掘岗面试总结
- JaveScript之函数传参