二楼放代码
#include <iostream>
#include <cmath>
#include <stdlib.h>
using namespace std;
/************************************************************/
class Trigonometric
{//三角函数实现
private:
double number;//要操作的数
char ch2;//选择控制
public:
void print1();//界面输出
void set1(double num)//传值给操作函数
{ number=num;}
};
void Trigonometric::print1()
{
cout<<"\t\t请输入一个弧度数:"<<endl;
cin>>number;
set1(number);
cout<<"\t\t 1.求sin(a)"<<endl;
cout<<"\t\t 2.求cos(a)"<<endl;
cout<<"\t\t 3.求tan(a)"<<endl;
cout<<"\t\t 4.求全部!"<<endl;
cin>>ch2;
back3:
if(ch2=='1')
cout<<"sin("<<number<<")="<<sin(number)<<endl;
else if(ch2=='2')
cout<<"cos("<<number<<")="<<cos(number)<<endl;
else if(ch2=='3')
cout<<"tan("<<number<<")="<<tan(number)<<endl;
else if(ch2=='4')
{
cout<<"sin("<<number<<")="<<sin(number)<<endl;
cout<<"cos("<<number<<")="<<cos(number)<<endl;
cout<<"tan("<<number<<")="<<tan(number)<<endl;
}
else
{
cout<<"\t\t输入有误!请重新选择:"<<endl;
cin>>ch2;
goto back3;
}
}
/************************************************************/
class Other
{//开方、平方实现
private:
double num;
char ch2;
public:
void set2(double num)
{num=num;}
void print2();
double sqrt(double num);
double pow(double num);
};
void Other::print2()
{
cout<<"请输入一个数:"<<endl;
cin>>num;
set2(num);
cout<<"\t\t*******************"<<endl;
cout<<"\t\t* 1.开方运算 *"<<endl;
cout<<"\t\t* 2.平方运算 *"<<endl;
cout<<"\t\t*******************"<<endl;
cout<<"\t\t请输入菜单项(1-2):";
cin>>ch2;
back4:
if(ch2=='1')
{
cout<<"\t\t"<<sqrt(num)<<endl;
}
else if(ch2=='2')
{
cout<<"\t\t"<<pow(num)<<endl;
}
else
{
cout<<"\t\t输入有误!请重新选择:"<<endl;
cin>>ch2;
goto back4;
}
}
class Calculate
{//一般计算
private:
double sum;//存储运算结果
char ch2;//选择控制
double num1,num2;//两个操作数
public:
void set3(double num1,double num2)//赋值
{ num2=num2;num1=num1;}
void print3();
double add(double num1,double num2);//加
double subtract(double num1,double num2);//减
double multiplication(double num1,double num2);//乘
double divide(double num1,double num2);//除
double mod(double num1,double num2);//取余
};
void Calculate::print3()
{
cout<<"\t\t请输入两个数:"<<endl;
cin>>num1>>num2;
set3( num1,num2);
cout<<"\t\t*******************"<<endl;
cout<<"\t\t* 1.加法运算 *"<<endl;
cout<<"\t\t* 2.减法运算 *"<<endl;
cout<<"\t\t* 3.乘法运算 *"<<endl;
cout<<"\t\t* 4.除法运算 *"<<endl;
cout<<"\t\t* 5.取余运算 *"<<endl;
cout<<"\t\t*******************"<<endl;
cout<<"\t\t请输入菜单项(1-6):";
cin>>ch2;
back2:
if(ch2=='1')
{// 1.加法运算
cout<<"\t\t"<<num1<<'+'<<num2<<'='<<add(num1,num2)<<endl;
}
else if(ch2=='2')
{// 2.减法运算
cout<<"\t\t"<<num1<<'-'<<num2<<'='<<subtract(num1,num2)<<endl;
}
else if(ch2=='3')
{// 3.乘法运算
cout<<"\t\t"<<num1<<'*'<<num2<<'='<<multiplication(num1,num2)<<endl;
}
else if(ch2=='4')
{// 4.除法运算
cout<<"\t\t"<<num1<<'/'<<num2<<'='<<divide(num1,num2)<<endl;
}
else if(ch2=='5')
{// 5.取余运算
cout<<'\t\t'<<num1<<'%'<<num2<<'='<<mod(num1,num2)<<endl;
}
else
{
cout<<"\t\t输入有误!请重新选择:"<<endl;
cin>>ch2;
goto back2;
}
}
double Calculate::add(double num1,double num2)
{
return sum=num1+num2;
}
double Calculate::subtract(double num1,double num2)
{
return sum=num1-num2;
}
double Calculate::multiplication(double num1,double num2)
{
return sum=num1*num2;
}
double Calculate::divide(double num1,double num2)
{
if(num2==0)
return sum=num1/num2;
else return 0;
}
double Calculate::mod(double num1,double num2)
{
if(num2==0)
return sum=(int)num1%(int)num2;
else return 0;
}
/************************************************************/
int main()
{
//int num1=0,num2=0,number=0;
Trigonometric tri;//三角函数对象
Calculate cal;//一般计算对象
Other oth;
char ch1,ch3;
back1:
{
do{
cout<<"\t\t*****主菜单**********"<<endl;
cout<<"\t\t* *"<<endl;
cout<<"\t\t* 1. 基本运算 *"<<endl;
cout<<"\t\t* 2. 开方、平方运算*"<<endl;
cout<<"\t\t* 3. 三角函数 *"<<endl;
cout<<"\t\t* *"<<endl;
cout<<"\t\t* 请选择:1---3 *"<<endl;
cout<<"\t\t*********************"<<endl;
cin>>ch1;
if(ch1=='1')
{// 1.基本运算
cal.print3();
}
else if(ch1=='2')
{// 2.开方、平方运算
oth.print2();
}
else if(ch1=='3')
{
tri.print1();
}
else
{
cout<<"输入有误!"<<endl;
goto back1;
}
cout<<"again?(y/n)"<<endl;
cin>>ch3;
}while(ch3=='y'||ch3=='Y');
};
return 0;
}