当前位置:首页 » 招生排名 » c大学基础教程答案

c大学基础教程答案

发布时间: 2022-02-27 00:12:55

『壹』 求《C 大学教程》/《C how to program》第6版deitel著 课后练习答案

第五版 课后答案 (H.M.Deitel)

http://www.daanwang.com/download/90970-.html
http://www.daanwang.com/download/90970-.html
要求注册登陆

『贰』 求《C++大学基础教程》 第五版 deitel 著 电子工业出版社 课后答案 是基础教程!!!

C 大学基础教程 课后答案DEITEL版 3.11 GradeBook类定义 include ltstringgt // program uses C standard string class using std::string class GradeBook public: // constructor initializes course name and instructor name GradeBook string string void setCourseName string // function to set the course name string getCourseName // function to retrieve the course name void setInstructorName string // function to set instructor name string getInstructorName // function to retrieve instructor name void displayMessage // display welcome message and instructor name private: string courseName // course name for this GradeBook string instructorName // instructor name for this GradeBook // end class GradeBook 类成员函数 include ltiostreamgt using std::cout using std::endl include quotGradeBook.hquot // constructor initializes courseName and instructorName // with strings supplied as arguments GradeBook::GradeBook string course string instructor setCourseName course // initializes courseName setInstructorName instructor // initialiZes instructorName // end GradeBook constructor // function to set the course name void GradeBook::setCourseName string name courseName name // store the course name // end function setCourseName // function to retrieve the course name string GradeBook::getCourseName return courseName // end function getCourseName // function to set the instructor name void GradeBook::setInstructorName string name instructorName name // store the instructor name // end function setInstructorName // function to retrieve the instructor name string GradeBook::getInstructorName return instructorName // end function getInstructorName // display a welcome message and the instructors name void GradeBook::displayMessage // display a welcome message containing the course name cout ltlt quotWelcome to the grade book fornquot ltlt getCourseName ltlt quotquot ltlt endl // display the instructors name cout ltlt quotThis course is presented by: quot ltlt getInstructorName ltlt endl // end function displayMessage 测试文件 include ltiostreamgt using std::cout using std::endl // include definition of class GradeBook from GradeBook.h include quotGradeBook.hquot // function main begins program execution int main // create a GradeBook object pass a course name and instructor name GradeBook gradeBook quotCS101 Introction to C Programmingquot quotProfessor Smithquot // display initial value of instructorName of GradeBook object cout ltlt quotgradeBook instructor name is: quot ltlt gradeBook.getInstructorName ltlt quotnnquot // modify the instructorName using set function gradeBook.setInstructorName quotAssistant Professor Batesquot // display new value of instructorName cout ltlt quotnew gradeBook instructor name is: quot ltlt gradeBook.getInstructorName ltlt quotnnquot // display welcome message and instructors name gradeBook.displayMessage return 0 // indicate successful termination // end main 3.12 类定义 class Account public: Account int // constructor initializes balance void credit int // add an amount to the account balance void debit int // subtract an amount from the account balance int getBalance // return the account balance private: int balance // data member that stores the balance // end class Account 类成员函数 include ltiostreamgt using std::cout using std::endl include quotAccount.hquot // include definition of class Account // Account constructor initializes data member balance Account::Account int initialBalance balance 0 // assume that the balance begins at 0 // if initialBalance is greater than 0 set this value as the // balance of the Account otherwise balance remains 0 if initialBalance gt 0 balance initialBalance // if initialBalance is negative print error message if initialBalance lt 0 cout ltlt quotError: Initial balance cannot be negative.nquot ltlt endl // end Account constructor // credit add an amount to the account balance void Account::credit int amount balance balance amount // add amount to balance // end function credit // debit subtract an amount from the account balance void Account::debit int amount if amount gt balance // debit amount exceeds balance cout ltlt quotDebit amount exceeded account balance.nquot ltlt endl if amount lt balance // debit amount does not exceed balance balance balance - amount // end function debit // return the account balance int Account::getBalance return balance // gives the value of balance to the calling function // end function getBalance 测试函数 include ltiostreamgt using std::cout using std::cin using std::endl // include definition of class Account from Account.h include quotAccount.hquot // function main begins program execution int main Account account1 50 // create Account object Account account2 25 // create Account object // display initial balance of each object cout ltlt quotaccount1 balance: quot ltlt account1.getBalance ltlt endl cout ltlt quotaccount2 balance: quot ltlt account2.getBalance ltlt endl int withdrawalAmount // stores withdrawal amount read from user cout ltlt quotnEnter withdrawal amount for account1: quot // prompt cin gtgt withdrawalAmount // obtain user input cout ltlt quotnattempting to subtract quot ltlt withdrawalAmount ltlt quot from account1 balancennquot account1.debit withdrawalAmount // try to subtract from account1 // display balances cout ltlt quotaccount1 balance: quot ltlt account1.getBalance ltlt endl cout ltlt quotaccount2 balance: quot ltlt account2.getBalance ltlt endl cout ltlt quotnEnter withdrawal amount for account2: quot // prompt cin gtgt withdrawalAmount // obtain user input cout ltlt quotnattempting to subtract quot ltlt withdrawalAmount ltlt quot from account2 balancennquot account2.debit withdrawalAmount // try to subtract from account2 // display balances cout ltlt quotaccount1 balance: quot ltlt account1.getBalance ltlt endl cout ltlt quotaccount2 balance: quot ltlt account2.getBalance ltlt endl return 0 // indicate successful termination // end main 3.13 类定义 include ltstringgt // program uses C standard string class using std::string // Invoice class definition class Invoice public: // constructor initializes the four data members Invoice string string int int // set and get functions for the four data members void setPartNumber string // part number string getPartNumber void setPartDescription string // part description string getPartDescription void setQuantity int // quantity int getQuantity void setPricePerItem int // price per item int getPricePerItem // calculates invoice amount by multiplying quantity x price per item int getInvoiceAmount private: string partNumber // the number of the part being sold string partDescription // description of the part being sold int quantity // how many of the items are being sold int pricePerItem // price per item // end class Invoice 类成员函数 include ltiostreamgt using std::cout using std::endl // include definition of class Invoice from Invoice.h include quotInvoice.hquot // Invoice constructor initializes the classs four data members Invoice::Invoice string number string description int count int price setPartNumber number // store partNumber setPartDescription description // store partDescription setQuantity count // validate and store quantity setPricePerItem price // validate and store pricePerItem // end Invoice constructor // set part number void Invoice::setPartNumber string number partNumber number // no validation needed // end function setPartNumber // get part number string Invoice::getPartNumber return partNumber // end function getPartNumber // set part description void Invoice::setPartDescription string description partDescription description // no validation needed // end function setPartDescription // get part description string Invoice::getPartDescription return partDescription // end function getPartDescription // set quantity if not positive set to 0 void Invoice::setQuantity int count if count gt 0 // if quantity is positive quantity count // set quantity to count if count lt 0 // if quantity is not positive quantity 0 // set quantity to 0 cout ltlt quotnquantity cannot be negative. quantity set to 0.nquot // end if // end function setQuantity // get quantity int Invoice::getQuantity return quantity // end function getQuantity // set price per item if not positive set to 0 void Invoice::setPricePerItem int price if price gt 0 // if price is positive pricePerItem price // set pricePerItem to price if price lt 0 // if price is not positive pricePerItem 0 // set pricePerItem to 0 cout ltlt quotnpricePerItem cannot be negative. quot ltlt quotpricePerItem set to 0.nquot // end if // end function setPricePerItem // get price per item int Invoice::getPricePerItem return pricePerItem // end function getPricePerItem // calulates invoice amount by multiplying quantity x price per item int Invoice::getInvoiceAmount return getQuantity getPricePerItem // end function getInvoiceAmount 测试函数 include ltiostreamgt using std::cout using std::cin using std::endl // include definition of class Invoice from Invoice.h include quotInvoice.hquot // function main begins program execution int main // create an Invoice object Invoice invoice quot12345quot quotHammerquot 100 5 // display the invoice data members and calculate the amount cout ltlt quotPart number: quot ltlt invoice.getPartNumber ltlt endl cout ltlt quotPart description: quot ltlt invoice.getPartDescription ltlt endl cout ltlt quotQuantity: quot ltlt invoice.getQuantity ltlt endl cout ltlt quotPrice per item: quot ltlt invoice.getPricePerItem ltlt endl cout ltlt quotInvoice amount: quot ltlt invoice.getInvoiceAmount ltlt endl // modify the invoice data members invoice.setPartNumber quot123456quot invoice.setPartDescription quotSawquot invoice.setQuantity -5 //negative quantityso quantity set to 0 invoice.setPricePerItem 10 cout ltlt quotnInvoice data members modified.nnquot // display the modified invoice data members and calculate new amount cout ltlt quotPart number: quot ltlt invoice.getPartNumber ltlt endl cout ltlt quotPart description: quot ltlt invoice.getPartDescription ltlt endl cout ltlt quotQuantity: quot ltlt invoice.getQuantity ltlt endl cout ltlt quotPrice per item: quot ltlt invoice.getPricePerItem ltlt endl cout ltlt quotInvoice amount: quot ltlt invoice.getInvoiceAmount ltlt endl return 0 // indicate successful termination // end main 3.14 类定义 include ltstringgt // program uses C standard string class using std::string // Employee class definition class Employee public: Employee string string int // constructor sets data members void setFirstName string // set first name string getFirstName // return first name void setLastName string // set last name string getLastName // return last name void setMonthlySalary int // set weekly salary int getMonthlySalary // return weekly salary private: string firstName // Employees first name string lastName // Employees last name int monthlySalary // Employees salary per month // end class Employee 类成员函数 include ltiostreamgt using std::cout include quotEmployee.hquot // Employee class definition // Employee constructor initializes the three data members Employee::Employee string first string last int salary setFirstName first // store first name setLastName last // store last name setMonthlySalary salary // validate and store monthly salary // end Employee constructor // set first name void Employee::setFirstName string name firstName name // no validation needed // end function setFirstName // return first name string Employee::getFirstName return firstName // end function getFirstName // set last name void Employee::setLastName string name lastName name // no validation needed // end function setLastName // return last name string Employee::getLastName return lastName // end function getLastName // set monthly salary if not positive set to 0.0 void Employee::setMonthlySalary int salary if salary gt 0 // if salary is positive monthlySalary salary // set monthlySalary to salary if salary lt 0 // if salary is not positive monthlySalary 0 // set monthlySalary to 0.0 // end function setMonthlySalary // return monthly salary int Employee::getMonthlySalary return monthlySalary // end function getMonthlySalary 测试函数 include ltiostreamgt using std::cout using std::endl include quotEmployee.hquot // include definition of class Employee // function main begins program execution int main // create two Employee objects Employee employee1 quotLisaquot quotRobertsquot 4500 Employee employee2 quotMarkquot quotSteinquot 4000 // display each Employees yearly salary cout ltlt quotEmployees yearly salaries: quot ltlt endl // retrieve and display employee1s monthly salary multiplied by 12 int monthlySalary1 employee1.getMonthlySalary cout ltlt employee1.getFirstName ltlt quot quot ltlt employee1.getLastName ltlt quot: quot ltlt monthlySalary1 12 ltlt endl // retrieve and display employee2s monthly salary multiplied by 12 int monthlySalary2 employee2.getMonthlySalary cout ltlt employee2.getFirstName ltlt quot quot ltlt employee2.getLastName ltlt quot: quot ltlt monthlySalary2 12 ltlt endl // give each Employee a 10 raise employee1.setMonthlySalary monthlySalary1 1.1 employee2.setMonthlySalary monthlySalary2 1.1 // display each Employees yearly salary again cout ltlt quotnEmployees yearly salaries after 10 raise: quot ltlt endl // retrieve and display employee1s monthly salary multiplied by 12 monthlySalary1 employee1.getMonthlySalary cout ltlt employee1.getFirstName ltlt quot quot ltlt employee1.getLastName ltlt quot: quot ltlt monthlySalary1 12 ltlt endl monthlySalary2 employee2.getMonthlySalary cout ltlt employee2.getFirstName ltlt quot quot ltlt employee2.getLastName ltlt quot: quot ltlt monthlySalary2 12 ltlt endl return 0 // indicate successful termination // end main 3.15 类定义 class Date public: Date int int int // constructor initializes data members void setMonth int // set month int getMonth // return month void setDay int // set day int getDay // return day void setYear int // set year int getYear // return year void displayDate // displays date in mm/dd/yyyy format private: int month // the month of the date int day // the day of the date int year // the year of the date // end class Date 类成员函数 include ltiostreamgt using std::cout using std::endl include quotDate.hquot // include definition of class Date from Date.h // Date constructor that initializes the three data members // assume values provided are correct really should validate Date::Date int m int d int y setMonth m setDay d setYear y // end Date constructor // set month void Date::setMonth int m month m if month lt 1 month 1 if month gt 12 month 1 // end function setMonth // return month int Date::getMonth return month // end function getMonth // set day void Date::setDay int d day d // end function setDay // return day int Date::getDay return day // end function getDay // set year void Date::setYear int y year y // end function setYear // return year int Date::getYear return year // end function getYear // print Date in the format mm/dd/yyyy void Date::displayDate cout ltlt month ltlt / ltlt day ltlt / ltlt year ltlt endl // end function displayDate 测试函数 include ltiostreamgt using std::cout using std::endl include quotDate.hquot // include definition of class Date.

