请编写函数fun(),其功能是计算并输出当x<0.97时下列多项式的值,直到|Sn-Sn-1|<0.000001为止。
Sn=1+0.5x+0.5(0.5-1)x2/2!+0.5(0.5-1)(0.5-2)x3/3!+…0.5(0.5-1)(0.5-2)…(0.5-n+1)xn/n!
例如:主函数从键盘给x输入0.21后,则输出为s=1.100000。
注意:部分源程序以存在文件test38_2.cpp中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
文件test38_2.cpp的内容如下:
include<stdio.h>
include<iostream.h>
include<math.h>
double fun(double x)
{
}
void main()
{
double x, s;
cout<<"Input x:"<<endl;
cin>>x;
s=fun(x);
cout<<"s="<<s<<endl;
}
第1题
请编写一个函数int compare(char *s,char *t)), 该函数的功能是对两个字符串进行比较。当s所指字符串和t所指字符串相等时,返回值为0;当s所指字符串大于是t指字符串时,返回值大于0;当s所指字符串小于t所指字符串时,返回值小于0。
注意:部分源程序已存在文件PROC8.cpp中。
文件PROC8.cpp的内容如下:
//PROC8.cpp
include <iostream>
include <string>
using namespace std;
int compare(char *s,char *t)
{
//* * * * * * * * *
}
int main ()
{
char str1[100],str2[100];
int result;
cout<<"Input the first string\n";
cin>>str1;
cout<<"Input the second string\n";
cin>>str2;
result=compare(str1,str2);
if (result==0)
cout<<"string1=string2 ! \n";
else if (result>0)
cout<<"string1>string2 ! \n";
else
cout<<"string1<string2 ! \n";
return 0;
}
请帮忙给出正确答案和分析,谢谢!
第4题
指出下面程序段中的错误的是 ______。
class X{//A
int a,b;
public:
X(int aa,int bb) {a=aa; b=bb;}//B
}:
X x(2,3);//C
X y(4); //D
请帮忙给出正确答案和分析,谢谢!
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!