面向对象程序设计C山师第六章习题答案.docx面向对象程序设计C山师第六章****题答案
面向对象程序设计C山师第六章****题答案
面向对象程序设计C山师第六章****题答案
第六章****题答案
一、选择填空
1、A 2、C 3、D 4、B 5、D 6 、A 7、C 向对象程序设计C山师第六章****题答案
2/22
面向对象程序设计C山师第六章****题答案
面向对象程序设计C山师第六章****题答案
面向对象程序设计C山师第六章****题答案
⑶类中成员函数 Setc( )的功能是用来设置字符数组中某地址的一个指定字符。⑷类中成员函数 Getc( )的功能是用来从某个字符数组中获取指定地址的字符。⑸类中成员函数 Append( )的功能是在一个字符数组中追加一个指定的字符串,立刻指
定的字符串增加到已知串的后边。
⑹不能够。
⑺该程序中有两处使用了 new 运算符。
⑻运行该程序输出结果以下所示。
empty.
a string.
9
a string.
i
this a string.
四、改正以下程序中的错误。
1、该程序中 point 类的构造函数定义不正确,在 main() 中队数据成员的接见不正确,
改正以下:
#include <>
class point
{
int x1,x2 。
public:
point(int x,int y){point::x=x 。 point::y=y 。 }
void disp()
{
cout<<x1<<endl 。
cout<<x2<<endl 。
}
} 。
void main()
{
point data(5,5) 。
()。
}
2、在 main() 函数中的 +=5 和 +=6 两个语句是错误的,因为保护数据仅能被类的
成员函数接见。
五、按以下要求编写程序。
1、程序内容以下所示。
#include <>
class Test
{
public:
Test(){}
Test(int i,int j=20)
面向对象程序设计C山师第六章****题答案
面向对象程序设计C山师第六章****题答案
面向对象程序设计C山师第六章****题答案
3/22
面向对象程序设计C山师第六章****题答案
面向对象程序设计C山师第六章****题答案
面向对象程序设计C山师第六章****题答案
{
t1=i 。
t2=j 。
t+=j-i 。
}
static int fun(Test&T) 。
friend int add(Test&T) 。
private:
int t1,t2 。
static int t 。
} 。
int Test::fun(Test&T)
{
t+= 。
return t 。
}
int add(Test&T)
{
int n=+ 。
return n 。
}
int Test::t=5 。
void main()
{
Test a1,a2(10),a3(15,25)。
cout<<add(a2)<<endl 。
cout<<Test::fun(a2)<<endl 。
}
2、程序内容以下所示。
#include <>
#include <>
class Product
{
char *name 。
int price 。
int quantity 。
public:
Product(char *n,int p,int q)
{
name =new char[strlen(n)+1] 。
strcpy(name,n) 。
price=p。
quantity=q 。
}
面向对象程序设计C山师第六章****题答案
面向对象程序设计C山师第六章****题答案
面向对象程序设计C山师第六章****题答案
4/22
面向对象程序设计C山师第六章****题答案
面向对象程序设计C山师第六章****题答案
面向对象程序设计C山师第六章****题答案
~Product()
{
if(name)
{
delete [] n
面向对象程序设计C山师第六章习题答案 来自淘豆网www.taodocs.com转载请标明出处.