大学C++期末考试试卷(含答案)_第1页
大学C++期末考试试卷(含答案)_第2页
大学C++期末考试试卷(含答案)_第3页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、C+突击题C+突击题2012-06-08- CBook(分)include #include math.h #inlcude stringclass CBookprivate:char *p_book; public:p_book=new charstrlen(p_val)+1 CBook(const char p_book = new strcpy(p_book, p_val);void print() const cout p_book p;CBook abook(; p_book_obj = 10)include iostream.hclass CJournal public:CJour

2、nal() cout“Journal default constructor”endl; virtual void subscribe() = 0;void read() cout “Read paper” endl; CJournal() coutJournal default destructor” endl;class CComputerDesign : public CJournal public:CComputerDesign) coutComputerDesigndefaultconstructor”endl; virtual void subscribe() cout“Subsc

3、ribing Computer endl; void read() cout “ReadingComputer endl; CComputerDesign() cout “Computer Designdefault destructor” rea(;1。当程序运行到处时,写出程序运行的输出结果 (3 分)2。 当程序结束时,程序会在第 1 问的基础上增加哪些输出. (4 分)3。 若在主函数中定义一个对象 CJournal journal;程序编译时会否出错?为什么?(3 分)四、编程题(40)定义一个商品类 CGoods,其中包含商品号(long no)、商品名(char p_name、商

4、品价格(doubleprice)(10include iostream#include string.husing namespace std; class CCourse private:long no;char float credit; public:CCourse(long no_val,char p_val,float CCourse(const CCourse &r_course;CCourse()delete p_name; void print() const;;CCourse:CCourse(long no_val,char p_val,float no=no_val;p_n

5、ame=new charstrlen(p_val)+1; strcpy(p_name,p_val); credit=credit_val;CCourse:CCourse(const CCourse no=r_course。no;p_name=new charstrlen(r_course.p_name)+1; strcpy(p_name,r_course 。 p_name); credit=r_course.credit;void CCourse:print() constcout”Course number”noendl; cout”Course name”p_nameendl; cout”

6、Course credit”credit2。 为 CGoods 类增加一个商品总数( int count)获取count获取商品名称p_name.CGoods1(103。 为 CGoods 类定义小于运算符()和不小于运算符(=)两个运算符重载函数.CGoods的值的大小来实现的(2)(10)4CGoodsCClothesCFood(char 数(void usedFor()可分别输出一条表示服装和食品用途的信息).写出 CFoodusedFor()成员函数的实现).(10)3075)1CGoods(long total_goods)和商品总价格total_price)getTotalGood

7、s()getTotalPrice(。(注意说明数据成员和成员函数的存储类型,getTotalGoods()getTotalPrice()这两个函数).为了能够采用动态联编的方式调用派生类的 usedFor()成员函数,应该在 CGoods 类及其派生类CClothesCFood(15)swap,个数组元素(通用类型)的数组采用冒泡排序算法进行排序的函数模板.(15)答案二、include math。h 改为#include ReadingComputer (312。 SubscribingComputer Reading paperComputer default destructor Jou

8、rnal default destructor(全部答对得 4 分,答错或漏答一条输出扣 1 分)会出错,因为CJournalCJournal(12四、1。 include iostreaminclude string。husing namespace std; class CCourse private:long char float credit;public:C+突击题C+突击题2012-06-08- CCourse(long no_val, char *p_val, float CCourse(const CCourse r_cours;CCourse() delete p_name;

9、 void print() const;CCourse::CCourse(long no_val, char *p_val, float credit_val) no = no_val;p_name = new strcpy(p_name, p_val);credit = credit_val;CCoursCCoursconst CCourse no = r_course.no;p_name = new chastrle(r_cours strcpy(p_name, r_course。p_name);credit = r_course.credit;void CCourse::print()

10、constcoutCourse numbernoendl; cout”Course p_nameendl; cout”Course credit = r_course。credit)return true;elsereturn false;(答对得 3 分)4。class CHLP : public CCourse private:char *p_openby; public:CHLP(longno_val,char p_va,floatcredit_va,char*p_ope):CCours(no_val,p_val, credit_val)p_openby = new charstrlen

11、(p_open)+1; strcpy(p_openby, p_open);CHLP() delete p_openby; void studyFor() cout ”Study for structured programming” endl; ;(531,studyFor(1class COOP : public private:char p_openby; public:COOP(longno_val,charp_va,floatcredit_val,char p_ope): p_val, credit_vap_openby = new strcpy(p_openby, p_open);C

12、OOP() delete p_openby; void studyFor() cout ”Study for object orientedprogramming” endl; ;(答对得 5 分,其中构造函数 3 分,析构函数 1 分,studyFor()函数 1 分)五、1。 在 class CCourse 定义中增加一条: public:virtual void cout choice;cout studyFor(); delete p_course;(答对得 13 分)2.#include iostream using namespace std; template class Tvoid swap(T a, T &b)T temp; temp = a; a = b;b = temp;template class Tvoid bubbleSort(T a, int int i, j;for (i=1; i n; i+) for (j=0; j ni; if ( aj+1) swaa, aj+1;template class T1vo

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论