题目详情
当前位置:首页 > 职业培训考试
题目详情:
发布时间:2023-10-23 22:16:04

[简答题]请使用“答题”菜单或使用VC6打开考生文件夹proj1下的工程proj1,此工程包含程序文件
main.cpp,其中有类Book(“书”)和主函数main的定义。程序中位于每个//ERROR************found************下的语句行有错,请加以改正。改正后程序的输出应该是:
书名:C++语言程序设计 总页数:299
已把"C++语言程序设计"翻页到第50页
已把“C++语言程序设计"翻页到第51页
已把书合上。
书是合上的。
已把"C++语言程序设计"翻页到第1页
注意:只能修改每个//ERROR************found************下的那一行,不要改动程序中的其他内容。
// 源程序
#include<iostream>
using namespace std;
class Book
char*title;
int num_pages; //页数
int cur_page; //当前打开页面的页码,0表示书未打开
public:
Book(const char*theTitle,int pages):num_pages(pages)
//ERROR************found************
title=new char[strlen(theTitle)];
strcpy(title,theTitle);
cout<<endl<<"书名:"<<title<<"总页数:"<<num_pages;

~Book( )delete[]title;
//ERROR************found************
bool isOpen( ) const return num_pages!=0; //书打开时返回true,否则返回false
int numOfPages( ) const return num_pages; //返回书的页数
int currentPage( ) const return cur_page; //返

更多"请使用“答题”菜单或使用VC6打开考生文件夹proj1下的工程proj"的相关试题:

[简答题]请使用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;) //返回打开页面的页
[简答题]请使用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或使用[答题]菜单打开考生文件夹proj1下的工程proj1,此工程中含有一个源程序文件proj1.cpp。其中位于每个注释“//ERROR ****found****”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为:
Constructor called.
The value is 10
Copy constructor called.
The value is 10
Destructor called.
Destructor called.
注意:只修改注释“//ERROR ****found****”的下一行语句,不要改动程序中的其他内容。
//proj1.cpp
#include <iostream>
using namespace std;
class MyClass
public:
//ERROR **********found**********
MyClass(int i)
value=i;cout<<"Construc-tor called."<<endl;
//ERROR **********found**********
MyClass(const MyClass p)

value=p.value;
cout<<"Copy constructorcalled."<<endl;

void Print ( )
cout<<"The value is"<<value<<endl;
//ERROR **********found**********
void ~MyClass( )
cout<<"Destructor called."
<<endl;
private:
int value;
;
int main( )

MyClass obj1;
obj1.Print( );
MyClass obj2(obj1);
obj2.Print( );
return
[简答题]请使用VC6或使用[答题]菜单打开考生文件夹proj1下的工程proj1。其中有线段类Line的定义。程序中位于每个“//ERROR ****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应该是:
End point 1=(1,8),End point 2=(5,2),length=7.2111。
注意:只修改每个“//ERROR ****found****”下的那一行,不要改动程序中的其他内容。
#include <iostream>
#include <cmath>
using namespace std;
class Line;
double length(Line);
class Line //线段类
double x1,y1; //线段端点1
double x2,y2; //线段端点2
public:
//ERROR **********found**********
Linedouble x1,double y1,doublex2,double y2)const
this->x1=x1;
this->y1=y1;
this->x2=x2;
this->y2=y2;

double getX1( )constreturn x1;
double getY1( )constreturn y1;
double getX2( )constreturn x2;
double getY2( )constreturn y2;
void show ( ) const
cout<<"End point 1=("<<x1<<","<<y1;
cout<<"),End point 2=("<<x2<<","<<y2;
//ERROR ********found********
cout<<"),length="<<length(this)
<<"。"<<endl;

;
double length (Line 1)
//ERROR
[简答题]请使用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 hum_pages; //页数
int cur_page; //当前打开页面的页码,0表示书未打开
public :
// ERROR ********** found **********
Book ( const char * theTide, int pages) num_pages (pages)

tide = new char[ strlen(theTifle) + 1 ] ;
strcpy ( tide, theTitle ) ;
cout << endl << " 书名:" << title
<< "页面数:" << num_pages ;

~Book( ) delete []title;
bool isClosed ( ) const return cur_page == 0 ; //书合上时返回true,否则返回false
bool isOpen( )const return ! isClosed( ) ; //书打开时返回true,否则返回false
int numOfPages ( ) const re
[简答题]请使用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;

