C++测试题,明天就要交了,求各位

来源:百度知道 编辑:UC知道 时间:2024/09/20 02:35:05
给出下列程序运行后的输出结果(每小题 7 分,共 21 分)
1.# include <iomanip.h>
int LB(int *a,int n) {
int s=1;
for (int i=0; i<n; i++)
s*=*a++;
return s;
}
void main() {
int a[]={1,2,3,4,5,6,7,8};
int b=LB(a,5)+LB(&a[3],3);
cout <<"b="<<b<<endl;
}

2.# include <iostream.h>
# include <string.h>
struct Worker{
char name[15]; // 姓名
int age; // 年龄
float pay; // 工资
};
void main() {
Worker x;
char *t="liouting";
int d=38; float f=493;
strcpy(x.name,t);
x.age=d; x.pay=f;
cout <<x.name<<' '<<x.age<<' '<<x.pay<<endl;
}

3.# include <iostream.h>
class A {
int a;
public:
A(int aa=0) { a=aa; }
~A() { cout <<"Destructor A!&q

1.b=240
2.liouting 38 493
3.前两个和c的一样,c++的不会
四、写出下列每个函数的功能
2.输入n个数的平方和
3.c++的不知道
五、编写程序
#include <iostream.h>
#include <stdio.h>

int main()
{
FILE *fp;
int temp;

if((fp=fopen("axxk1.txt", "w+")) == NULL)
{
cout<<"connot open file"<<endl;
exit(1);
}
cin >>temp;
while(temp!=-1)
{

fprintf(fp, "%d\n", temp);
cin >>temp;
}

fclose(fp);
return 0;

}
希望对你有所提示,呵

哇靠 QB编程么? 学得这么深了··

你这是啥玩意,几年的课程。

去老师办公室拿个答案吧- -