『叁』 求练习题答案,戴特尔著 c语言大学教程 第六版

哎,我也是跟楼主同求,买了这本书,其他都好,就是没答案……

『肆』 标准C语言基础教程(第四版)答案,,,,,急求,,,,

网络搜索一下。

『伍』 c语言基础教程(c99版)

C语言基础教程别看了,学习C语言不能脱离具体的系统,不能不了解计算机体系结构和操作系统原理、编译原理,推荐你看这本开源的书:
《Linux C编程一站式学习》

如果是在Windows上学习,可以安装cygwin来模拟linux环境,下载地址:

下面贴一下这本书的介绍,磨刀不误砍柴工,看过之后你就会爱上这本书了:

这本书有什么特点?面向什么样的读者?

这本书最初是为北京亚嵌教育研究中心的嵌入式Linux系统工程师就业班课程量身定做的教材之一。该课程是为期四个月的全日制职业培训,要求学员毕业时具备非常Solid的C编程能力,能熟练地使用Linux系统,同时对计算机体系结构与指令集、操作系统原理和设备驱动程序都有较深入的了解。然而学员入学时的水平是非常初级而且参差不齐的:学历有专科、本科也有研究生,专业有和计算机相关的也有很不相关的(例如会计专业),以前从事的职业有和技术相关的也有完全不相关的(例如HR),年龄从二十出头到三十五六岁的都有。这么多背景完全不同、基础完全不同、思维习惯和理解能力完全不同的人来听同一堂课,大家都迫切希望学会嵌入式开发技术,投身IT行业,这就是职业教育的特点,也是我编这本书时需要考虑的主要问题。

