单选题下列不属于C++预定义的流对象的是( )。
单选题已知类模板Test定义如下:templatetypenamT1,typenamT2clasTestpublic;voifooTt;;则以下针对foo函数的类外定义中语法正确的是( )。
单选题有如下程序:运行时的输出结果是( )。
单选题定义派生类时,若不使用关键字显式地规定采用何种继承方式,则默认方式为( )。
单选题软件需求规格说明书的作用不包括( )。
问答题请使用“答题”菜单或使用VC6打开考生文件夹proj3下的工程文件proj3,其中包含了类Integers和主函数main的定义。一个Integers对象就是一个整数的集合,其中包含0个或多个可重复的整数。成员函add将一个元素添加到集合中,成员函数remove从集合中删除指定的元素(如果集合中存在该元素),成员函filter去除集合中的所有负整数。请编写这个filter函数。此程序的正确输出结果
问答题请使用“答题”菜单或使用VC6打开考生文件夹proj1下的工程文件proj1,程序中位于每个“ERROR*********found*********”下的语句行有错误,请加以更正。更正后程序的输出应该是: Name:Smith Age:21 ID:99999 CourseNum:12 Record:970 注意:只能修改每个“ERROR*********found*********”下的那
问答题请使用“答题”菜单或使用VC6菜单打开考生文件夹proj2下的工程proj2。此工程包含一个程序文main.cpp,其中有日期类Date、人员类Person以及排序函数sortByAge和主函数main的定义。请在程序中的横线处填写适当的代码,然后删除横线,以实现该程序。此程序的正确输出结果应为: 排序前: 张出生日期:1978年4月20日 王出生日期:1965年8月3日 杨出生日期:19
问答题阅读下列函数说明和代码,补充空出的代码。函数TrimRight(char*des,char*str)实现功能是:(1)如果字符串最后面有空格或者不可打印字符,则全部去掉;(2)返回转换后的数据到des,并且指针作为返回值返回。注意:部分代码已经实现,只能补充TrimRight()函数。**********code.c********************-code.c**********
问答题学校教务处要为任课老师开发一个学生管理系统,需求如下: (1)学生的信息要受到严密保护和限制,包括姓名、五位英文字符的学号,以及精确到小数点后一位的一科成绩,只有任课老师可以修改,如果学生升学了,比如由本科升到研究生,原来的信息还有效,而只需要添加研究生的必要信息,不过现在不必马上实现,但应当有所考虑。 (2)学生的所有信息可以查看,但也只有学生自己才有这个权利。 (3)学生的信息可以从文件
问答题本题类的定义并不完整,按要求完成下列操作,将类的定义补充完整。 (1)完成类CMyArry的构造函数,申请数组的大小,请在注释*******1******后添加适当的语句。 (2)完成类CMyArry的构造函数,释放数组,请在注释*******2*****后加适当的语句。 (3)完成重载运算符“[]”用来获得指定下标的数据,请在注释*******3*******后添加适当的语句。 (4)完
问答题请使用“答题”菜单或使用VC6打开考生文件夹proj1下的工程文件proj1。此工程包含程序文main.cpp,其中有类Door和主函数main的定义。程序中位于每个“ERROR*********found*********”下的语句行有错误,请加以更正。更正后程序的输出应该是: 打开503号门...门是锁着的,打不开。打开503号门的锁...锁开了。 打开503号门...门打开了。 打开5
操作题 请使用VC6或使用[答题]菜单打开考生文件夹proj3下的工程proj3,其中声明的CDeepCopy是一个用于表示动态数组的类。请编写其中的复制构造函数。
要求:
补充编制的内容写在“//********333********”与“//********666********”之间,不得修改程序的其他部分。
注意:程序最后将结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件,并且在本程序中调用。
//CDeepCopy.h
#include <iostream>
#include <string>
using namespace std;
class CDeepCopy
{
public:
int n; //动态数组的元素个数
int * p; //动态数组首地址
CDeepCopy (int);
~CDeepCopy ();
CDeepCopy(const CDeepCopy r);
//复制构造函数
};
void writeToFile (char * );
//main. cpp
#include 'CDeepCopy. h'
CDeepCopy:: ~CDeepCopy () { delete [] p;}
CDeepCopy::CDeepCopy (int k) { n = k; p=new int[n];}
//构造函数实现
CDeepCopy:: CDeepCopy ( const CDeepCopy r)
//复制构造函数
{
//******** 333********
//******** 666********
}
int main ()
{
CDeepCopy a (2), d (3);
a.p[0] =1; d.p[0] =666;
//对象a,d数组元素的赋值
{
CDeepCopy b (a);
a.p[0] =88;
cout <<b.p[0];
//显示内层局部对象的数组元素
}
cout <<d.p[0];
//显示d数组元素a.p[0]的值
cout <<' d fade away; \n'; cout <<a. p[0];
//显示a数组元素a.p[0]的值
writeToFile ('');
return 0;
}
操作题 请使用VC6或使用[答题]菜单打开考生文件夹proj1下的工程prog1。其中位于每个“//ERROR ****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为:
v1=23;v2=42
注意:只修改每个“//ERROR ****found****”下的那一行,不要改动程序中的其他内容。
#include <iostream>
using namespace std;
class MyClass
{
int v1;
static int v2;
public:
MyClass(int v) : v1 (v) {}
int getValue() const { return v1; }
static int getValue(int dummy)
{
// ERROR ********** found**********
return v1;
}
};
// ERROR ********** found**********
int MyClass.v2 = 42;
int main()
{
MyClass obj (23);
// ERROR ********** found**********
int v1 = obj.v1;
int v2 = MyClass::getValue(0);
cout << 'v1 = ' << v1 << '; v2 = '<< v2 << endl;
return 0;
}
操作题 请使用VC6或使用[答题]菜单打开考生文件夹proj3下的工程proj3,其中包含主程序文件main.cpp和用户定义的头文件Array.h,整个程序包含有类Array的定义和主函数main的定义。请把主程序文件中的Array类的成员函数Contrary()的定义补充完整,经补充后运行程序,得到的输出结果应该是:
58
5, 4, 3, 2, 1
0, 0, 8.4, 5.6, 4.5, 3.4, 2.3, 1.2
注意:只允许在“//********333********”和“//********666********”之间填写内容,不允许修改其他任何地方的内容。
//Array.h
#include <iostream>
using namespace std;
template<class Type, int m>
class Array { //数组类
public:
Array(Type b[], int mm) { //构造函数
for(int i=0; i<m; i++)
if(i <mm) a[i] =b[i];
else a[i] =0;
}
void Contrary();
//交换数组a中前后位置对称的元素的值
int Length() const{ return m;}
//返回数组长度
Type operator [] (int i) const {
//下标运算符重载为成员函数
if(i<0 || i>=m)
{cout<<'下标越界!'<<endl; exit(1);}
return a[i];
}
private:
Type a[m];
};
void writeToFile(const char * );
//不用考虑此语句的作用
//main.cpp
#include'Array.h'
//交换数组a中前后位置对称的元素的值
template <class Type, int m>
void Array <Type, m >::Contrary () {
//补充函数体
//********333********
//********666********
}
int main(){
int s1[5] ={1, 2, 3, 4, 5};
double s2[6] = {1.2, 2.3, 3.4, 4.5, 5.6, 8.4};
Array<int, 5> d1(s1,5);
Array<double, 8> d2(s2,6);
int i;
d1.Contrary(); d2.Contrary();
cout <<d1.Length () <<' <<d2. Length ()<<endl;
for(i=0; i<4; i++)
cout <<d1[i] <<',';
cout <<d1[4] <<endl;
for(i=0; i<7; i++)
cout <<d2[i] <<',';
cout <<d2 [7] <<endl;
writeToFile ('');
//不用考虑此语句的作用
return 0;
}
操作题 请使用VC6或使用[答题]菜单打开考生文件夹proj3下的工程proj3,其中声明的DataList类,是一个用于表示数据表的类。sort成员函数的功能是将当前数据表中的元素升序排列。请编写这个sort函数。程序的正确输出应为:
排序前:7,1,3,11,6,9,12,10,8,4,5,2
排序后:1,2,3,4,5,6,7,8,9,10,11,12
要求:
补充编制的内容写在“//********333********”与“//********666********”两行之间。不得修改程序的其他部分。
注意:程序最后将结果输出到文件out. dat中。输出函数writeToFile已经编译为obj文件,并且在本程序调用。
//DataList.h
#include<iostream>
using namespace std;
class Datalist{//数据表类
int len;
double*d;
public:
DataList(int len,double data[]=NULL);
~DataList(){delete[]d;}
int length()const{ return len;}
//数据表长度(即数据元素的个数)
double getElement(int i)const{return d[i];}
void sort();//数据表排序
void show () const; //显示数据表
};
void writeToFile (char*, constDataList);
//main.cpp
#include 'DataList.h'
DataList::DataList(int len,double data[]):len(len){
d=new double[len];
for{int i=0;i<len;i++)
d[i]=(data==NULL?0.0:data[i]);
}
void DataList::sort(){//数据表排序
//********333********
//********666********
}
void Datalist::show()const{
//显示数据表
for(int i=0;i<len-1;i++)cout<<d[i]<<',';
cout<<d[len-1]<<endl;
}
int main () {
double s[]={7,1,3,11,6,9,12,10,8,4,5,2};
DataList list(12,s);
cout<<'排序前:';
list.show();
list.sort();
cout<<endl<<'排序后:';
list.show();
writeToFile(' ',list);
return 0;
}
操作题 请使用VC6或使用【答题】菜单打开proj1下的工程proj1,该工程中包含程序文件main.cpp,其中有关TVSet(“电视机”)和主函数main的定义。程序中位于每个“// ERROR ********found********”之后的一行语句有错误,请加以改正。改正后程序的输出结果应该是:
规格:29英寸,电源:开,频道:5,音量:18
规格:29英寸,电源:关,频道:-1,音量:-1
注意:只修改每个“// ERROR ****found****”下的那一行,不要改动程序中的其他内容。
#include <iostream>
using namespace std;
class TVSet{ //'电视机'类
const int size;
int channel; //频道
int volume; //音量
bool on; //电源开关:true表示开,false表示关
public:
// ERROR *******found*******
TVSet(int size) {
this -> size(size);
channel = 0;
volume = 15;
on = false;
}
int getSize() const {return size;} //返回电视机规格
bool isOn() const {return on;} //返回电源开关状态
//返回当前音量,关机情况下返回-1
int getVolume() const {return isOn()? volume:-1;}
/返回当前频道,关机情况下返回-1
int getChannel() const {return isOn()? channel: -1;}
// ERROR *******found*******
void turnOnOff() const //将电源在'开'和'关'之间转换
{on=! on;}
void setChannelTo (int chan){ //设置频道(关机情况下无效)
if (isOn() chan >= 0 chan <= 99)
channel = chan;
}
void setVolumeTo (int vol){ //设置音量(关机情况下无效)
if(isOn() vol >= 0 vol <= 30)
volume = vol;
}
void show_state() {
// ERROR *******found*******
cout << '规格:' << getSize() << '英寸'
<< ',电源:' << (isOn()? '开':'关')
<< ',频道:' << getChannel() << ',音量:' << getVolume()
<< endl;
}
};
int main() {
TVSet tv(29);
tv.turnOnOff();
tv.setChannelTo(5);
tv.setVolumeTo(18);
tv.show_state();
tv.turnOnOff();
tv.show_state();
return 0;
}
操作题
使用VC++2010打开考生文件夹下“proj1”文件夹中的工程proj1.sln,该程序运行时有错误,请改正错误,使得程序正常运行,并且要求最后一个catch()必须抛出执行的任何异常。
程序通过抛出异常输出:
error
0
ERROR
注意:不要改动main函数,不能增行或删行,也不能更改程序的结构,错误的语句在//******error******的下面。
#include<iostream.h>
int main()
{
try
{
throw('error');
}
//********error********
catch(char s)
{
cout<<s<<endl;
}
try
{
throw((int)0);
}
//********error********
catch()
{
cout<<i<<endl;
}
try
{
throw(0);
throw('error');
}
//********error********
catch()
{
cout<<'ERROR'<<endl;
}
return 0;
}
操作题 请使用VC6或使用【答题】菜单打开proj1下的工程proj1,其中有枚举DOGCOLOR、狗类Dog和主函数main的定义。程序中位于每个“// ERROR ****found****”下的语句行有错误,请加以改正。改正后程序的输出结果应该是:
There is a white dog named Hoho.
There is a black dog named Haha.
There is a motley dog named Hihi.
注意:只修改每个“// ERROR ****found****”下的那一行,不要改动程序中的其他内容。
#include <iostream>
using namespace std;
//狗的颜色:黑、白、黄、褐、花、其他
enum DOGCOLOR {BLACK, WHITE, YELLOW, BROWN, PIEBALD, OTHER};
class Dog{ //狗类
DOGCOLOR color;
char name[20];
static int count;
public:
Dog (char name[], DOGCOLOR color){
strcpy(this->name,name);
// ERROR *******found*******
strcpy (this -> color, color);
}
DOGCOLOR getColor() const {return color;}
// ERROR *******found*******
const char * getName() const {return * name;}
const char * getColorString() const {
switch(color) {
case BLACK: return 'black';
case WHITE: return 'white';
case YELLOW: return 'yellow';
case BROWN: return 'brown';
case PIEBALD: return 'piebald';
}
return 'motley';
}
void show() const {
cout << 'There is a' << getColorString() << 'dog named' << name << '.' << endl;
}
};
int main() {
// ERROR *******found*******
Dog dog1('Hoho', WHITE), dog2('Haha', BLACK); dog3('Hihi', OTHER);
dog1.show();
dog2.show();
dog3.show();
return 0;
}
操作题 请使用VC6或使用【答题】菜单打开proj1下的工程proj1。程序中位于每个“// ERROR ****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为:
value = 63
number = 1
注意:只修改每个“// ERROR ****found****”下的那一行,不要改动程序中的其他内容。
#include <iostream>
using namespace std;
class MyClass {
int * p;
const int N;
public:
// ERROR *******found*******
MyClass(int val):N = 1
{
p = new int;
*p = val;
}
// ERROR *******found*******
~MyClass() {delete *p;}
friend void print (MyClass obj);
};
// ERROR *******found*******
void MyClass::print (MyClass obj)
{
cout << 'value =' << * (obj.p) << endl;
cout << 'number =' << obj.N << endl;
}
int main()
{
MyClass obj(63);
print(obj);
return 0;
}