试卷详情
-
C++语言笔试-12
-
[简答题]请使用VC6或使用[答题]菜单打开考生文件夹proj2下的工程proj2。此工程中包含一个源程序文件main.cpp,其中有“房间”类Room及其派生出的“办公室”类Office的定义,还有主函数main的定义。请在程序中“//****found****”下的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:
办公室房间号:308
办公室长度:5.6
办公室宽度:4.8
办公室面积:26.88
办公室所属部门:会计科
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。
#include<iostream>
using namespace std;
class Room //“房间”类
int room no; //房间号
double length; //房间长度(m)
double width; //房间宽度(m)
public:
Room(int the room_no.double the_length,double the_width):room_no(the_room_no),length(the_length),width(the width)
int theRoomNo( )constreturn room_no;
//返回房间号
double theLength( )const returnlength;) //返回房间长度
double theWidth( )const returnwidth; //返回房间宽度
//**********found**********
double theArea( )const______
//返回房间面积(矩形面积)
;
class Office:public Room //“办公室”类char*depart; //所属部门
public:
Office (int the_room_no.double the_length,double the_width,constchar*t
-
[简答题]请使用VC6或使用[答题]菜单打开考生文件夹proj3下的工程文件proj3。本题创建一个小型字符串类,字符串长度不超过100。程序文件包括proj3.h、proj3.cpp、writeToFile.obj。补充完成重载赋值运算符函数,完成深复制功能。
屏幕上输出的正确结果应该是:
Hello!
Happy new year!
要求:
补充编制的内容写在“//**********333**********”与“//**********666**********”两行之间。不得修改程序的其他部分。
注意:
程序最后调用writeToFile函数,使用另一组不同的测试数据,将不同的运行结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件。
//proj3.h
#include<iostream>
#include<iomanip>
using namespace std;
class MiniString
public:
friend ostream &operator<< ostream &output,const MiniString &s)
//重载流插入运算符
output <<s.sPtr; return output;
friend istream &operator>>(istream &input,MiniString &s)
//重载流提取运算符
char temp[100];//用于输入的临时数组
temp[0]=’/0’; //初始为空字符串
input>>setw(100)>>temp;
int inLen=strlen(temp);
//输入字符长度
if(inLen!=0)
s.length=inLen; //赋长度
if(s.sPtr!=0)delete[]s.sPtr;//避免内存泄漏
s.sPtr=new char[s.length+1];
strcpy(s.sPtr,temp);
//如
-
[简答题]请使用VC6或使用[答题]菜单打开考生文件夹proj1下的工程proj1,此工程中包含一个源程序文件main.cpp,其中有类Book(“书”)和主函数main的定义。程序中位于每个“//ERROR****found****”下的语句行有错误,请加以改正。改正后程序的输出结果应该是:
书名:C++语句程序设计总页数:299
已把“C++语言程序设计”翻到第50页
已把“C++语言程序设计”翻到第51页
已把“C++语言程序设计”翻到第52页
已把“C++语言程序设计”翻到第51页
已把书合上。
当前页:0
注意:只修改每个“//ERROR ****found****”下的那一行,不要改动程序中的其他内容。
#include<iostream>
using namespace std;
class Book
char*title;
int num_pages;//页数
int cur_page;//当前打开页面的页码,0表示书未打开
public:
//ERROR **********found**********
Book(const char*theTitle,int pages)num_pages(pages)
title=new char[strlen(theTitle)+1];
strcpy(title,theTitle);
cout<<endl<<"书名:"<<title<<"总页数:"<<num_pages;
~Book( )delete[]title;)
bool isClosed( )constreturn cur_page==0; //书合上时返回true,否则返回falsebool isOpen( )constreturn! isClosed( );)//书打开时返回true,否则返回falseint numOfPages( )const return num_pages;) //返回书的页数
int currentPage( )const return cur_page;) //返回打开页面的页