学习编程绝不是一件简单的事,尤其是对于零基础的初学者来说。大学的计算机专业有四年时间从零基础开始培养一个人,微积分、线代、随机、离散、组合、自动机、编译原理、操作系统、计算机组成原理等等一堆基础课,再加上C/C++、Java、数据库、网络、软件工程、计算机图形学等等一堆专业课,最后培养出一个能找到工作的学生。很遗憾这最后一条很多学校没有做好,来亚嵌培训的很多学生就是四年这么学过来的,但据我们考查他们的基础几乎为零,我不知道为什么。与之形成鲜明对比的是,只给我们四个月的时间,同样要求从零基础开始,最后培养出一个能找到工作的学生,而且还要保证他找到工作,这就是职业教育的特点。

为什么我说“只给我们四个月的时间”?我们倒是想教四年呢,但学时的长短我们做不了主,是由市场规律决定的。四年的任务要求四个月做好,要怎么完成这样一个几乎不可能的任务?有些职业教育给出的答案是“实用主义”,打出了“有用就学,没有用就不学”的口号,大肆贬低说大学里教的基础课都是过时的、无用的,只有他们教的技术才是实用的,这种炒作很不好,我认为大学里教的每一门课都是非常有用的,基础知识在任何时候都不会过时,倒是那些时髦的“实用技术”有可能很快就过时了。

