题目内容
请使用VC6或使用[答题]菜单打开考生文件夹proj2下的工程proj2。此工程中包含一个源程序文件main.cpp,其中有“书”类Book及其派生出的“教材”类TeachingMaterial的定义,还有主函数main的定义。请在横线处填写适当的代码并删除横线,以实现上述类定义和函数定义。该程序的正确输出结果应为: 教材名:C++语言程序设计 页数:299 作者:张三 相关课程:面向对象的程序设计 注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。 #include <iostream> using namespace std; class Book{ //"书"类 char * title; //书 int num_pages; //页数 char * writer; //作者姓名 public: //********** found********** Book(const char * the title, int pages, const char * the writer): ______{ title =new char[ strlen (the_titie) +1]; strcpy(title,the_title); //********** found********** ______ strcpy(writer,the_writer); } ~Book(){ delete []title; delete []writer; } int numOfPages()const{ return numpages;} //返回书的页数 const char * theTitle () const { return title; } //返回书名 const char * theWriter () const{ return writer; } //返回作者名 }; class TeachingMaterial: public Book{ //“教材”类 char * course; public: TeachingMaterial (const char * the_title, int pages, const char * the_writer, const char * the_course) //********** found********** :______{ course = new char [ strlen (the_course) +i]; strcpy (course, the_course); } ~TeachingMaterial () { delete [ ]course; } const char * theCourse () const{ return course; } //返回相关课程的名称 }; int main () { TeachingMaterial abook ("C++语言程序设计", 299, "张三", "面向对象的程序设计"); cout <<"教材名:" << a book.theTitle() <<endl << "页数:" << a_book.numOfPages ()<< endl <<"作者:" <<a book.theWriter ()<< endl //********** found********** << "相关课程:" <<______; cout << endl; return 0; }
查看答案
搜索结果不匹配?点我反馈
更多问题