如下程序的输出结果是______。
include<iostream>
using namespace std;
class Wages{ //“工资”类
double base; //基本工资
double bonus; //奖金
double tax; //税金
public:
Wages(double CBase,double CBonus,doable CTax):
base(CBase),bonus(CBonus),tax(CTax){ }
double getPay()const; //返回应付工资额
Wages operator+(Wages w)cons[; //重载加法
};
double Wages::getPay()cons[{return base+bonus-tax;}
Wages Wages::operator+(Wages w)const{return Wages(base+w.base,bonus+w.bonus,tax+w.tax);}
int main(){
Wages wl(2000,500,100),w2(5000,1000,300);
eout<<(wl+w2).getPay()<<endl;
return 0;
}
第1题
请在下列程序中的空格处填写正确的语句:
class Sample{
public:
Sample( ){ }
~Sample( ){ }
void SetData(int datA) {//将Sample类成员变量data设置成形参的值
______
}
private:
int data;
};
第2题
如下程序的输出结果是______。
include<iostream>
using namespace std;
class pumpkin{
public:
pumpkin( ){++count;}
~pumpkin( ){--eount;}
static void total_count( ){cout<<count<<"pumpkin(s)"<<endl;}
private:
static int count;
};
int pumpkin::count=0;
int main( ){
pumpkin pl[10];
pumpkin::total_count( );
return 0;
}
第3题
阅读下面程序:
include <iostream.h>
void main()
{
int i,j,row=0,column=0,m;
static int a[3][3]={ 100,28,72,-30,2,-100};
m=a[0][0];
for (i=0;i<3;i++)
for (j=0;j<3;j++)
if (a[i][j]<m)
{
m=a[i][j];
row=i;
column=j;
}
cout<<m<<","<<row<<","<<column<<endl;
}
该程序的功能是【 】,其执行结果为上丝【 】。
第5题
对于长度为n的有序线性表,在最坏情况下,二分查找需要比较log2n,那么顺序查找需要比较的次数是【 】。
第6题
数resort的功能是:能在一个数列中,对从指定位置开始的几位数,按相反顺序重新排列,并在主函数中输出新的序列。
请改正程序中的错误,使它能得到正确结果。
注意,不要改动main函数,不得删行或增行,也不得更改程序的结构。
源程序文件RevMain8.cpp中的程序清单如下:
//RevMain8.cpp
include <instream>
using namespace std;
void resort(int arr[],int where,int amount);
int main ()
{
int number [20] ,where, arrount, i;
cout<<"Input 20 numbers\n";
for (i=0; i<20; i++)
cin>>number [i];
cout<<"How many do you want to sort: ";
cin>>arrount;
cout<<"\n where do you want to start: ";
cin>>where;
cout<<"old array as follow:\n";
for (i=0; i<20; i++)
cout<<nmuber [i] <<" ";
resort (number,where, arrount);
cout<<"\n resorted array as follow:\n";
for (i=0; i<20; i++)
cout<<number [i] <<" ";
cout<<end1;
return 0;
}
void resort(int array[],int where, int amount)
{
int *pi, *p2, temp;
p1=&array [where-1];
p2=&array [where-2+amount];
/* * * * *FOUND * * * * */
for (;p1<&array [where-1+amount/2]; )
{
/* * * * *FOUND * * * * */
*p1=*p2;
*p2=*p1;
}
return;
}
第8题
请编写函数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;
}
第9题
符串和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;
}
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!