2.定义一个计算机类MyComputer。

2.定义一个计算机类MyComputer,它包含CPU类型(String类型)、RAM内存大小
(Integer类型)、HD硬盘大小(Integer类型),设计它的构造函数,并设计一个显示函数,建立
一个MyComputer对象并调用该显示函数显示。

直接问作业不好哦,和我上学的时候有一道作业题不能说是像,简直是一模一样,我给你写一个C++的代码
你参考着python里面的类的定义,构造方法什么的这些写一下。

class MyComputer{
  // 定义类属性成员
  public string cpu;
  public int ram_size;
  public int hd_size;
  // 构造方法
  public MyComputer(string cpu, int ram_size, int hd_size){
    this.cpu = cpu;
    this.ram_size = ram_size;
    this.hd_size = hd_size;
  }
  // 显示方法
  public void show(){
    // 输出cpu型号、内存硬盘大小
    std::cout << "cpu:" << this.cpu << std::endl;
    std::cout << "ram_size:" << this.ram_size << "GB" << std::endl;
    std::cout << "hd_size:" << this.hd_size << "GB" << std::endl;
  }
}
// 调用
MyComputer computer = new MyComputer("AMD", 8, 512);
computer.show();

显示结果:

cpu:AMD
ram_size:8GB
hd_size:512GB