ImageVerifierCode 换一换
格式:DOC , 页数:21 ,大小:122KB ,
资源ID:3179283      下载积分:20 文钱
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,省得不是一点点
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.wenke99.com/d-3179283.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: QQ登录   微博登录 

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(C++编程思想 答案 第四章 其他章节请点击用户名找 thinking in C++ annotated solution guide(charpter 4).doc)为本站会员(11****ws)主动上传,文客久久仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知文客久久(发送邮件至hr@wenke99.com或直接QQ联系客服),我们立即给予删除!

C++编程思想 答案 第四章 其他章节请点击用户名找 thinking in C++ annotated solution guide(charpter 4).doc

1、 Viewing Hints Book Home Page Free Newsletter Seminars Seminars on CD ROM Consulting Annotated Solution GuideRevision 1.0for Thinking in C+, 2nd edition, Volume 1by Chuck Allison2001 MindView, Inc. All Rights Reserved. Previous Chapter Table of Contents Next Chapter Chapter 44-1In the Standard C lib

2、rary, the function puts( ) prints a char array to the console (so you can say puts(“hello“). Write a C program that uses puts( )but does not include or otherwise declare the function. Compile this program with your C compiler. (Some C+ compilers are not distinct from their C compilers; in this case

3、you may need to discover a command-line flag that forces a C compilation.) Now compile it with the C+ compiler and note the difference.(Left to the reader)4-2Create a struct declaration with a single member function, then create a definition for that member function. Create an object of your new dat

4、a type, and call the member function.(see the next exercise)4-3Change your solution to Exercise 2 so the struct is declared in a properly “guarded” header file, with the definition in one cpp file and your main( ) in another.Solution:/: S04:MyStruct.h#ifndef MYSTRUCT_H#define MYSTRUCT_Hstruct MyStru

5、ct void f();#endif /:/: S04:MyStruct.cpp O#include “MyStruct.h“#include using namespace std;void MyStruct:f() cout using namespace std;struct HasInt int x;void setInt(int newX) x = newX;int getInt() return x;int main() HasInt h;h.setInt(5);cout using namespace std;struct HasInt int x;void setInt(int

6、 x) this-x = x;int getInt() return this-x;void display() cout getInt() by saying: printf(“%dn”, i) in which i is the int you wish to print. Create a separate file containing main( ), and in this file declare f( ) to take a float argument. Call f( ) from inside main( ). Try to compile and link your p

7、rogram with the C+ compiler and see what happens. Now compile and link the program using the C compiler, and see what happens when it runs. Explain the behavior.Solution:This exercise illustrates type-safe linkage. In C+ function name are decorated (aka mangled) to include information about their ar

8、guments. The consequence is that the name the linker sees is actually quite different than what you see. For example, f(int) might appear to the linker as f_F1i (a function taking one int), say, and f(double) as f_F1d. Since the names are distinct, you get a linker error. In C the names are the same

9、, allowing you to call f(double) with an int, which is an error.4-10Find out how to produce assembly language from your C and C+ compilers. Write a function in C and a struct with a single member function in C+. Produce assembly language from each and find the function names that are produced by you

10、r C function and your C+ member function, so you can see what sort of name decoration occurs inside the compiler.Solution:For f(int) one compiler generated the name ?fYAXHZ, and ?fYAXNZ for f(double). Go figure.4-11Write a program with conditionally-compiled code in main( ), so that when a preproces

11、sor value is defined one message is printed, but when it is not defined another message is printed. Compile this code experimenting with a #define within the program, then discover the way your compiler takes preprocessor definitions on the command line and experiment with that.(Left to the reader)4

12、-12Write a program that uses assert( ) with an argument that is always false (zero) to see what happens when you run it. Now compile it with #define NDEBUG and run it again to see the difference.(Left to the reader)4-13Create an abstract data type that represents a videotape in a video rental store.

13、 Try to consider all the data and operations that may be necessary for the Videotype to work well within the video rental management system. Include a print( ) member function that displays information about the Video.(Left to the reader)4-14Create a Stack object to hold the Video objects from Exerc

14、ise 13. Create several Video objects, store them in the Stack, then display them using Video:print( ).(Left to the reader)4-15Write a program that prints out all the sizes for the fundamental data types on your computer using sizeof( ).Solution:/: S04:Sizeof.cpp#include int main() using namespace st

15、d;cout as its underlying data structure.(Left to the reader)4-17Dynamically create pieces of storage of the following types, using new: int, long, an array of 100 chars, an array of 100 floats. Print the addresses of these and then free the storage using delete.Solution:/: S04:Storage.cpp#include int main() using namespace std;int* p_int = new int;long* p_long = new long;char* p_chars = new char100;float* p_floats = new float100;cout (p_chars) endl;cout “p_floats = “ p_floats endl;delete p_int;delete p_long;delete p_chars;delete p_floats;/* Output:/ Compiler A:

Copyright © 2018-2021 Wenke99.com All rights reserved

工信部备案号浙ICP备20026746号-2  

公安局备案号:浙公网安备33038302330469号

本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。