四年的任务怎么才能用四个月做好?我们给出的答案是“优化”。现在大学里安排的课程体系最大的缺点就是根本不考虑优化。每个过来人都会有这样的感觉:大一大二学了好多数学课,却不知道都是干什么用的,为什么要学。连它有什么用都不知道怎么能有兴趣学好呢?然后到大三大四学专业课时,用到以前的知识了,才发现以前学的数学是多么有用,然而早就忘得一干二净了,考完试都还给老师了,回头重新学吧,这时候才发现很多东西以前根本没学明白,现在才真的学明白了,那么前两年的时间岂不是都浪费了?大学里的课程体系还有一个缺点就是不灵活,每门课必须占一个学期,必须由一个老师教,不同课程的老师之间没有任何沟通和衔接,其实这些课程之间是相互依赖的,把它们强行拆开是不符合人的认知规律的。比如我刚上大学的时候,大一上半学期就被逼着学C语言,其实C语言是一门很难的编程语言,不懂编译原理、操作系统和计算机体系结构根本不可能学明白,那半个学期自然就浪费掉了。当时几乎所有学校的计算机相关专业都是这样,大一上来就学C语言,有的学校更疯狂,上来就学C++,导致大多数学生都以为自己会C语言,但其实都是半吊子水平,到真正写代码的时候经常为一个Bug搞得焦头烂额,却没有机会再系统地学一遍C语言,因为在学校看来,C语言课早在大一就给你“上完了”,就像一顿饭已经吃完了,不管你吃饱没吃饱,不会再让你重吃一遍了。显而易见,如果要认真地对这些课程做优化,的确是有很多水份可以挤的。

