设计一个最简单的C++加减乘除的程序
2个回答
展开全部
#include<iostream>
using namespace std;
class CPU{
public:
CPU(){
cout<<"一个CPU 对象被创建"<<endl;
}
CPU(char atype){
type=atype;
cout<<"CUP 类被调用"<<endl;
}
char get_type(){
return type;
}
private:
char type;
};
class RAM{
public:
RAM(){
cout<<"一个RAM对象被创建"<<endl;
}
RAM(char atype){
type=atype;
cout<<"内存对象被调用!!"<<endl;
}
char get_type(){
return type;
}
private:
char type;
};
class CDROM{
public:
CDROM(){
cout<<"光驱对象被调用!!"<<endl;
}
};
class Computer{
public:
Computer(){
cout<<"一个computer对象被建立"<<endl;
}
void run(){
cout<<"the computer is running !!"<<endl;
}
void stop(){
cout<<"the computer is sleeping!!"<<endl;
}
char get_cpu(){
return acpu.get_type();
}
char get_ram(){
return aram.get_type();
}
private:
CPU acpu;
RAM aram;
CDROM acdrom;
};
int main(){
Computer acomputer=Computer();
// acomputer.get_cpu();
// acomputer.get_ram();
return 0;
}
using namespace std;
class CPU{
public:
CPU(){
cout<<"一个CPU 对象被创建"<<endl;
}
CPU(char atype){
type=atype;
cout<<"CUP 类被调用"<<endl;
}
char get_type(){
return type;
}
private:
char type;
};
class RAM{
public:
RAM(){
cout<<"一个RAM对象被创建"<<endl;
}
RAM(char atype){
type=atype;
cout<<"内存对象被调用!!"<<endl;
}
char get_type(){
return type;
}
private:
char type;
};
class CDROM{
public:
CDROM(){
cout<<"光驱对象被调用!!"<<endl;
}
};
class Computer{
public:
Computer(){
cout<<"一个computer对象被建立"<<endl;
}
void run(){
cout<<"the computer is running !!"<<endl;
}
void stop(){
cout<<"the computer is sleeping!!"<<endl;
}
char get_cpu(){
return acpu.get_type();
}
char get_ram(){
return aram.get_type();
}
private:
CPU acpu;
RAM aram;
CDROM acdrom;
};
int main(){
Computer acomputer=Computer();
// acomputer.get_cpu();
// acomputer.get_ram();
return 0;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <iostream>
using namespace std;
int main()
{
double a, b;
char c;
cin >> a >> c >> b;
switch (c)
{
case '+':
{
cout << a << '+' << b << '=' << a + b << endl;
break;
}
case '-':
{
cout << a << '-' << b << '=' << a - b << endl;
break;
}
case '*':
{
cout << a << '*' << b << '=' << a * b << endl;
break;
}
case '/':
{
if (b == 0)
{
cout << "除数为0,错误\n";
return 0;
}
else
{
cout << a << '/' << b << '=' << a / b << endl;
break;
}
}
default:
cout << "符号错误\n";
}
return 0;
}
using namespace std;
int main()
{
double a, b;
char c;
cin >> a >> c >> b;
switch (c)
{
case '+':
{
cout << a << '+' << b << '=' << a + b << endl;
break;
}
case '-':
{
cout << a << '-' << b << '=' << a - b << endl;
break;
}
case '*':
{
cout << a << '*' << b << '=' << a * b << endl;
break;
}
case '/':
{
if (b == 0)
{
cout << "除数为0,错误\n";
return 0;
}
else
{
cout << a << '/' << b << '=' << a / b << endl;
break;
}
}
default:
cout << "符号错误\n";
}
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询