题目
(1)定义类Table的私有数据成员x和y,分别用于表示九九表中的两个乘数(x*y),它们都是int型的数据。请在注释“//**1**”之后添加适当的语句;
(2)完成类Table的成员函数prin()的定义,该函数以“x*y=z”的格式打印出九九表中的一个乘法算式,请使用格式化输出函数prinff实现,在注释“//**2**”之后添加适当的语句;
(3)完成类Table9的成员函数print()的定义,该函数调用基类Table的print()函数,将九九表输出到屏幕,请在注释“//**3**”之后添加适当的语句;
(4)补充主函数,在屏幕上输出九九表,以便测试所定义的类的正确性。请在注释“//**4**”之后添加适当的语句。
注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。
源程序文件test8_3.cpp清单如下:
include<iostream.h>
include<stdio.h>
class Table
{
//**1**
int z;
public:
void print(int x,int y,int z);
};
void Table::print(int x,int y,int z)
{
//**2**
}
class Table9:public Table
{
public:
void print();
};
void Table9::print()
{
//**3**
int x,y,z;
for (i=1;i<1O;i++)
{
for(j=1;j<i+1;j++)
{
x=i;
y=j;
z=i*j;
Table::print(y,x,z);
}
printf("\n");
}
}
main()
{
//+*4**
return 0;
}
第1题
注意:不得删行或增行,也不得更改程序的结构。
源程序文件RevMain12.cpp中的程序清单如下:
//RevMain12.cpp
include<iostream>
/* * * * FOUND * * * * */
using namespace std;
class test
{
private:
const int value;
char dep[10];
public:
/* * * * *FOUND* * * * */
test()
{
value=0;
strcpy(dep,"m");
}
/* * * * *FOUND* * * * */
test(int newvalue)
{
value=newvalue;
strcpy (dep, "m");
}
/* * * * *FOUND * * * * */
void show()
{
cout<<"value= "<<value<<end1;
}
};
int main ()
{
test t1;
const test t2;
t1.show ();
t2.show();
return 0;
}
第2题
使用VC6打开考生文件夹下的工程test18_1,此工程包含一个源程序文件(est18_1.cpp,但该程序运行有问题,请改正程序中的错误,使程序的输出结果如下:
Enter x and y:
-4 -5
xoffset=1
yoffset=1
angle=45
radius=1.41421
源程序文件test18_1.cpp 清单如下:
include <iostream.h>
include <math.h>
class point
{
public:
void set(double ix,double iy)
{
x=ix;
y=iy;
}
double xoffset()
{
return x;
}
double yoffset()
{
return y;
}
double angle ()
{
return (180/3.14159)*atan2(y,x);
}
/**************** found *******************/
inline radius ()
{
return sqrt(x*x+y*y);
}
protected:
double x;
double y;
};
void main()
{
point p;
double x,y;
cout<<"Enter x and y:\n";
cin>>x>>y;
p.set(x,y);
/**************** found *******************/
p.x+=5;
p.y+=6;
/**************** found *******************/
cout<<"xoffset="<<p.xoffset()<<end1;
cout<<"yoffset="<<p.yoffset()<<end1;
cout<<"angle="<<p.angle()<<end1;
cout<<"radius="<<p.radius()<<end1;
第3题
5
5
源程序文件test28_1.cpp清单如下:
include <iostream.h>
class A{
public:
/***************** found *****************
static int n=1;
A(){n++;};
~A() (n--;};
};
/***************** found *****************
int n=0;
int main() {
A a;
A b[3];
A *c=new A;
c=&a;
/***************** found *****************
cout<<c.n<<end1;
cout<<A::n<<end1;
return 0;
}
第4题
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;
}
第5题
源程序文件RevMain3.cpp清单如下:
//RevMain3.cpp
include<iostream>
using namespace std;
class MyClass{
public:
/* * * * * * * * *found * * * * * * + * * */
void MyClass(int a){ value=a;}
int Max(int x,int y)
{
if(x>y)
return x>y?x:y;
else
return y>value?y:value;
}
/* * * * * * * * *found * * * * * * * * * */
~MyClass(int a)
{
value=a;
}
private:
int value;
};
int main()
{
MyClass my(10);
cout<<my.Max(20,30)<<end1;
return 0;
}
第6题
x=20
源程序文件RevMain4.cpp的清单如下:
//RevMain4.cpp
include<iostream>
using namespace std;
class MyClass
{
public:
MyClass(int a)
{
x=a;
}
void setX(int a)
{
x=a;
}
void print()
{
cout<<"x="<<x;
}
private:
int x;
};
int main()
{
const MyClass obj (10);
/ ************found**************/
obj.setX(20);
/ ************found**************/
obj.print();
return 0;
}
第7题
100
源程序文件test27_1.cpp清单如下:
include <iostream.h>
template <class T>
class pair
{
T valuel, value2;
public:
pair (T first, T second)
{valuel=first; value2=second;}
/***************** found *****************/
char getmax ();
};
/***************** found *****************/
T pair<T>::getmax ()
{
T retval;
/***************** found *****************/
retval = valuel>value2?? value1 : value2;
return retval;
}
void main ()
{
pair <int> myobject (100, 75);
cout << myobject.getmax()<<end1;
}
第8题
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();
}
第9题
源程序文件main2.cpp清单如下:
//main2.cpp
include <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;
}
第10题
A:a=5
display1:a=6
display2:a=5
源程序文件test3_1.cpp清单如下:
include<iostream.h>
Class A
{
public:
/**********found**********/
A (){}
void printa(){cout<<"A:a="<<a<<endl;}
private:
int a;
/***********found**********/
class B;
};
class B
{
public:
/*********found**********/
void display1(A t)
{
(*t).a++;cout<<"display1:a="<<(*t).a<<endl;
}
void display2(A t)
{
t.a--;cout<<"display2:a="<<t.a<<end1;
}
};
void main()
{
A obj1;
B obj2;
obj1.printa();
obj2.display1(&obj1);
obj2.display2(obi1);
}
第11题
Previous=9,Next=11
源程序文件test30_1.cpp清单如下:
include <iostream.h>
/***************** found *****************/
void prevnext (int,int &,int&);
int main ()
{
int x=10,y,z;
prevnext (x,y,z);
cout << "Previous=" << y << ", Next=" << z<<end1;
return 0;
}
/***************** found *****************/
void prevnext (int x, int prev, int next)
{
/***************** found *****************/
prev=x--;
next=++x;
}
为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!