![](https://lstatic.shangxueba.com/sxbzda/h5/images/m_q_title.png)
语句cout<<setiosflagags(ios::showpos)<<125<<"/t"<<-125<<endl;的输出结果为【】。
语句cout<<setiosflagags(ios::showpos)<<125<<"/t"<<-125<<endl;的输出结果为【 】。
![](https://lstatic.shangxueba.com/sxbzda/h5/images/tips_org.png)
语句cout<<setiosflagags(ios::showpos)<<125<<"/t"<<-125<<endl;的输出结果为【 】。
第2题
执行这个程序的输出结果是( );
include<iostream>
using namespace std;
class TestClass1
{
public:
void fun1(){cout<<"TestClass1\n";}
virtual void fun2(){cout<<"TestClass1\n";}
};
class TestClass2:public TestClass1
{
public:
void fun1(){cout<<"TestClass2\n";}
void fun2(){cout<<"TestClass2\n";}
};
void f(TestClass1&b){b.fun1();b.fun2();}
int main()
{
TestClass2 obj;
f(obj);
return 0;
}
第3题
师和考生情况进行了描述。由于教师和考生之间有相同的信息,如姓名、年龄等,所以可抽象出一个基类person,考生类student和教师类teacher作为person类的派生类。请按要求完成下列操作,将程序中的类定义补充完整。
(1)定义基类person的私有数据成员name和age,分别用于表示姓名和年龄,name为字符指针,age为血型的数据。请在注释“//**1**”之后添加适当的语句。
(2)完成基类person的重载构造函数person(char *mint a)的定义,把数据成员name,age分别初始化为参数n,a的值,请在注释“//**2**”之后添加适当的语句。
(3)根据主函数main中对s1的声明,定义派生类student的构造函数。在注释“//**3**”之后添加适当的语句。
(4)完成派生类teacher成员函数void setinf(ehar *n,int a,char *d,char *1)的定义,其功能为记录教师的姓名、年龄、院,系与职称信息。请在注释“//**4**”之后添加适当的语句。
输出结果如下:
刘雷(45)destructor
蒋军(23)destructor
注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。
源程序文件test4_3.cpp清单如下:
include<iostream.h>
class person
{
//**1**
public:
person(){}
person(char *n,int a)
{
//**2**
}
void setname(char *n){name=n;)
void setage(int a){age=a;}
~person(){cout<<name<<"("<<age<<")destructor"<<endl;)
};
class student:public person
{
char *department;
int code;
public:
//**3**
{
department=d;
code=c;
}
};
class teacher:public person
{
char *department;
char *level;
public:
teacher(){}
void setinf(char *n,int a,char *d,char *1)
{
//**4**
department=d;
level=1;
}
};
void main()
{
student s1("蒋军",23,"计算机学院",2);
teacher t1;
t1.setinf("刘雷",45,"计算机学院","教授");
}
第4题
问题,请改正程序中的错误,使程序的输出结果如下:
x=3 y=5 z=0
8
源程序文件test5_1.cpp清单如下:
include<iostream.h>
static int x=5;
int z=0;
int *add(int x,int y)
{
cout<<"X="<<X<<"y="<<y<<" Z="<<z<<endl;
z=z+x+y;
/********found*********/
return z;
/********found*********/
};
void main()
{
int y=5;
int x=3;
/*********found********/
cout<<&(add(X,y))<<endl;
}
第7题
函数模板的定义是______。
第9题
array的长度。
注意:部分源程序已存在文件test34_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数sum的花括号中填写若干语句。
程序输出结果如下:
sum of array 15
文件test34_2.cpp的内容如下:
include <iostream.h>
int sum(int array[],int len)
{
}
void main()
{
static int a[5]-{1,2,3,4,5};
int result=sum(a,5);
cout<<"sum of array "<<result<<end1;
}
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!