下载此文档

面向对象程序设计C山师第六章习题答案.docx


文档分类:IT计算机 | 页数:约22页 举报非法文档有奖
1/22
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/22 下载此文档
文档列表 文档介绍
面向对象程序设计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转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数22
  • 收藏数0 收藏
  • 顶次数0
  • 上传人菲菲
  • 文件大小34 KB
  • 时间2022-01-23