本书有以下特点:

*

不是孤立地讲C语言,而是和编译原理、操作系统、计算机体系结构结合起来讲。或者说,本书的内容只是以C语言为载体,真正讲的是计算机的原理和程序的原理。
*

强调基本概念和基本原理,在编排顺序上非常重视概念之间的依赖关系,每次引入一个新的概念,只依赖于前面章节已经讲过的概念,而绝不会依赖后面章节要讲的概念。有些地方为了叙述得完整,也会引用后面要讲的内容,比如说“有关XX我们到XX章再仔细讲解”,凡是这种引用都不是必要的依赖,可以当它不存在,只管继续往下看就行了。
*

尽量做到每个知识点直到要用的时候才引入。过早引入一个知识点,讲完了又不用它,读者很快就会遗忘,这是不符合认知规律的。

这是一本从零基础开始学习编程的书,不要求读者有任何编程经验,但读者至少需要具备以下素质:

*

熟悉Linux系统的基本操作。如果不具备这一点,请先参考其它教材学习Linux系统的基本操作,熟练之后再学习本书,《鸟哥的Linux私房菜》据说是 Linux系统管理和应用方面比较好的一本书。但学习本书并不需要会很多系统管理技术,只要会用基本命令,会自己安装系统和软件包就足够了。
*

具有高中毕业的数学水平。本书会用到高中的数学知识,事实上,如果不具有高中毕业的数学水平,也不必考虑做程序员了。但并不是说只要具有高中毕业的数学水平就足够做程序员了,只能说看这本书应该没有问题,数学是程序员最重要的修养,计算机科学其实就是数学的一个分支,如果你的数学功底很差,日后还需恶补一下。
*

具有高中毕业的英文水平。理由同上。
*

对计算机的原理和本质深感兴趣,不是为就业而学习,不是为拿高薪而学习,而是真的感兴趣,想把一切来龙去脉搞得清清楚楚而学习。
*

勤于思考。本书尽最大努力理清概念之间的依赖关系,力求一站式学习,读者不需要为了找一个概念的定义去翻其它书,也不需要为了搞清楚一个概念在本书中前后一通乱翻,只需从前到后按顺序学习即可。但一站式学习并不等于傻瓜式学习,有些章节有一定的难度,需要积极思考才能领会。本书可以替你节省时间,但不能替你思考,不要指望像看小说一样走马观花看一遍就能学会。

又是一本C语言书。好吧,为什么我要学这本书而不是谭浩强或者K&R? 请点评

谭浩强的书我就不说什么了。居然教学生include一个.c文件。

K&R 是公认的世界上最经典的C语言教程,这点毫无疑问。在C标准出台之前,K&R第一版就是事实上的C标准。C89标准出台之后,K&R跟着标准推出了第二版,可惜此后就没有更新过了,所以不能反映C89之后C语言的发展以及最新的C99标准,本书在这方面做了很多补充。上面我说过了,这本书与其说是讲C语言,不如说是以C语言为载体讲计算机和操作系统的原理,而K&R就是为了讲C语言而讲C语言,侧重点不同,内容编排也很不相同。 K&R写得非常好,代码和语言都非常简洁,但很可惜,只有会C语言的人才懂得欣赏它,K&R是非常不适合入门学习的,尤其不适合零基础的学生入门学习。
这本书“是什么”和“不是什么” 请点评

本书包括三大部分:

*

C语言入门。介绍基本的C语法,帮助没有任何编程经验的读者理解什么是程序,怎么写程序,培养程序员的思维习惯,找到编程的感觉。前半部分改编自[ThinkCpp]。
*

C语言本质。结合计算机和操作系统的原理讲解C程序是怎么编译、链接、运行的,同时全面介绍C的语法。位运算的章节改编自亚嵌教育林小竹老师的讲义,链表和二叉树的章节改编自亚嵌教育朱老师的讲义。汇编语言的章节改编自[GroudUp],在该书的最后一章提到,学习编程有两种Approach,一种是Bottom Up,一种是Top Down,各有优缺点,需要两者结合起来。所以我编这本书的思路是,第一部分Top Down,第二部分Bottom Up,第三部分可以算填了中间的空隙,三部分全都围绕C语言展开。
*

Linux系统编程。介绍各种Linux系统函数和内核的工作原理。Socket编程的章节改编自亚嵌教育卫剑钒老师的讲义。

