网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)

使用VC6打开考生文件夹下的工程test41_3。此工程包含一个test41_3.cpp,其中定义了类Rectangle,但该类的定义并不完整。请按要求完成下列操作,将程序补充完整。

(1)定义类Rectangle的私有数据成员left,top和fight,bottom,它们都是int型的数据。请在注释“//**1**”之后添加适当的语句。

(2)添加类Rectangle的带四个int型参数1、t、r、b的构造函数的声明,并使这四个参数的默认值均为0,请在注释“//**2**”之后添加适当的语句。

(3)添加类Rectangle的成员函数SetTop()参数为int型的t,作用为把t的值赋给类的数据成员top,添加类Rectangle的成员函数SetBottom()参数为int型的t,作用为把t的值赋给类的数据成员bottom,请在注释“//**3**”之后添加适当的语句。

(4)完成派生类Rectangle的成员函数Show()的定义,使其以格式“right-bottom point is(right,bottom)”输出,请在注释“//**4**”之后添加适当的语句。

源程序文件test41_3.cpp清单如下:

include <iostream.h>

class Rectangle

{

// ** 1 **

int right, bottom;

public:

// ** 2 **

~ Rectangle(){};

void Assign(int 1, int t, int r, int b);

void SetLeft(int t){left = t;}

void SetRight(int t){right = t;}

// ** 3 **

void SetBottom(int t){bottom = t;}

void Show();

};

Rectangle::Rectangle(int 1, int t, int r, int b)

{

left = 1; top = t;

right = r; bottom = b;

}

void Rectangle::Assign(int 1, int t, int r, int b)

{

left = 1; top = t;

right = r; bottom = b;

}

void Rectangle::Show()

{

cout<<"left-top point is ("<<left<<","<<top<<")"<<'\n';

// ** 4 **

}

void main()

{

Rectangle rect;

rect.Show();

rect.Assign(100,200,300,400);

rect.Show();

}


参考答案

更多 “ 使用VC6打开考生文件夹下的工程test41_3。此工程包含一个test41_3.cpp,其中定义了类Rectangle,但该类的定义并不完整。请按要求完成下列操作,将程序补充完整。(1)定义类Rectangle的私有数据成员left,top和fight,bottom,它们都是int型的数据。请在注释“//**1**”之后添加适当的语句。(2)添加类Rectangle的带四个int型参数1、t、r、b的构造函数的声明,并使这四个参数的默认值均为0,请在注释“//**2**”之后添加适当的语句。(3)添加类Rectangle的成员函数SetTop()参数为int型的t,作用为把t的值赋给类的数据成员top,添加类Rectangle的成员函数SetBottom()参数为int型的t,作用为把t的值赋给类的数据成员bottom,请在注释“//**3**”之后添加适当的语句。(4)完成派生类Rectangle的成员函数Show()的定义,使其以格式“right-bottom point is(right,bottom)”输出,请在注释“//**4**”之后添加适当的语句。源程序文件test41_3.cpp清单如下:include <iostream.h>class Rectangle{// ** 1 **int right, bottom;public:// ** 2 **~ Rectangle(){};void Assign(int 1, int t, int r, int b);void SetLeft(int t){left = t;}void SetRight(int t){right = t;}// ** 3 **void SetBottom(int t){bottom = t;}void Show();};Rectangle::Rectangle(int 1, int t, int r, int b){left = 1; top = t;right = r; bottom = b;}void Rectangle::Assign(int 1, int t, int r, int b){left = 1; top = t;right = r; bottom = b;}void Rectangle::Show(){cout<<"left-top point is ("<<left<<","<<top<<")"<<'\n';// ** 4 **}void main(){Rectangle rect;rect.Show();rect.Assign(100,200,300,400);rect.Show();} ” 相关考题
考题 使用VC6打开考生文件夹下的工程test4_1,此工程包含一个源程序文件test4_1.cpp,但该程序在类的定义中存在问题,请改正类定义中的错误,使程序的输出结果如下:a=3 b=13a=5 b=13注意:请勿修改主函数main中的任何内容。源程序文件rcst4_1.cpp清单如下:include<iostream.h>class T{public:/*********found***+******/T(int x){a=x; b+=x;)/+********found**********/void display(T c){ cout<<"a="<<c.a<<"\t"<<"b="<<c.b<<endl;)private:const int a;static int b;};/**********found*********/int b=5;void main(){T A(3),B(5);T::display(A);T::display(B);}

考题 使用VC6打开考生文件夹下的工程test29_1,此工程包含一个源程序文件test29_1.cpp,但该程序运行有问题,请改正程序中的错误,使该程序的输出结果为:A:no parametersB:int parameterA:no parametersB:int parameterC:int parameter源程序文件test29_1.cpp清单如下;include <iostream.h>class A{/***************** found *****************/private:A(){ cout<<"A:no parameters\n";}A(int a) {cout<<"A: int parameter\n";}};class B:public A{public:B(int a){cout<<"B:int Parameter\n";}};/***************** found *****************/class C:public B,public A{public:/***************** found *****************/C(int a) ::B(a) {cout<<"C: int parameter\n"; )};void main ( ){B b(1);C c(2);}

