题目详情
当前位置:首页 > 职业培训考试
题目详情:
发布时间:2024-05-26 20:02:09

[简答题]请使用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 ) : roomno (the_room_no) , length ( the_length) , width ( the_width )
int theRoomNo( ) const return roomno ;
//返回房间号
double theLength( )const return length; //返回房间长度
double theWidth( )const return width; //返回房间宽度
//********** found **********
double theArea ( ) const ______ //返回房间面积(矩形面积)
;
class Office: public Room //"办公室"类
char * depart; //所属部门
public :
Office(int the_r

更多"请使用VC6或使用[答题] 菜单打开考生文件夹proj2下的工程pro"的相关试题:

[简答题]请使用VC6或使用[答题]菜单打开考生文件夹projl下的工程proj1,其中有枚举DOGCOLOR、狗类Dog和主函数man的定义。程序中位于每个“//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);
strcpy(this->color,color);

DOGCOLOR getColor ( ) constreturncolor;
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<<"
[简答题]请使用VC6或使用[答题] 菜单打开考生文件夹proj3下的工程文件proj3。本题创建一个小型字符串类,字符串长度不超过100。程序文件包括proj3. h、proj3. cpp、writeToFile. obj。补充完成重载赋值运算符函数,完成深复制功能。
屏幕上输出的正确结果应该是:
Hello!
Happy new year!
要求:
补充编制的内容写在“//**********333**********”与“//**********666**********”两行之间。不得修改程序的其他部分。
注意:
程序最后调用writeToFile函数,使用另一组不同的测试数据,将不同的运行结果输出到文件out. dat中。输出函数writeToFile已经编译为obj文件。
//proj3. h
#inelude < iostream >
#include < iomanip >
using namespaee std;
class MiniString

public :
friend ostream &operator << ( ostream &output, const MiniString &s ) //重载流插入运算符
output << s. sPtr; return output;
friend istream &operator >> ( istrearn &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 ch
[简答题]请使用VC6或使用[答题]菜单打开考生文件夹projl下的工程proj1,此工程包含一个源程序文件proj1.cpp。其中位于每个注释“//ERROR****found****”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为:You are nght.
注意:只修改注释“//ERROR ****found****”的下一行语句,不要改动程序中的其他内容。
//proj1.cpp
#include <iostream>
using namespace std;
class MyClass

public:
MyClass(int x):number (x)
//ERROR **********found**********
~MyClass(int x)
//ERROR **********found**********
void Judge(MyClass &obj);
private:
int number;
void Judge(MyClass &obj)

if(obj.number==10)
cout<<"You are right."<<endl;else
cout<<"Sorry"<<endl;

int main( )

//ERROR **********found**********
MyClass object;
Judge(object);
return 0;

[简答题]请使用VC6或使用[答题]菜单打开考生文件夹proj3下的工程prog3,其中声明了VaIArray类,该类在内部维护一个动态分配的整型数组。ValArray类的复制构造函数应实现对象的深层复制。请编写ValArray类的复制构造函数。在main函数中给出了一组测试数据,此种情况下程序的输出应该是:
VaIArray v1=1,2,3,4,5
VaIArray v2=2,2,2,2,2
要求:
补充编制的内容写在“//*******333*******”与“//********666********”之间。不要修改程序的其他部分。
注意:
相关文件包括:main.cpp、ValArray.h。
程序最后调用writeToFile函数,使用另一组不同的测试数据,将不同的运行结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件。
//ValArray.h
#include<iostream>
using namespace std;
class ValArray
int*v;
int size;
public:
ValArray(const int*p,int n)size(n)

v=new int[size];
for (int i=0;i<size;i++)
v[i]=p[i];

ValArray(const ValArray& other);
~ValArray( )delete [] v;
void setElement(int i,int val)

v[i] =val;

void print (ostream& out) const

for (int i=0;i<size-1;i++)
out<<b[i]<<",";
out<<v[size-1]<<’’;

;
void writeToFile (const char*);
//main.cpp
#include
[简答题]请使用VC6或使用[答题]菜单打开考生文件夹proj3下的工程proj3,其中声明了SortedList类,是一个用于表示有序数据表的类。其成员函数insert的功能是将一个数据插入到一个有序表中,使得该数据表仍然保持有序。请编写这个insert函数。程序的正确输出应为:
插入前:
1,2,4,5,7,8,10
插入6和3后:
1,2,3,4,5,6,7,8,10
要求:
补充编制的内容写在“//********333********”与“//********666********”之间。不得修改程序的其他部分。
注意:程序最后将结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件,并且在本程序中调用。
//SortedList.h
#include<iostream>
using namespace std;
class SortedList //有序数据表类
int len;
double*d;
public:
SortedList(int len,double data[]=NULL);
~SortedList( )delete[]d;
int length( )constreturn len;//有序数据表长度(即元素的个数)
double getElement(int i)constreturn d[i];
void insert(double data);
void show( )const;//显示有序数据表
;
void writeToFile(char*,const Sort-edlist &);
//main.cpp
#include"SortedList.h"
SortedList::SortedList (int len,double data[]):len(len)
d=new double[len];
for(int k=0;k<len;k++)
d[k]=(data==NULL0.0:data[k]);
for(int i
[简答题]请使用VC6或使用[答题]菜单打开考生文件夹proj2下的工程proj2,其中定义了Component类、Composite类和Leaf类。Component是抽象基类,Composite和Leaf是Component的公有派生类。请在横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:
Leaf Node
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“// ****found****”。
#include<iostream>
using namespace std;
class Component
public:
//声明纯虚函数print( )
//**********found**********
;
class Composite:public Component
public:
//**********found**********
void setChild(______)

m_child=child;

virtual void print( )const

m_child->print( );

private:
Component*m_child;
;
class Leaf:public Component
public:
virtual void print( )const

//**********found**********
______

;
int main( )

Leaf node;
Composite comp;
comp.setChild(&node);
Component*p=∁
p->print( );
return 0;

[简答题]请使用VC6或使用[答题]菜单打开考生文件夹proj3下的工程proj3,其中声明的DataList类,是一个用于表示数据表的类。DataList的重载运算符函数operator+,其功能是求当前数据表与另一个相同长度的数据表之和;即它返回一个数据表,其每个元素等于相应两个数据表对应元素之和。请编写这个operator+函数。程序的正确输出应该是:
两个数据表:
1,2,3,4,5,6
3,4,5,6,7,8
两个数据表之和:
4,6,8,10,12,14
要求:
补充编制的内容写在“//********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[]=
DataList(Datalist &data);
int length ( ) constreturn len;
double getElement(int i)const return d[i];
Datalist operator+(const DataList&list)const; //两个数据表求和
void show ( ) const; //显示数据表void writeToFile(char*,constDataList&);
//main.cpp
#include"Datalist.h"
DataList::DataList(int len,doubledata[]):len(len)
d=new double[len];
for(int i=0;i<len;i++)
d[i]=(data==N
[简答题]请使用VC6或使用[答题]菜单打开考生文件夹projl下的工程proj1,该工程含有一个源程序文件proj1. cpp。其中位于每个注释“//ERROR **** found ****”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为:
The value is 10
注意:只修改注释“//ERROR ***** found ****”的下一行语句,不要改动程序中的其他内容。
// proj1, cpp
#include < iostream >
using namespace std;
class MyClass
int value ;
public :
// ERROR ******** found ********
void MyClass(int val) : value(val)
int GetValue( ) const return value;
void SetValue(int val) ;
;
//ERROR ******** found ********
inline void SetValue(int val) value = val;
int main( )
MyClass obj (0) ;
obj. SetValne(10) ;
//ERROR ******** found ******** 下列语句功能是输出obj的成员value的值
cout << "The value is " << obj. value << endl;
return 0 ;

[简答题]请使用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或使用[答题]菜单打开考生文件夹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或使用[答题]菜单打开考生文件夹proj2下的工程proj2,此工程包含一个源程序文件proj2.cpp。其中定义了Score类。
Score是一个用于管理考试成绩的类。其中,数据成员_s指向存储成绩的数组,_n表示成绩的个数;成员函数Sort使用冒泡排序法将全部成绩按升序进行排列。
请在程序中的横线处填写适当的代码,然后删除横线,以实现Score类的成员函数Sort。
注意:只在指定位置编写适当代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。
//proj2.cpp
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
class Score
public:
Score(double * s, int n):_s(s),_n(n)
double GetScore (int i) const return_s[i];
void Sort ( );
private:
double*_s;
int_n;
;
void Score::Sort( )

for(int i=0;i<n-1;______)
//********found********
for(int j=______;j>i;j--)
if(_s[j]<_s[j-1])
//交换_s[j]和_s[j-1]double t=_s[j];
//********found********
______;
//********found********
______;


int main ( )

const int NUM=10;
double s[NUM];
srand(time (0));
for(int i=0;i<NUM;i++)
s[i]=double(rand ( ))/RAND M
[简答题]请使用VC6或使用[答题]菜单打开考生文件夹proj2下的工程proj2,此工程中含有一个源程序文件proj2.cpp。函数char * GetNum(char*src,char*buf)从src开始扫描下—个数字字符序列,并将其作为一个字符串取出放入字符串空间buf中。函数返回扫描的终止位置,如果返回NULL表示没有扫描到数字字符序列。
运行程序时,如果输入的一行字符序列是
ABC012XY2378MN274WS
则输出为:
Digit string 1 is 012
Digit string 2 is 378
Digit string 3 is 274
注意:只在横线处编写适当代码,不要删除或移动“//****found****”。
//proj2.cpp
#include <iostream>
using namespace std;
char*GetNum(char*src,char*buf)

while(*src!=’/0’)

if(isdigit(*src)break;

if (*src=="/0")
//********found********
______;
while(*src!=’/0’&& isdigit(*src)

//********found********
______;
buf++;
src++;

*buf=’/0’;
return src;

int main( )

char str[100l,digits[20];
cin.getline(str,100);
char*p=str;
int i=1;
while((p=GetNum(p,digits))!=NULL)

cout<<"Digit string "<<i<<"is "<<digits<<endl;
//********found********
______;<
[简答题]请使用VC6或使用[答题]菜单打开考生文件夹proj2下的工程proj2。该工程中包含一个程序文件maln.cpp,其中有“书”类Book及其派生出的“教材”类TeachingMaterial的定义,还有主函数main的定义。请在程序中“//********found********”下的横线处填写适当的代码,然后删除横线,以实现上述类定义和函数定义。此程序的正确输出结果应为:
教材名:C++语言程序设计
页 数:299
作 者:张三
相关课程:面向对象的程序设计
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。
#include <iostream>
using namespace std;
class Book //"书"类
char * title; //书名
int num_pages; //页数
char * writer; //作者姓名
public:
Book(const char * the_title,intpages,const char * the_writer):num_pages(pages)
title=new char[strlen(the_title)+1];
strcpy(title,the_title);
//**********found**********
______
strcpy(writer,the_writer);

~Book( )______
int numOfPages( )constreturn num_pages; //返回书的页数
const char * theTitle ( ) const return title; //返回书名
const char * theWriter ( ) const return writer; //返回作者名
;
class TeachingMaterial:public Book
//“教材”类
char * course;
[简答题]请使用VC6或使用[答题]菜单打开考生文件夹proj1下的工程proj1,此工程包含一个源程序文件proj1.cpp。文件中将表示数组元素个数的常量Size定义为4,并用int类型对类模板进行了实例化。文件中位于每个注释“//ERROR****found****”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为:
1 2 3 4
注意:模板参数名用T。只修改注释“//ERROR ********found********”的下一行语句,不要改动程序中的其他内容。
//proj1.cpp
#include <iostream>
using namespace std;
//将数组元素个数 Size定义为4
//ERROR ********found********
const int Size;
template <typename T>
class MyClass

public:
MyClass(T*p)

for(int i=0;i<Size;i++)
array[i]=p[i];

void Print( );
private:
T array[Size];
;
template <typename T>
void MyClass::Print( )

for (int i=0;i<Size;i++)
cout<<array[i]<<’/t’;

int main( )

int intArray[Size]=1,2,3,4;
//ERROR ********found********
MyClass <double> obj(intArray);
obj.Print( );
cout<<endl;
return 0;

[简答题]请使用VC6或使用[答题]菜单打开考生文件夹proj3下的工程文件proj3,此工程中包含一个源程序文件proj3.cpp,其中定义了用于表示平面坐标系中的点的类MyPoint和表示矩形的类MyRectangle;程序应当显示:
(0,2)(2,2)(2,0)(0,0)4
但程序中有缺失部分,请按照以下提示,把缺失部分补充完整:
(1)在“//**1** ****found****”的下方是构造函数的定义,它用参数提供的左上角和右下角的坐标对up_left和down_right进行初始化。
(2)在“**2** ****found****”的下方是成员函数getDownLeft的定义中的一条语句。函数getDownLeft返回用MyPoint对象表示的矩形的左下角。
(3)在”//**3** ****found****”的下方是成员函数area的定义,它返回矩形的面积。
注意:只在指定位置编写适当代码,不要改动程序中的其他内容,也不要删除或移动“****found****”。
//proj3.cpp
#include<iostream>
using namespace std;
class MyPoint//表示平面坐标系中的点的类
double x;
double y;
public:
MyPoint (double x,double y)this->x=x;this->y=y;
double getX( )constreturn x;
double getY( )constreturn y;
void show( )constcout<<’(’<<x<<’,’<<y<<’)’;
);
class MyRectangle //表示矩形的类
MyPoint up_left; //矩形的左上角顶点
MyPoint down_right; //矩形的右下角顶点
public:
MyRectangle (MyPoint upleft, MyPoint downright);
MyPoint getUpLeft ( ) const re
[简答题]请使用VC6或使用[答题]菜单打开考生文件夹proj2下的工程proj2,该工程中含有一个源程序文件proj2.cpp,其中定义了CharShape类、Triangle类和Rectangle类。
CharShape是一个抽象基类,它表示由字符组成的图形(简称字符图形),纯虚函数Show用于显示不同字符图形的相同操作接口。Triangle和Rectangle是CharShape的派生类,它们分别用于表示字符三角形和字符矩形,并且都定义了成员函数Show,用于实现各自的显示操作。程序的正确输出结果应为:
*
***
*****
*******
########
########
########
请阅读程序,分析输出结果,然后根据以下要求在横线处填写适当的代码并删除横线。
(1)将Triangle类的成员函数Show补充完整,使字符三角形的显示符合输出结果。
(2)将Rectangle类的成员函数Show补充完整,使字符矩形的显示符合输出结果。
(3)为类外函数fun添加合适的形参。
注意:只在指定位置编写适当代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。
//proj2.cpp
#include<iostream>
using namespace std;
class CharShape
public:
CharShape (char ch):ch (ch));
virtual void Show( )=0;
protected:
char ch;//组成图形的字符;
class Triangle:public CharShape
public:
Triangle(char ch,int r):Char-Shape(ch),_rows (r)
void Show( );
private:
int rows; //行数
;
class Rectangle: public CharShape
public:
Rectan
[简答题]请使用VC6或使用[答题]菜单打开考生文件夹proj1下的工程proj1,此工程中含有一个源程序文件proj1.cpp。其中位于每个注释“//ERROR ****found****”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为:
The value is:10
注意:只修改注释“//ERROR ****found****”的下一行语句,不要改动程序中的其他内容。
//proj1.cpp
#include <iostream>
using namespace std;
class Member
//ERROR ********found********
private:
Member(int val):value(val)
int value;
;
class MyClass
Member m;
public:
MyClass(int val)
int GetValue ( ) const return_m.value;
;
int main ( )

MyClass * obj=new MyClass(10);
//ERROR ********found********
下列i语句输出 obj指向类中的 value值
cout<<"The value is:"<<obj.GetValue ( )<<endl;
delete obj;
return 0;
[简答题]请使用VC6或使用[答题]菜单打开考生文件夹proj2下的工程proj2,此工程中包含一个头文件shape.h,其中包含了类Shape、Point和Triangle的声明;包含程序文件shape.cpp,其中包含了类Triangle的成员函数和其他函数的定义;还包含程序文件proj2.cpp,其中包含测试类Shape、Point和Triangle的程序语句。请在程序中的横线处填写适当的代码并删除横线,以实现上述功能。此程序的正确输出结果应为:
此图形是一个抽象图形,周长=0,面积=0
此图形是一个三角形,周长=6.82843,面积=2
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。
//shape.h
class Shape
public:
virtual double perimeter( )const return 0; //返回形状的周长
virtual double area( )const return 0;) //返回形状的面积
virtual const char * name( )constreturn"抽象图形"; //返回形状的名称
;
class Point //表示平面坐标系中的点的类
double x;
double y;
public:
//**********found**********
Point (double x0, double y0):______//用x0、y0初始化数据成员X、Y
double getX( ) constreturn x;
double getY( ) constreturn y;
;
class Triangle:public Shape
//**********found**********
______;
//定义3个私有数据成员
public:
Triangle(Point p1,Point p2,Pointp3):point1(p1),point2(p2),point3(p3)

我来回答:

购买搜题卡查看答案
[会员特权] 开通VIP, 查看 全部题目答案
[会员特权] 享免全部广告特权
推荐91天
¥36.8
¥80元
31天
¥20.8
¥40元
365天
¥88.8
¥188元
请选择支付方式
  • 微信支付
  • 支付宝支付
点击支付即表示同意并接受了《购买须知》
立即支付 系统将自动为您注册账号
请使用微信扫码支付

订单号:

请不要关闭本页面,支付完成后请点击【支付完成】按钮
恭喜您,购买搜题卡成功
重要提示:请拍照或截图保存账号密码!
我要搜题网官网:https://www.woyaosouti.com
我已记住账号密码