这本书定位在入门级,虽然内容很多,但不是一本网络全书,除了C语言基本要讲透之外其它内容都不深入,书中列出了很多参考资料,是读者进一步学习的起点。 K&R的第一章是一个Whirlwind Tour,把全书的内容简单过了一遍,然后再逐个深入进去讲解。本书也可以看作是计算机专业课程体系的一个Whirlwind Tour,学习完本书之后有了一个全局观,再去学习那些参考资料就应该很容易上手了。
为什么要在Linux平台上学C语言?用Windows学C语言不好吗? 请点评

用 Windows还真的是学不好C语言。C语言是一种面向底层的编程语言,要写好C程序,必须对操作系统的工作原理非常清楚,因为操作系统也是用C写的,我们用C写应用程序直接使用操作系统提供的接口。既然你选择了看这本书,你一定了解:Linux是一种开源的操作系统,你有任何疑问都可以从源代码和文档中找到答案,即使你看不懂源代码,也找不到文档,也很容易找个高手教你,各种邮件列表、新闻组和论坛上从来都不缺乐于助人的高手;而Windows是一种封闭的操作系统,除了微软的员工别人都看不到它的源代码,只能通过文档去猜测它的工作原理,更糟糕的是,微软向来喜欢藏着揶着,好用的功能留着自己用,而不会写到文档里公开。本书的第一部分在Linux或Windows平台上学习都可以,但第二部分和第三部分介绍了很多Linux操作系统的原理以帮助读者更深入地理解C语言,只能在Linux平台上学习。

Windows平台上的开发工具往往和各种集成开发环境(IDE,Integrated Development Environment)绑在一起,例如Visual Studio、Eclipse等。使用IDE确实很便捷,但IDE对于初学者绝对不是好东西。微软喜欢宣扬傻瓜式编程的理念,告诉你用鼠标拖几个控件,然后点一个按钮就可以编译出程序来,但是真正有用的程序有哪个是这么拖出来的?很多从Windows平台入门学编程的人,编了好几年程序,还是只知道编完程序点一个按钮就可以跑了,把几个源文件拖到一个项目里就可以编译到一起了,如果有更复杂的需求他们就傻眼了,因为他们脑子里只有按钮、菜单的概念,根本没有编译器、链接器、Makefile的概念,甚至连命令行都没用过,然而这些都是初学编程就应该建立起来的基本概念。另一方面,编译器、链接器和C语言的语法有密切的关系,不了解编译器、链接器的工作原理,也不可能真正掌握C的语法。所以,IDE并没有帮助你学习,而是阻碍了你学习,本来要学好C编程只要把语法和编译命令学会就行了,现在有了IDE,除了学会语法和编译命令,你还得弄清楚编译命令和IDE是怎么集成的,这才算学明白了,本来就很复杂的学习任务被IDE搞得更加复杂了。Linux用户的使用习惯从来都是以敲命令为主,以鼠标操作为辅,从学编程的第一天起就要敲命令编译程序,等到你把这些基本概念都搞清楚了,你觉得哪个IDE好用你再去用,不过到那时候你可能会更喜欢vi或emacs而不是IDE了。

『陆』 c++程序设计基础教程课后答案(清华大学出版社郑莉 董渊著)

第 一 章 概述

1-1 简述计算机程序设计语言的发展历程。

解:
迄今为止计算机程序设计语言的发展经历了机器语言、汇编语言、高级语言等阶段,C++语言是一种面向对象的编程语言,也属于高级语言。

1-2 面向对象的编程语言有哪些特点?

解:
面向对象的编程语言与以往各种编程语言有根本的不同,它设计的出发点就是为了能更直接的描述客观世界中存在的事物以及它们之间的关系。面向对象的编程语言将客观事物看作具有属性和行为的对象,通过抽象找出同一类对象的共同属性(静态特征)和行为(动态特征),形成类。通过类的继承与多态可以很方便地实现代码重用,大大缩短了软件开发周期,并使得软件风格统一。因此,面向对象的编程语言使程序能够比较直接地反问题域的本来面目,软件开发人员能够利用人类认识事物所采用的一般思维方法来进行软件开发。C++语言是目前应用最广的面向对象的编程语言。

1-3 什么是结构化程序设计方法?这种方法有哪些优点和缺点?

