C++面向对象程序设计教程(第3版)—-陈维兴-林小茶课后习题答案

上传人:gbs****77 文档编号:10126391 上传时间:2020-04-10 格式:DOCX 页数:46 大小:77.88KB
返回 下载 相关 举报
C++面向对象程序设计教程(第3版)—-陈维兴-林小茶课后习题答案_第1页
第1页 / 共46页
C++面向对象程序设计教程(第3版)—-陈维兴-林小茶课后习题答案_第2页
第2页 / 共46页
C++面向对象程序设计教程(第3版)—-陈维兴-林小茶课后习题答案_第3页
第3页 / 共46页
点击查看更多>>
资源描述
C 面向对象程序设计教程课后题答案 1 1 什么是面向对象程序设计 面向对象程序设计是一种新的程序设计范型 这种范型的主要特征是 程序 对象 消息 面向对象程序的基本元素是对象 主要结构特点是 第一 程序一般由类的定义和类的使用两部分组成 第二 程序中的一切操作都是通过向对象发送消息来实现的 1 2 什么是对象 什么是类 对象与类之间的关系是什么 对象是描述其属性的数据以及对这些数据施加的一组操作封装在一起构成的统 一体 类就是具有相同的数据和相同的操作的一组对象的集合 也就是说 类是对具 有相同数据结构和相同操作的一类对象的描述 类和对象之间的关系是抽象和具体的关系 类是多个对象进行综合抽象的结果 一个对象是类的一个实例 1 3 现实世界中的对象有哪些特征 请举例说明 现实世界中的对象具有以下特征 1 每一个对象必须有一个名字以区别于其他对象 2 用属性来描述对象的某些特征 3 有一组操作 每组操作决定对象的一种行为 4 对象的行为可以分为两类 一类是作用于自身的行为 另一类是作 用于其他对象的行为 例如一个教师是一个对象 每个教师对象有自己的名字来和别的教师区别 教 师具有编号 姓名 年龄 职称 专业等属性 教师拥有走路 吃饭 授课等 行为操作 走路 吃饭是作用于自身的行为 授课是作用于其他对象的行为 1 4 什么是消息 消息具有什么性质 一个对象向另一个对象发出的请求成为 消息 消息具有以下 3 个性质 1 同一个对象可以接收不同形式的多个消息 做出不同的相应 2 相同形式的消息可以传递给不同的对象 所做出的响应可以是不同 的 3 对消息的响应并不是必须的 对象可以响应消息 也可以不响应 1 5 什么是抽象和封装 请举例说明 抽象是将有关事物的共性归纳 集中的过程 例如 把所有具有大学生学籍的人归为一类 成为 大学生 这就是一个抽 象 封装是指把数据和实现操作的代码集中起来放在对象内部 并尽可能隐藏对象 的内部细节 例如 每一台洗衣机都有出厂日期 机器编号等属性 也有启动 暂停 选择 等操作 人们在使用洗衣机的时候只需要按下对应的按钮 而不用关心具体的 内部实现 这就是封装 1 6 什么是继承 请举例说明 继承就是允许派生类使用基类的数据和操作 同时 派生类还可以增加新的操 作和数据 例如 哺乳动物是一种热血 有毛发 用奶哺育幼崽的动物 狗是有犬牙 食 肉 特定的骨骼结构 群居的哺乳动物 狗就继承了哺乳动物 1 7 若类之间具有继承关系 则他们之间具有什么特征 若类之间具有继承关系 则他们之间具有下列几个特征 1 类间具有共享特征 包括数据和操作代码的共享 2 类间具有差别或新增部分 包括非共享的数据和操作代码 3 类具有层次结构 1 8 什么是单继承 多继承 请举例说明 单继承是指每个派生类只直接继承了一个基类的特征 例如狗继承自哺乳动物 多继承是指多个基类派生出一个派生类的继承关系 比如玩具车同时继承自玩 具和车 1 9 什么是多态 请举例说明 多态是指不同的对象收到相同的消息时执行不同的操作 例如 有一个窗口类对象 还有一个棋子类对象 当我们发出 移动 消息时 两个对象的行为不同 1 10 面向对象程序设计的主要优点是什么 1 可提高程序的重用性 2 可控制程序的复杂性 3 可改善程序的可维护性 4 能够更好地支持大型程序设计 5 增强了计算机处理信息的范围 能够很好地适应新的硬件环境 2 1 简述 C 的主要特点 1 C 是 C 的超集 保持与 C 的兼容 2 保持了 C 的简洁 高效和接近汇编语言等特点 并对 C 的功能作了 不少扩充 用 C 编写的程序比 C 更安全 可读性更好 代码结构更为合理 3 程序质量高 4 增加了面向对象机制 2 2 include using namespace std int main int a b d min cout a b min a b b a for d 2 d min d if a d 0 if d min cout No common denominators endl return 0 cout The lowest common denominator is d endl return 0 2 3 有效 2 4 没有函数声明 函数定义没有写返回值类型 2 5 1 等价 函数声明可以省略参数的名字 2 不等价 第二个的函数定义不能省略参数的名字 2 6 2 10 CDAAB 2 11 2 15 ACBDC 2 16 2 17 DC 2 18 101 2 19 10 10 2 20 10 20 2 21 举例说明可以使用 const 替代 define 以消除 define 的不安全性 include using namespace std int main int a 1 define T1 a a define T2 T1 T1 cout T2 is T2 endl return 0 上面这个程序 初看应该输出 T2 is 0 但是实际上 得出 T2 is 2 如果把 define 换成 const 则可以输出想要的结果 2 22 用动态分配空间的方法 计算 Fibonacci 数列的前 20 项 并存储到动态 分配的空间中 include using namespace std int main int pi new int 20 pi 1 pi 1 1 for int i 2 i 20 i pi i pi i 2 pi i 1 return 0 2 23 重载 sroot 函数 输出一个数的二次方根 include using namespace std double sroot int num return double sqrt double num double sroot long num return double sqrt double num double sroot double num return double sqrt num int main return 0 2 24 解决百钱问题 将一元人民币换成 1 2 5 分的硬币 有多少种换法 include using namespace std int main int num 0 总共换法的总数 初始化为 0 for int i 0 i 100 i for int j 0 j 100 break for int k 0 k 20 k if i 2 j 5 k 100 num cout 1 分 i 个 2 分 j 个 5 分 k 个 100 break cout num endl return 0 2 25 输入两个整数 按由小到大的顺序输出 要求使用变量的引用 include using namespace std void swap int b a b a a b int main int a b cin a b if a b swap a b cout a b endl return 0 2 26 用二分法求解 f x 0 的根 include using namespace std double Fun double x return 35 x 25 假设 f x 35x 25 int main double a b cin a if Fun a 0 cout x a b while Fun a Fun b 0 if Fun b 0 cout x b b a a b b a b a a b while 1 if Fun a b 2 0 cout x a b 2 endl return 0 if Fun a Fun a b 2 0 b a b 2 if Fun b Fun a b 2 0 a a b 2 return 0 3 1 类声明的一般格式是什么 class 类名 private 私有数据成员和成员函数 public 公有数据成员和成员函数 3 2 构造函数和析构函数的主要作用是什么 它们各自有什么特性 构造函数是一种特殊的成员函数 它主要用于为对象分配空间 进行 初始化 构造函数的名字必须与类名相同 而不能由用户任意命名 它可以有任意类型 的参数 但不能具有返回值类型 析构函数通常用于执行一些清理任务 如释放分配给对象的内存空间等 析构函数名与类名相同 但它前面必须加一个波浪号 不能有返回值 也不能 有参数 3 3 什么是对象数组 所谓对象数组 是指每一个数组元素都是对象的数组 3 4 什么是 this 指针 它的主要作用是什么 C 为成员函数提供了一个名为 this 的指针 这个指针称为自引用指 针 每当创建一个对象时 系统就把 this 指针初始化为指向该对象 一个类的所有对象合用一份成员函数 this 指针可以帮助对象辨别 出当前调用的是自己的那个对象的数据成员和函数 3 5 友元函数有什么作用 友元函数可以在类的外部访问类的私有成员或保护成员 3 6 1 声明并定义了 P2 P3 并用默认无参构造函数初始化 2 声明并定义了 P2 并调用 Point 类的拷贝构造函数用 P1 对 P2 进行初始 化 3 声明并定义了 P2 并调用 Point 类的拷贝构造函数用 P1 对 P2 进行初始 化 4 调用拷贝构造函数 将 P1 的成员值赋值给 P4 的成员 3 7 3 10 BCCB 3 11 3 15 BAABA 3 16 3 17 BB 3 18 10 20 30 48 50 68 70 80 90 16 11 120 3 19 Constructing 10 100 Destructing 3 20 3objects in existence 4objects in existence after allocation 3objects in existence after deletion 3 21 Counting at0 Counting at9 3 22 Default constructor called Default constructor called Default constructor called Construcotor a 1 b 2 Construcotor a 3 b 4 Construcotor a 5 b 6 3 23 Con Copy con default Copy con 3 24 A 5 B 14 A 9 B 14 3 25 5 7 22 25 3 26 Constructing Constructing A 5 B 15 A 10 B 15 Destructing Destructing 3 27 void pintStu 函数只有声明 没有定义 age 是私有成员 不能用对象直接调用 3 28 void printStu 和 void setSno int s 没有加限定符 Student void setAge int a 在类中没有声明 3 29 构造函数不能定义为私有 否则无法创建对象 3 30 下面是一个计算器类的定义 请完成该类成员函数的实现 class counter public counter int number void increment 给原始值加 1 void decrement 给原始值减 1 int getvalue 取的计数器值 int print 显示计数 private int value counter counter int number value number void counter increment value void counter decrement value int counter getvalue return value int counter print cout value endl return value 3 31 根据注释语句提示 实现类 Date 的成员函数 include using namespace std class Date public void printDate void setDay int d void setMonth int m void setYear int y private int day month year void Date printDate cout 今天是 year 年 month 月 day 日 endl void Date setDay int d day d void Date setMonth int m month m void Date setYear int y year y int main Date testDay testDay setDay 5 testDay setMonth 10 testDay setYear 2003 testDay printDate return 0 3 32 建立类 cylinder cylinder 的构造函数被传递了两个 double 值 分别表示圆柱体的半径 和高度 用类 cylinder 计算圆柱体的体积 并存储在一个 double 变量中 在类 cylinder 中 包含一个成员函数 vol 用来显示每个 cylinder 对象的体积 const int PI 3 14 class cylinder private double radius height volume public cylinder int rad int hei double getVolume void vol cylinder cylinder int rad int hei radius rad height hei double cylinder getVolume volume PI radius radius height return volume void cylinder vol cout 圆柱体的体积是 volume endl 3 33 构建一个类 book 其中包含有两个私有数据成员 qu 和 price 将 qu 初始化为 1 5 将 price 初始化为 qu 的 10 倍 建立一个有 5 个元素的数组对象 显示每个对象数组元素 的 qu price 值 class book private int qu price public book int qu int mult book book int q if q 5 qu 1 else qu q price 10 qu int book mult return qu price int main book books 5 1 2 3 4 5 for int i 0 i 5 i cout books i mult 3 34 修改 3 33 通过对象指针访问对象数组 使程序以相反的顺序显示每个对象数组元素 的 qu price 值 class book private int qu price public book int qu int mult book book int q if q 5 qu 1 else qu q price 10 qu int book mult return qu price int main book books 5 1 2 3 4 5 book p books p 4 for int i 0 i 5 i cout mult p return 0 3 35 构建一个类 Stock 含字符数组 stockcode 及整型数组成员 quan 双精度型数据成员 price 构造函数含 3 个参数 字符数组 na 及 q p 当定义 Stock 的类对象时 将对象的 第一个字符串参数赋给数据成员 stockcode 第 2 和第 3 个参数分别赋给 quan price 未 设置第 2 和第 3 个参数时 quan 的值为 1000 price 的值为 8 98 成员函数 print 没有形参 需使用 this 指针 显示对象数据成员的内容 编写程序显示对象数据成员的值 include using namespace std class Stock private char stockcode 25 int quan double price public Stock char na int q 1000 double p 8 98 Stock char na void print Stock Stock char na int q 1000 double p 8 98 strcpy stockcode na quan q price p void Stock print cout stockcode stockcode quan quan price price endl int main Stock stock1 600001 3000 5 67 Stock stock2 600002 stock1 print stock2 print return 0 3 36 编写一个程序 已有若干学生的数据 包括学号 姓名 成绩 要求输出这些学生的 数据并计算出学生人数和平均成绩 要求将学生人数和总成绩用静态数据成员表示 include using namespace std class student private char name 25 studentNo 10 int score static int sum static int totalScore public student char na char stuNo int sc void show static void showTotal student student char na char stuNo int sc strcpy name na strcpy studentNo stuNo score sc sum totalScore sc void student show cout 姓名 name endl cout 学号 studentNo endl cout 成绩 score endl void student showTotal cout 总人数 sum endl cout 平均成绩 double totalScore sum endl int student sum 0 int student totalScore 0 int main student s1 张无忌 111254 75 student s2 李莫愁 254114 60 student s3 小龙女 112587 88 s1 show s2 show s3 show student showTotal return 0 4 1 有哪几种继承方式 每种方式的派生类对基类成员的继承性如何 公有继承 私有继承和保护继承 基类的私有成员 无论哪种继承方式都不能访问 公有继承不改变基类的公有和保护成员的访问限制 私有继承将基类的公有和保护成员都变成私有 保护继承将基类的公有和保护成员都变成保护 4 2 派生类能否直接访问基类的私有成员 若否 应如何实现 不能 可以在基类里添加一个公有成员函数来访问私有成员 派生类 就能继承这个公有成员函数 实现对基类私有成员的访问 4 3 保护成员有哪些特性 保护成员以公有方式或私有方式继承后的访问特性 如何 保护成员只能被本类或本类的派生类所访问 在类或派生类外是不能 被访问的 后面一问见第一题的答案 4 4 派生类构造函数和析构函数的执行顺序是怎样的 构造函数是先执行父类的构造函数 再执行类中其他类对象的构造函 数 再执行本类的构造函数 如果同级有多个构造函数 则按声明顺序执行 析构函数与构造函数的执行顺序刚好相反 4 5 派生类构造函数和析构函数的构造规则是怎样的 派生类名 参数总表 基类名 参数总表 派生类新增数据成员的初始化语句 派生类中的析构函数与基类无关 4 6 什么是多继承 多继承时 构造函数与析构函数的执行顺序是怎样的 多继承是指一个类同时继承自多个不同的基类 执行顺序同 4 4 4 7 在类的派生中为何要引入虚基类 虚基类构造函数的调用顺序是如何规定 的 如果一个类有多个直接基类 而这些直接基类又有一个共同的基类 则在最底层的派生类中会保留这个简介的共同基类数据成员的多份同名成员 在访问这些同名成员的时候 会产生二义性 为了解决二义性 引入了虚基类 1 如果虚基类中定义有带形参的构造函数 并且没有定义默认形式的 构造函数 则整个继承结构中 所有直接或间接的派生类都必须在构造函数的 成员初始化表中列出对虚基类构造函数的调用 以初始化在虚基类中定义的数 据成员 2 建立一个对象时 如果这个对象中含有从虚基类继承来的成员 则 虚基类的成员是由最远派生类的构造函数通过调用虚基类的构造函数进行初始 化的 该派生类的其他基类对虚基类构造函数的调用都自动被忽略 3 若同一层次中同时包含虚基类和非虚基类 应先调用虚基类的构造 函数 再调用非虚基类的构造函数 最后调用派生类的构造函数 4 8 4 11 ACCB 4 12 Constructor B1 Constructor B2 Constructor A 3 2 1 4 13 主食 bread 副食 steak 4 14 0 0 0 0 1 0 3 6 9 4 15 Constructor B1 Constructor B2 Constructor B3 Constructor A 1 2 4 3 4 16 4 4 17 1 2 5 6 6 9 4 18 class base1 class base2 class level2 class base2 class level1 class toplevel 4 19 include using namespace std include class table public table int p int q i p j q void ascii void protected int i j void table ascii int k 1 for i j i cout setw 4 i char i if k 12 0 cout n k cout n class der table public table public der table int p int q char m table p q c m void print protected char c void der table print cout c n table ascii int main der table ob a z ASCII value char ob print return 0 4 20 include using namespace std include class area c1 protected double height double width public area c1 double r double s height r width s virtual double area 0 class rectangle public area c1 public rectangle double r double s area c1 r s virtual double area double rectangle area return height width class isosceles public area c1 public isosceles double r double s area c1 r s virtual double area double isosceles area return height width 2 int main rectangle r 10 5 isosceles i 4 6 area c1 a a cout 矩形的面积是 area endl a cout 三角形的面积是 area endl return 0 4 21 include using namespace std include class Time public Time int h int m int s hours h minutes m seconds s void display cout 出生时间 hours 时 minutes 分 seconds 秒 endl protected int hours minutes seconds class Date public Date int m int d int y month m day d year y void display cout 出生年月 year 年 month 月 day 日 endl protected int month day year class Birthtime public Time public Date public Birthtime char name int m int d int y int h int mi int s Time h mi s Date m d y strcpy Childname name void showName cout 我的名字是 Childname endl private char Childname 25 int main Birthtime b xiaoming 3 6 2012 11 12 42 b showName b Time display b Date display return 0 4 22 include using namespace std include class person protected char number 25 char name 25 public person char num char na strcpy number num strcpy name na void showName cout 编号 number 姓名 name class student public person private int classNumber score public student char num char na int cNumber int sc person num na classNumber cNumber score sc void show showName cout 班号 classNumber 成绩 score endl class teacher public person private char title 25 department 25 public teacher char num char na char tit char depart person num na strcpy title tit strcpy department depart void show showName cout 职称 title 部门 department endl C 第五章习题 1 什么是静态联编 什么是动态联编 静态联编是指系统在编译时就决定如何实现某一动作 动态联编是指系统在运行时动态实现某一动作 1 编译时的多态性与运行时的多态性有什么区别 他们的实现方式有什么 不同 静态联编支持的多态性称为编译时多态性 也称静态多态性 编译时多态性是 通过函数重载和模板实现的 动态联编所支持的多态性称为运行时多态性 也称动态多态性 是通过虚函数 来实现的 1 简述运算符重载规则 a C 中绝大部分的运算符允许重载 b C 只能对已有的 C 运算符进行重载 c 运算符重载是针对新类型数据的实际需要 对原有运算符进行适当 的改造完成 应与原有的功能相类似 d 重载不能改变运算符的操作对象的个数 e 重载不能改变运算符原有的优先级 f 不能改变原有的结合特性 g 参数至少应有一个是类对象 h 重载函数可以是普通函数 也可以是类的成员函数 也可以是类的 友元函数 i 一般用于类对象的运算符除了赋值运算符都要重载 1 友元运算符函数和成员运算符函数有什么不同 a 对于双目运算符 成员运算符重载含有一个参数 友元重载含有两 个参数 对于单目运算符 成员重载没有参数 友元重载有一个参数 b 双目运算符一般可以被重载为友元或成员 但是如果将一个对象和 一个普通类型运算 必须重载为友元 c 调用方式不同 d 一般 双目运算符用友元 单目运算符用成员 如果操作数有隐式 类型转换 则必须用友元 1 什么是虚函数 虚函数与函数重载有哪些相同点与不同点 虚函数就是在基类中被关键字 virtual 说明 并在派生类中重新定义的函数 函数名都相同 重载函数的参数个数或参数类型必须有所不同 虚函数要求函数名 返回类型 参数个数 参数的类型和顺序与基类中的虚函数原型完全相同 1 什么是纯虚函数 什么是抽象类 纯虚函数是一个在基类中说明的虚函数 它在该基类中没有定义 但要求在它 的派生类中根据需要对它进行定义 或仍说明为纯虚函数 如果一个类至少有一个纯虚函数 那么就称这个类为抽象类 7 12 DAADCC 13 不对 参数个数必须一样 14 7 6 15 This is c book 第一个字符 T 第 16 个字符 第 26 个字符 数组下标超界 16 m 1 5 千米 17 include using namespace std class twoDArray int a 2 3 public twoDArray for int i 0 i 2 i for int j 0 j 3 j a i j 5 twoDArray int b 3 for int i 0 i 2 i for int j 0 j 3 j a i j b i j void show twoDArray operator twoDArray n twoDArray operator twoDArray n void twoDArray show for int i 0 i 2 i for int j 0 j 3 j cout a i j cout endl twoDArray twoDArray operator twoDArray n twoDArray temp for int i 0 i 2 i for int j 0 j 3 j temp a i j a i j n a i j return temp twoDArray twoDArray operator twoDArray n twoDArray temp for int i 0 i 2 i for int j 0 j 3 j temp a i j a i j n a i j return temp int main int a 2 3 for int i 0 i 2 i for int j 0 j a i j twoDArray a1 a2 a total sub total a1 a2 sub a1 a2 total show sub show return 0 18 include using namespace std class twoDArray int a 2 3 public twoDArray for int i 0 i 2 i for int j 0 j 3 j a i j 5 twoDArray int b 3 for int i 0 i 2 i for int j 0 j 3 j a i j b i j void show friend twoDArray operator twoDArray m twoDArray n friend twoDArray operator twoDArray m twoDArray n void twoDArray show for int i 0 i 2 i for int j 0 j 3 j cout a i j cout endl twoDArray operator twoDArray m twoDArray n twoDArray temp for int i 0 i 2 i for int j 0 j 3 j temp a i j m a i j n a i j return temp twoDArray operator twoDArray m twoDArray n twoDArray temp for int i 0 i 2 i for int j 0 j 3 j temp a i j m a i j n a i j return temp int main int a 2 3 for int i 0 i 2 i for int j 0 j a i j twoDArray a1 a2 a total sub total a1 a2 sub a1 a2 total show sub show return 0 19 include using namespace std class complex double real imag public complex double re double im real re imag im friend complex operator complex a complex b void print complex operator complex a complex b return complex a real b real a imag b imag void complex print cout real imag endl int main complex c1 2 5 3 7 complex c2 4 2 6 5 complex total c1 c2 total print return 0 20 include using namespace std const double PI 3 14 class Container protected double r d 如果是球形 r 是半径 d 为 0 如果是圆柱体 r 为底 面半径 d 为高 如果是正方体 r 为边长 d 为 0 public Container double a double b 0 r a d b virtual double serface 0 计算表面积 virtual double volume 0 计算体积 class Sphere public Container public Sphere double r Container r double serface double volume double Sphere serface return 4 PI r r double Sphere volume return PI r r r class Cylinder public Container public Cylinder double a double b Container a b double serface double volume double Cylinder serface return 2 PI r d PI r r double Cylinder volume return PI r r d class Cube public Container public Cube double a Container a double serface double volume double Cube serface return 6 r r double Cube volume return r r r 7 1 C 为什么要有自己的输入输出系统 C 的编译系统对数据类型进行严格的检查 凡是类型不正确的数据 都不可能通过编译 C 中需要定义众多的用户自定义类型且能够输入输出 7 2 C 有哪 4 个预定义的流对象 他们分别与什么具体设备相关联 标准输入流对象 cin 标准输出流对象 cout 非缓冲型的标准出错流 对象 cerr 和缓冲型的标准出错流对象 clog cin 对应标准输入设备 cout 对应标准输出设备 cerr 对应标准错误输出设备 clog 对应标准错误输出设备 7 3 cerr 和 clog 间的区别是 cerr 不经过缓冲区直接显示错误信息 而 clog 存放在缓冲区 缓冲 区满或遇上 endl 时再输出 7 4 C 提供哪两种控制输入输出格式的方法 一种是使用 ios 类中的有关格式控制的流成员函数进行格式控制 另 一种是使用称为操纵符的特殊类型的函数控制 7 5 C 进行文件输入输出的基本过程是什么 首先创建一个流对象 然后将这个流对象与文件相关联 即打开文件 此时才能进行读写操作 读写操作完成后再关闭这个文件 7 6 7 8 BCA 7 9 include include using namespace std int factorial int n if n 0 n 1 return n return factorial n 1 n int main for int i 1 i 9 i cout setw 5 factorial i if i 3 0 cout endl return 0 7 10 include include using namespace std int main for int i 1 i 7 i cout setw 16 i for int j 1 j 2 i 1 j cout A cout endl return 0 7 11 include include using namespace std class matrix private int data 2 3 public matrix friend ostream friend matrix operator matrix ostream i 2 i for int j 0 j 3 j os a data i j os istream for int i 0 i 2 i for int j 0 j a data i j return in matrix operator matrix for int i 0 i 2 i for int j 0 j m1 m2 total m1 m2 cout total return 0 7 12 include include using namespace std int main fstream fout stock txt ios out if fout cout 文件打开失败 endl return 1 fout Shen fa zhan 000001 n fout shang hai qi che 600104 n fout Guang ju neng yuan 000096 fout close return 0 7 13 include include using namespace std int main char str 30 fstream in file1 txt ios in if in cout str str for int i 0 i 30 i if str i 0 fstream out file2 txt ios out if out cout str in close out close return 0 7 14 include include using namespace std int main char str 30 fstream in file1 txt ios in if in cout str str for int i 0 i 30 i if str i 0 fstream out file2 txt ios app if out cout str in close out close return 0 7 15 不会 include include buy h include book h using namespace std class order private int orderID int buyerID int listcount string orderlist 20 static int ordercount public order buyer orderID ordercount buyerID person buyerID listcount bookNumber for int i 0 i bookNumber i orderlist i b i book ID void show cout 订单编号 orderID n 购书人编号 buyerID n 购书数量 listcount endl for int i 0 i listcount i cout 书号 orderlist i endl int order ordercount 0 int main book c 20 book c1 7 302 0145214 6 C 程序设计 谭浩强 清华 25 book c2 7 302 0145214 7 C 程序设计 谭浩强 清华 28 c 1 c 2 layfolk b1 林晓茶 1 北京 0 order ord b1 c 2 order show return 0
展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 解决方案


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!