考题 使用VC6打开考生文件夹下的工程proj2。此工程包含一个源程序文件main2.cpp,但该程序运行有问题。请改正main函数中的错误。源程序文件main2.cpp清单如下://main2.cppinclude <iostream>using namespace std;class MyClass{public:MyClass(int m){member=m;}~MyClass() {}int GetMember(){return member;}private:int member;};MyClass MakeObject(int m){MyClass *pMyClass=new MyClass(m);return *pMyClass;}int main ( ){int x=7;/************found**************/MyClass *myObj=MakeObject(x);/*************found*************/cout<<"My object has member"<<myObj.GetMember()<<end1;return 0;}

考题 使用VC6打开考生文件夹下的工程test34_1,此工程包含一个源程序文件test34_1.cpp,但该程序运行有问题,请改正程序中的错误,使该程序的输出结果为:David 3123 1000源程序文件test34_1.cpp清单如下:include <iostream.h>include <string.h>class person{public:char name[20];unsigned long id;float salary;void print(){cout<<name<<' '<<id<<' '<<salary<</***************** found *****************/}void main( ){person p;person *ptr;/***************** found *****************/ptr=p;/***************** found *****************/strcpy("David",ptr->name);ptr->id=3123;ptr->salary=1000;ptr->print();}

考题 使用VC6打开考生文件夹下的工程test21_1,此工程包含一个源程序文件test21_1.cpp,但该程序运行有问题,请改正程序中的错误,使程序的输出结果如下:The grade is 3源程序文件test21_1.cpp清单如下:include<iostream.h>class student{private:int grade;public:/**************** found*******************/student(int thegra):(thegra){}~student(){}int get_grade(){return grade;}};void main(){int thegra=3;/**************** found*******************/student point=new student(thegra);/**************** found*******************/cout<<"The grade is"<<point.get_grade()<<endl;delete point;}

考题 使用VC6打开考生文件夹下的工程test1_1,此工程包含一个源程序文件test1_1.cpp,但该程序运行有问题,请改正main函数中的错误,使该程序的输出结果如下:Constructor called.Default constructor called.Area is 6Area is 0Area is 6源程序文件test1_1,cpp清单如下:include<iostream.h>class RectAngle{private:double ledge,sedge;public:RectAngle(){cout<<"Default constructor called.";}RectAngle(double l,double s){ledge=l;sedge=s;cout<<"Constructor called.";}void Set(double l,double s){ledge=l;sedge=s;}void Area(){cout<<"Area is"<<ledge*sedge<<endl;}};void main(){/***************** found *****************/RectAngle Rect1(2,3);RectAngle Rect2(1);/**************** found *****************/RectAnglC Rect3;Rectl.Area();/***************** found *****************/RecL2.lodge=0;Rect2.sedge=0;Reck2.Area();Rect3.Area();}

考题 使用VC6打开考生文件夹下的工程RevProj15。此工程包含一个源程序文件RevMain15.cpp,但该程序中类的定义有错误。请改正程序中的错误,使它能得到正确结果。注意,不要改动主函数,不得删行或增行,也不得更改程序的结构。源程序文件RevMain15.cpp中的程序清单如下://RevMain15.cppinclude<iostream>using namespace std;class Sample{private:int x;static int y;public:Sample(int a){x=a;y+=x;}static void print(Sample s){cout<<"x="<<x<<",y="<<y<<end1;}Sample::y=5;int main(){Sampel s1(10);Sample s2(15);Sample::print(s1);Sample::print(s2);return 0;}

考题 使用VC6打开考生文件夹下的工程test41_1,此工程包含一个源程序文件test41_1.cpp,但该程序运行有问题,请改正函数中的错误,使该程序的输出结果为:7源程序文件test41_1.cpp清单如下:include<iostream.h>class myclass{int a, b;public:/***************** found *****************/int sum(myclass x);void set_ab(int i, int j);}:/**************** found ****************/void myclass:set_ab(int i, int j){a=i;b=j;}int sum (myclass x){/***************** found ***************/x.a+x.b;}void main ( ){myclass n;n.set_ab (3, 4);cout <<sum(n)<<endl;}

考题 使用VC6打开考生文件夹下的工程test15_1,此工程包含一个源程序文件test15_1.cpp,但该程序运行有问题,请改正程序中的错误,使该程序的输出结果如下:My object has member 7源程序文件test15_1.cpp清单如下:include<iostream.h>class MyClass{public:MyClass(int mem){member=mem;}~MyClass(){}int GetAge()const{ return member;}private:int member;};/*****+********+** found *************/void main(){int mem=7;/*************** found ***************/MyClass myObj=MakeObject(mem);cout<<"My object has member"<<myObj->GetAge()<<endl;/***************** found ****************/delete;}MyClass *MakeObject(int mem){MyClass *pMyClass=new MyClass(mem);return pMyClass;}