解:
结构化程序设计的思路是:自顶向下、逐步求精;其程序结构是按功能划分为若干个基本模块;各模块之间的关系尽可能简单,在功能上相对独立;每一模块内部均是由顺序、选择和循环三种基本结构组成;其模块化实现的具体方法是使用子程序。结构化程序设计由于采用了模块分解与功能抽象,自顶向下、分而治之的方法,从而有效地将一个较复杂的程序系统设计任务分解成许多易于控制和处理的子任务,便于开发和维护。
虽然结构化程序设计方法具有很多的优点,但它仍是一种面向过程的程序设计方法,它把数据和处理数据的过程分离为相互独立的实体。当数据结构改变时,所有相关的处理过程都要进行相应的修改,每一种相对于老问题的新方法都要带来额外的开销,程序的可重用性差。
由于图形用户界面的应用,程序运行由顺序运行演变为事件驱动,使得软件使用起来越来越方便,但开发起来却越来越困难,对这种软件的功能很难用过程来描述和实现,使用面向过程的方法来开发和维护都将非常困难。

1-4 什么是对象?什么是面向对象方法?这种方法有哪些特点?

解:
从一般意义上讲,对象是现实世界中一个实际存在的事物,它可以是有形的,也可以是无形的。对象是构成世界的一个独立单位,它具有自己的静态特征和动态特征。面向对象方法中的对象,是系统中用来描述客观事物的一个实体,它是用来构成系统的一个基本单位,由一组属性和一组行为构成。
面向对象的方法将数据及对数据的操作方法放在一起,作为一个相互依存、不可分离的整体--对象。对同类型对象抽象出其共性,形成类。类中的大多数数据,只能用本类的方法进行处理。类通过一个简单的外部接口,与外界发生关系,对象与对象之间通过消息进行通讯。这样,程序模块间的关系更为简单,程序模块的独立性、数据的安全性就有了良好的保障。通过实现继承与多态性,还可以大大提高程序的可重用性,使得软件的开发和维护都更为方便。
面向对象方法所强调的基本原则,就是直接面对客观存在的事物来进行软件开发,将人们在日常生活中习惯的思维方式和表达方式应用在软件开发中,使软件开发从过分专业化的方法、规则和技巧中回到客观世界,回到人们通常的思维。

1-5 什么叫做封装?

解:
封装是面向对象方法的一个重要原则,就是把对象的属性和服务结合成一个独立的系统单位,并尽可能隐蔽对象的内部细节。

1-6 面向对象的软件工程包括哪些主要内容?

解:
面向对象的软件工程是面向对象方法在软件工程领域的全面应用,它包括面向对象的分析(OOA)、面向对象的设计(OOD)、面向对象的编程(OOP)、面向对象的测试(OOT)和面向对象的软件维护(OOSM)等主要内容。

1-7 简述计算机内部的信息可分为几类?

解:
计算机内部的信息可以分成控制信息和数据信息二大类;控制信息可分为指令和控制字两类;数据信息可分为数值信息和非数值信息两类。

1-8 什么叫二进制?使用二进制有何优点和缺点?

解:
二进制是基数为2,每位的权是以2 为底的幂的进制,遵循逢二进一原则,基本符号为0和1。采用二进制码表示信息,有如下几个优点:1.易于物理实现;2.二进制数运算简单;3.机器可靠性高;4.通用性强。其缺点是它表示数的容量较小,表示同一个数,二进制较其他进制需要更多的位数。

1-9 请将以下十进制数值转换为二进制和十六进制补码:
(1)2 (2)9 (3)93
(4)-32 (5)65535 (6)-1

解:
(1) (2)10 = (10)2 = (2)16
(2) (9)10 = (1001)2 = (9)16
(3) (93)10 = (1011101)2 = (5D)16
(4) (-32)10 = (11100000)2 = (E0)16
(5) (65535)10 = (11111111 11111111)2 = (FFFF)16
(6) (-1)10 = (11111111 11111111)2 = (FFFF)16

1-10 请将以下数值转换为十进制:
(1)(1010)2 (2)(10001111)2 (3)(01011111 11000011)2
(4)(7F)16 (5)(2D3E)16 (6)(F10E)16

解:
(1)(1010)2 = (10)10
(2)(10001111)2 = (143)10
(3)(01011111 11000011)2 = (24515)10
(4)(7F)16 = (127)10
(5)(2D3E)16 = (11582)10
(6)(F10E)16 = (61710)10

1-11 简要比较原码、反码、补码等几种编码方法。
解:
原码:将符号位数字化为 0 或 1,数的绝对值与符号一起编码,即所谓"符号——绝对值表示"的编码。
正数的反码和补码与原码表示相同。
负数的反码与原码有如下关系:
符号位相同(仍用1表示),其余各位取反(0变1,1变0)。
补码由该数反码的最末位加1求得。

第 二 章 C++简单程序设计

2-1 C++语言有那些主要特点和优点?