[简答题]请使用“答题"菜单或使用VC6打开考生文件夹proj1下的工程proj1,该工程含有一个源程序文件proj1.cpp。程序中位于每个//ERROR************found************下的语句行有错误。请改正这些错误,改正后程序的输出应该是:
1 2 3 4 5 6 7 8 9 10
注意:只修改注释//ERROR************found************下的一行语句,不要改动程序中的其他内容。
//源程序proj1.cpp
#include<iostream>
using namespace std;
class MyClass
public:
MyClass(int len)
array=new int[len];
arraySize=len;
for(int i=0;i<arraySize; i++) array[i]=i+l;

~MyClass( )
//ERROR************found************
delete array[];

void Print( ) const
for(int i=0;i<arraySize; i++)
//ERROR************found************
cin<<array[i]<<";
cout<<endl;

prlvate:
int*array;
int arraySize;

int main( )
//ERROR************found************
MyClass obj;
obj.Print( );
return 0:

[简答题]请使用“答题”菜单或使用VC6打开考生文件夹proj1下的工程proj1。此工程定义了Stop-Watch(秒表)类,用于表示时、分、秒信息,有构造函数StopWatch( )、设置时间函数reset( )、并且重载了前置和后置++运算符,用于实现增加秒的功能。程序中位于每个//ERROR************found************下的语句行有错误,请加以改正。改正后程序的输出应该是:
00:00:00
00:01:00
注意:只能修改每个//ERROR************found************下的那一行,不要改动程序中的其他内容。
//源程序
#include<iostream>
#include<iomanip>
using namespace std;
class StopWatch //“秒表”类
int hours,minutes,seconds; //小时、分钟、秒
public:
StopWatch( ):hours(0),minutes (0),seconds(0)
void reset( )hours=minutes=seconds=0;
StopWatch operator++(int) //后置++
StopWatch old=*this;
++(*this);
return old;

//前进1秒
StopWatch& operator++( ) //前置++
//ERROR************found************
if(seconds++==60)
seconds=0;minutes++;
if(minutes==60)
minutes=0;hours++;


//ERROR************found************
return this:

friend void show(StopWatch);

void show(StopWatch watc
[多项选择]请使用“答题”菜单或使用VC6打开考生文件夹proj1下的工程proj1。程序中位于每个//ERROR************found************下的语句行有错,请加以改正。改正后程序的输出应该是:
Name:Smith Age:21 ID:99999 CourseNum:12 Record:970
注意:只能修改每个//ERROR************found************下的那一行,不要改动程序中的其他内容。
//源程序
#include<iostream>
using namespace std;
class StudentInfo
protected:
//ERROR************found************
char Name[];
int Age;
int ID;
int CourseNum;
float Record:
public:
//ERROR************found************
void StudentInfo(char*name, int age, int ID, int courseNum,float record);
//ERROR************found************
void~StudentInfo( )delete[]Name;
float AverageRecord( )
return Record/CourseNum:

void show( ) consL;

StudentInfo::StudentInfo(char*name, int age, int ID, int courseNum, float record)
Name=strdup(name);
[简答题]请使用“答题”菜单或从VC6中打开考生文件夹proj1下的工程proj1。此工程包含了类Pets(“宠物”)和主函数main的定义。程序中位于每个//ERRO************found************下的语句行有错,请加以改正。改正后程序的输出结果是: Name: sonny Type: dog Name: John Type: dog Name: Danny Type: cat Name: John Type: dog 注意:只能修改每个//ERROR************found************下的那一行,不要改动程序中的其他内容。 //源程序 #include <iostream> using namespace std; enum Pets_type{dog,cat,bird,fish}; class Pets{ private: char*name: Pets_type type; public: Pets(const char*name="sonny",Pets_type type=dog); Pets& operator=(const Pets &s); ~Pets( ); void show( ) const; }; Pets::Pets(const char*name,Pets_type type){ //构造函数 this->name=new char[strlen(name)+1]; strcpy(this->name,name); //ERROR************found************ type=type; } Pets::~Pets( ){ //析构函数,释放name所指向的字符串 //ERROR************found************ name=’/0’: } Pets&Pets::operator=(const Pets &s){ if(&s==this) return*this; //确保不要向自身赋值 delete[]name; name=new char[strlen(s.name)+1]; //ERROR************found************ strcpy(s.name,this->name); type=S.type; return*this: } void Pets::show( ) const{ couL<<"Name:"<<name<<"Type:"; switch(type){ case dog: cout<<"dog";break; case cat: cout<<"cat";break; case bird: cout<<"bird";break; case fish: cout<<"fish";break; } cout<<endl; } int main( ){ Pets mypet1,mypet2("John",dog); Pets youpet("Danny",cat); mypet1.show( ); mypet2.show( ); youpet.show( ); youpet=mypet2; youpet.show( ); return 0: }
[简答题]请使用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或使用[答题]菜单打开考生文件夹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下的工程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

我来回答:

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

订单号:

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