c++ 定义一个computer类,有数据成员芯片(cpu),内存(ram),光驱(cdrom)等
展开全部
#include<iostream>
#include<string>
using namespace std;
class Computer
{
private:
string cpu;
int ram;
int cdrom;
public:
Computer(string CPU,int Ram,int Cdrom)
{
cpu=CPU;
ram=Ram;
cdrom=Cdrom;
}
string Getcpu() {return cpu;}
int Getram() {return ram;}
int Getcdrom() {return cdrom;}
};
int main()
{
string a;
int b;
int c;
cout<<"CPU:";
cin>>a;
cout<<"Ram:";
cin>>b;
cout<<"CDrom";
cin>>c;
Computer mypc(a,b,c);
cout<<"CPU:"<<mypc.Getcpu()<<"\n"<<"Ram:"<<mypc.Getram()<<"\n"<<"CDrom"<<mypc.Getcdrom()<<endl;
}
构造了一个Computer类,并且可以实现输入你自己电脑的CPU,RAM,CDRAM并把它们显示出来的功能。
#include<string>
using namespace std;
class Computer
{
private:
string cpu;
int ram;
int cdrom;
public:
Computer(string CPU,int Ram,int Cdrom)
{
cpu=CPU;
ram=Ram;
cdrom=Cdrom;
}
string Getcpu() {return cpu;}
int Getram() {return ram;}
int Getcdrom() {return cdrom;}
};
int main()
{
string a;
int b;
int c;
cout<<"CPU:";
cin>>a;
cout<<"Ram:";
cin>>b;
cout<<"CDrom";
cin>>c;
Computer mypc(a,b,c);
cout<<"CPU:"<<mypc.Getcpu()<<"\n"<<"Ram:"<<mypc.Getram()<<"\n"<<"CDrom"<<mypc.Getcdrom()<<endl;
}
构造了一个Computer类,并且可以实现输入你自己电脑的CPU,RAM,CDRAM并把它们显示出来的功能。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
class computer
{ int cpu;
int ram;
int cdrom;
};
{ int cpu;
int ram;
int cdrom;
};
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Class Computer
{
public:
Compuer(std::string cpu, std::string ram, std::string cdrom)
:
m_cpu(cpu),
m_ram(ram),
m_cdrom(cdrom)
{
}
private:
std::string m_cpu;
std::string m_ram;
std::string m_cdrom;
};
{
public:
Compuer(std::string cpu, std::string ram, std::string cdrom)
:
m_cpu(cpu),
m_ram(ram),
m_cdrom(cdrom)
{
}
private:
std::string m_cpu;
std::string m_ram;
std::string m_cdrom;
};
参考资料: s
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
数据成员啥类型?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询