解:
C++语言的主要特点表现在两个方面,一是全面兼容C,二是支持面向对象的方法。C++是一个更好的C,它保持了C的简洁、高效、接近汇编语言、具有良好的可读性和可移植性等特点,对C的类型系统进行了改革和扩充,因此C++比C更安全,C++的编译系统能检查出更多的类型错误。 C++语言最重要的特点是支持面向对象。

2-2 下列标识符哪些是合法的?
Program, -page, _lock, test2, 3in1, @mail, A_B_C_D

解:
Program, _lock, test2, A_B_C_D是合法的标识符,其它的不是。

2-3 例2.1中每条语句的作用是什么?
#include <iostream.h>
void main(void)
{
cout<<"Hello!\n";
cout<<"Welcome to c++!\n";
}

解:
#include <iostream.h> //指示编译器将文件iostream.h中的代码
//嵌入到该程序中该指令所在的地方
void main() //主函数名,void 表示函数没有返回值
{ //函数体标志
cout<<"Hello!\n"; //输出字符串Hello!到标准输出设备(显示器)上。
cout<<"Welcome to c++!\n"; //输出字符串Welcome to c++!
}
在屏幕输出如下:
Hello!
Welcome to c++!

2-4 使用关键字const而不是#define语句的好处有哪些?

解:
const定义的常量是有类型的,所以在使用它们时编译器可以查错;而且,这些变量在调试时仍然是可见的。

2-5 请写出C++语句声明一个常量PI,值为3.1416;再声明一个浮点型变量a,把PI的值赋给a。

解:
const float PI = 3.1416;
float a = PI;

2-6 在下面的枚举类型中,Blue的值是多少?
enum COLOR ;

解:
Blue = 102

2-7 注释有什么作用?C++中有哪几种注释的方法?他们之间有什么区别?

解:
注释在程序中的作用是对程序进行注解和说明,以便于阅读。编译系统在对源程序进行编译时不理会注释部分,因此注释对于程序的功能实现不起任何作用。而且由于编译时忽略注释部分,所以注释内容不会增加最终产生的可执行程序的大小。适当地使用注释,能够提高程序的可读性。在C++中,有两种给出注释的方法:一种是延用C语言方法,使用"/*"和"*/"括起注释文字。另一种方法是使用"//",从"//"开始,直到它所在行的行尾,所有字符都被作为注释处理。

2-8 什么叫做表达式?x = 5 + 7是一个表达式吗?它的值是多少?

解:
任何一个用于计算值的公式都可称为表达式。x = 5 + 7是一个表达式,它的值为12。

2-9 下列表达式的值是多少?
1. 201 / 4
2. 201 % 4
3. 201 / 4.0

解:
1. 50
2. 1
3. 50.25

2-10 执行完下列语句后,a、b、c三个变量的值为多少?
a = 30;
b = a++;
c = ++a;

解:
a:32 ; b:30 ; c:32;

2-11 在一个for循环中,可以初始化多个变量吗?如何实现?

解:
在for循环设置条件的第一个";"前,用,分隔不同的赋值表达式。
例如:
for (x = 0, y = 10; x < 100; x++, y++)

2-12 执行完下列语句后,n的值为多少?
int n;
for (n = 0; n < 100; n++)

『柒』 deitel大学c语言教程答案

是这个吗

『捌』 《c大学教程》第五版 习题答案 为提供者追加200分

第四版的答案:

http://www.rayfile.com/zh-cn/files/c4d7ca40-8d1e-11dd-9634-0019d11a795f/

『玖』 求《C 大学教程》/《C how to program》第5版 课后练习答案

《c大学教程 (Deitle 著) 电子工业出版社 课后答案》
是不是这个?

『拾』 c/c++程序设计基础教程课后答案(清华大学出版社)

谭浩强的都很好

热点内容
四川农业大学申请考核博士 发布:2025-10-20 08:58:11 浏览:981
福田雷沃重工本科生待遇怎么样 发布:2025-10-20 08:53:49 浏览:575
华为要本科生吗 发布:2025-10-20 08:25:41 浏览:550
2008年青岛本科生工资 发布:2025-10-20 08:04:24 浏览:444
东北大学艺术考研 发布:2025-10-20 07:38:35 浏览:299
我的大学生活txt 发布:2025-10-20 07:35:28 浏览:25
人民大学外语系考研 发布:2025-10-20 07:31:12 浏览:894
上海交通大学考研辅导班 发布:2025-10-20 07:24:54 浏览:420
华中农业大学细胞生物学考研群 发布:2025-10-20 07:09:36 浏览:558
南京大学2016考研线 发布:2025-10-20 06:43:12 浏览:930