用C++语言定义一个类,实现加减乘除运算 100
//class2.cpp:定义控制台应用程序的入口点。//#include"stdafx.h"#include<IOSTREAM>usingnamespacestd;cl...
// class2.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <IOSTREAM>
using namespace std;
class nHour
{
public:
nHour();
public:
double add(double a, double b);
double div(double a, double b);
};
double add(double a, double b)
{
return a + b;
}
double subtract(double a, double b)
{
return a - b;
}
int main()
{
nHour my;
double sum = 0;
sum = my.add(10, 5);
cout << "10+5 = " << sum << endl;
sum = my.subtract(10, 5);//包含的有为什么会说没有 求解
cout << "10-5 = " << sum << endl;
} 展开
//
#include "stdafx.h"
#include <IOSTREAM>
using namespace std;
class nHour
{
public:
nHour();
public:
double add(double a, double b);
double div(double a, double b);
};
double add(double a, double b)
{
return a + b;
}
double subtract(double a, double b)
{
return a - b;
}
int main()
{
nHour my;
double sum = 0;
sum = my.add(10, 5);
cout << "10+5 = " << sum << endl;
sum = my.subtract(10, 5);//包含的有为什么会说没有 求解
cout << "10-5 = " << sum << endl;
} 展开
1个回答
展开全部
#include <iostream.h> class CMy_Math { public: CMy_Math(); ~CMy_Math(); public: double add(double a,double b); //加法 double div(double a,double b);//除法 double subtract(double a,double b);//减法 double mult(double a,double b); //乘法 }; CMy_Math::CMy_Math() { } CMy_Math::~CMy_Math() { } double CMy_Math::add(double a,double b) { return a+b; } double CMy_Math::subtract(double a,double b) { return a-b; } double CMy_Math::mult(double a,double b) { return a*b; } double CMy_Math::div(double a,double b) { if ( 0.0 != b) //b不能为0.0 return a/b; } int main(double argc, char* argv[]) { CMy_Math my; double sum=0; sum= my.add(10,5); cout<<"10+5 = "<<sum<<endl; sum= my.subtract(10,5); cout<<"10-5 = "<<sum<<endl; sum= my.subtract(10,5); cout<<"10*5 = "<<sum<<endl; sum= my.div(10,5); cout<<"10/5 = "<<sum<<endl; return 0; }
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |