一道C++编程题, 谢谢啦!
2个回答
2014-03-13
展开全部
请编写函数fun.其功能是:计算并输出3到m之间所有素数的平方根之和。 例如,若主函数从键盘给m输入50后,则输出为s=63.665791。 请勿改动主函数main与其他函数中任何内容,仅在函数的花括号中填入所编写的若干语句。注意:m的值要大于2但不大于100。部分源程序给出如下。 试题程序: #include "math.h"
2014-03-13
展开全部
#include "stdafx.h"
#include "iostream"
#include "cmath"
#include "windows.h"
using namespace std;#define pi 3.14
#define NULL 0double sin(double x);
double cos(double x);class complex_number
{
double radius; //R
double corner; //角
double image; //虚部
public:
complex_number(double r=0.0, double c=0.0);
complex_number(const complex_number& c);
~complex_number(); friend complex_number operator +(const complex_number& c1, const complex_number& c2);
friend complex_number operator *(const complex_number& c1, const complex_number& c2);
friend complex_number operator !(const complex_number& c);
operator double()
{
image=radius* sin(corner*pi/180); if(image==NULL)
{
cout<<"error..."<<endl;
return NULL;
}
return radius; }
};complex_number::complex_number(double r,double c)
{
radius=r;
corner=c;
}complex_number::~complex_number(){}complex_number operator +(const complex_number& c1,const complex_number& c2)
{
double H_corner1,H_corner2; //弧度 complex_number result; H_corner1=c1.corner*pi/180;
H_corner2=c2.corner*pi/180; result.radius=c1.radius* cos(H_corner1)+c2.radius* cos(H_corner2);
result.image=c2.radius* sin(H_corner1)+c2.radius* sin(H_corner2);
cout<<result.radius<<"+"<<result.image<<"*i"<<endl; return NULL;
}complex_number operator *(const complex_number& c1,const complex_number& c2)
{
double H_corner1,H_corner2;
double radius1,radius2;
double image1,image2;
complex_number result; H_corner1=c1.corner*pi/180;
H_corner2=c2.corner*pi/180; radius1=c1.radius* cos(H_corner1);
radius2=c2.radius* cos(H_corner2);
image1=c1.radius* sin(H_corner1);
image2=c2.radius* sin(H_corner2); result.radius=(radius1 * radius2)-(image1 * image2);
result.image=(radius1 * image2)+(radius2 * image1); if(result.image==NULL)
{
cout<<result.radius<<endl;
return NULL;
} cout<<result.radius<<"+"<<result.image<<"*i"<<endl; return NULL;
}complex_number operator !(const complex_number& c)
{
complex_number result; result.radius=c.radius* cos(c.corner*pi/180);
result.image=-c.radius* sin(c.corner*pi/180); if(result.image==NULL)
{
cout<<"error..."<<endl;
return NULL;
} if(result.image >= NULL)
cout<<result.radius<<"+"<<result.image<<"*i"<<endl;
else
cout<<result.radius<<result.image<<"*i"<<endl; return NULL;
}
int main(int argc, char* argv[])
{
//带入的两个量分别是 半径(radius)和角(corner)
//输出复数形式为: a+bi
double r1,corner1;
double r2,corner2;
cout<<"学号:2940611524 姓名:王鹏宇"<<endl;
cout<<"初始化..."<<endl; Sleep(800); cout<<"请输入第一个复数的 半径R: 和角Corner: "<<endl;
cin>>r1;cin>>corner1;
cout<<"请输入第二个复数的 半径R: 和角Corner: "<<endl;
cin>>r2;cin>>corner2; complex_number No1(r1,corner1),No2(r2,corner2),No_result; cout<<"复数1 + 复数2..."<<endl;
No_result=operator +(No1, No2);
cout<<"复数1 * 复数2..."<<endl;
No_result=operator *(No1, No2);
cout<<"复数1的共轭..."<<endl;
No_result=operator !(No1);
cout<<"复数2的模..."<<endl;
double result=double(No2); if(result!=NULL)
cout<<result<<endl; return NULL;
}
本人原创~!黑色武装网络安全组 BY 狼行绝路
#include "iostream"
#include "cmath"
#include "windows.h"
using namespace std;#define pi 3.14
#define NULL 0double sin(double x);
double cos(double x);class complex_number
{
double radius; //R
double corner; //角
double image; //虚部
public:
complex_number(double r=0.0, double c=0.0);
complex_number(const complex_number& c);
~complex_number(); friend complex_number operator +(const complex_number& c1, const complex_number& c2);
friend complex_number operator *(const complex_number& c1, const complex_number& c2);
friend complex_number operator !(const complex_number& c);
operator double()
{
image=radius* sin(corner*pi/180); if(image==NULL)
{
cout<<"error..."<<endl;
return NULL;
}
return radius; }
};complex_number::complex_number(double r,double c)
{
radius=r;
corner=c;
}complex_number::~complex_number(){}complex_number operator +(const complex_number& c1,const complex_number& c2)
{
double H_corner1,H_corner2; //弧度 complex_number result; H_corner1=c1.corner*pi/180;
H_corner2=c2.corner*pi/180; result.radius=c1.radius* cos(H_corner1)+c2.radius* cos(H_corner2);
result.image=c2.radius* sin(H_corner1)+c2.radius* sin(H_corner2);
cout<<result.radius<<"+"<<result.image<<"*i"<<endl; return NULL;
}complex_number operator *(const complex_number& c1,const complex_number& c2)
{
double H_corner1,H_corner2;
double radius1,radius2;
double image1,image2;
complex_number result; H_corner1=c1.corner*pi/180;
H_corner2=c2.corner*pi/180; radius1=c1.radius* cos(H_corner1);
radius2=c2.radius* cos(H_corner2);
image1=c1.radius* sin(H_corner1);
image2=c2.radius* sin(H_corner2); result.radius=(radius1 * radius2)-(image1 * image2);
result.image=(radius1 * image2)+(radius2 * image1); if(result.image==NULL)
{
cout<<result.radius<<endl;
return NULL;
} cout<<result.radius<<"+"<<result.image<<"*i"<<endl; return NULL;
}complex_number operator !(const complex_number& c)
{
complex_number result; result.radius=c.radius* cos(c.corner*pi/180);
result.image=-c.radius* sin(c.corner*pi/180); if(result.image==NULL)
{
cout<<"error..."<<endl;
return NULL;
} if(result.image >= NULL)
cout<<result.radius<<"+"<<result.image<<"*i"<<endl;
else
cout<<result.radius<<result.image<<"*i"<<endl; return NULL;
}
int main(int argc, char* argv[])
{
//带入的两个量分别是 半径(radius)和角(corner)
//输出复数形式为: a+bi
double r1,corner1;
double r2,corner2;
cout<<"学号:2940611524 姓名:王鹏宇"<<endl;
cout<<"初始化..."<<endl; Sleep(800); cout<<"请输入第一个复数的 半径R: 和角Corner: "<<endl;
cin>>r1;cin>>corner1;
cout<<"请输入第二个复数的 半径R: 和角Corner: "<<endl;
cin>>r2;cin>>corner2; complex_number No1(r1,corner1),No2(r2,corner2),No_result; cout<<"复数1 + 复数2..."<<endl;
No_result=operator +(No1, No2);
cout<<"复数1 * 复数2..."<<endl;
No_result=operator *(No1, No2);
cout<<"复数1的共轭..."<<endl;
No_result=operator !(No1);
cout<<"复数2的模..."<<endl;
double result=double(No2); if(result!=NULL)
cout<<result<<endl; return NULL;
}
本人原创~!黑色武装网络安全组 BY 狼行绝路
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询