首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

请教哪位高手有C++primer第四版答案啊小妹先谢过了

2012-03-08 
请问谁有C++primer第四版答案啊?小妹先谢过了麻烦给我个地址啦要能发到我信箱flyhigh2005@126.com就最好了

请问谁有C++primer第四版答案啊?小妹先谢过了
麻烦给我个地址啦
要能发到我信箱flyhigh2005@126.com就最好了!
小妹就太谢谢了!100分全给你吧

[解决办法]
恩,用baidu阿,如果搜不到的话,别人一般没有。
[解决办法]
//这个可能是第三版的。
http://www.infoxa.com/asp/book_file/xxnr_book_1335.htm

//这个是csdn试读的,不全。
http://book.csdn.net/bookfiles/216/
[解决办法]
在这个地方找到了。
http://download.csdn.net/source/172123
[解决办法]
http://www.infoxa.com/asp/book/xxnr.asp?id=1335
[解决办法]
买本书不就有了吗
[解决办法]
我发给你,记得我的邮件哦 jiangkeredgirl@126.com
分我也不要了,只求发张你的照片给我

发了 c++ primer4sourcecode
[解决办法]
肯定没有全部的答案.

要是有了他们的保密也太垃圾了吧
买本书吧,我就是买的书

[解决办法]
帮顶
[解决办法]
顶一下
[解决办法]
目前还没有出完整的答案
[解决办法]
回复人:jiangkeredgirl(地狱卐小怪) ( 一级(初级)) 信誉:100 2007-05-21 08:38:21
我发给你,记得我的邮件哦 jiangkeredgirl@126.com
分我也不要了,只求发张你的照片给我
————————————————————————————————————————
汗。。。。。。。。。。。。。。。。。。
[解决办法]
我是买的书,现在是做一道题保存一道,等我做完了全部发给你。
不过怕你等不及啊。呵呵
[解决办法]
Chapter 6
1: Consider the following two code fragments for counting spaces and newlines:

// Version 1
while (cin.get(ch)) // quit on eof
{
if (ch == ' ')
spaces++;
if (ch == '\n ')
newlines++;
}
// Version 2
while (cin.get(ch)) // quit on eof
{
if (ch == ' ')
spaces++;
else if (ch == '\n ')
newlines++;
}

What advantages, if any, does the second form have over the first?

A: Both versions give the same answers, but the if else version is more efficient. Consider what happens, for example, when ch is a space. Version 1, after incrementing spaces, tests to see whether the character is a newline. This wastes time because the program already has established that ch is a space and hence could not be a newline. Version 2, in the same situation, skips the newline test.

2: In Listing 6.2, what is the effect of replacing ++ch with ch+1?

A: Both ++ch and ch + 1 have the same numerical value. But ++ch is type char and prints as a character, while ch + 1, because it adds a char to an int, is type int and prints as a number.

3: Consider carefully the following program:

#include <iostream>
using namespace std;
int main()
{
char ch;
int ct1, ct2;
ct1 = ct2 = 0;
while ((ch = cin.get()) != '$ ')
{
cout < < ch;
ct1++;
if (ch = '$ ')
ct2++;
cout < < ch;
}
cout < < "ct1 = " < < ct1 < < ", ct2 = " < < ct2 < < "\n ";


return 0;
}

Suppose we provide the following input, where represents pressing Enter:

Hi!
Send $10 or $20 now!

What is the output? (Recall that input is buffered.)

A: Because the program uses ch = '$ ' instead of ch == '$ ', the combined input and output looks like this:

Hi!
H$i$!$
$Send $10 or $20 now!
S$e$n$d$ $ct1 = 9, ct2 = 9

Each character is converted to the $ character before being printed the second time. Also, the value of the expression ch = $ is the code for the $ character, hence nonzero, hence true; so ct2 is incremented each time.

4: Construct logical expressions to represent the following conditions:

weight is greater than or equal to 115 but less than 125.

ch is q or Q.

x is even but is not 26.

x is even but is not a multiple of 26.

donation is in the range 1000–2000 or guest is 1.

ch is a lowercase letter or an uppercase letter (assume the lowercase letters are coded sequentially and that the uppercase letters are coded sequentially but that there is a gap in the code between uppercase and lowercase).

A: weight > = 115 && weight < 125

ch == 'q ' || ch == 'Q '

x % 2 == 0 && x != 26

x % 2 == 0 && !(x % 26 == 0)

donation > = 1000 && donation <= 2000 || guest == 1

(ch > = 'a ' && ch <= 'z ') ||(ch > = 'A ' && ch <= 'Z ')

5: In English the statement "I will not not speak " means the same as "I will speak. " In C++, is !!x the same as x?

A: Not necessarily. For example, if x is 10, then !x is 0 and !!x is 1. However, if x is a bool variable, then !!x is x.

6: Construct a conditional expression that is equal to the absolute value of a variable. That is, if a variable x is positive, the value of the expression is just x, but if x is negative, the value of the expression is -x, which is positive.

A: (x < 0)? -x : x

or

(x > = 0)? x : -x;

7: Rewrite the following fragment using switch:

if (ch == 'A ')
a_grade++;
else if (ch == 'B ')
b_grade++;
else if (ch == 'C ')
c_grade++;
else if (ch == 'D ')
d_grade++;
else
f_grade++;


A: switch (ch)
{
case 'A ': a_grade++;
break;
case 'B ': b_grade++;
break;
case 'C ': c_grade++;
break;
case 'D ': d_grade++;
break;
default: f_grade++;
break;
}

8: In Listing 6.10, what advantage would there be in using character labels, such as a and c, instead of numbers for the menu choices and switch cases? (Hint: Think about what happens if the user types q in either case and what happens if the user types 5 in either case.)

A: If you use integer labels and the user types a noninteger such as q, the program hangs up because integer input can 't process a character. But if you use character labels and the user types an integer such as 5, character input will process 5 as a character. Then the default part of the switch can suggest entering another character.

9: Consider the following code fragment:

int line = 0;
char ch;
while (cin.get(ch))
{
if (ch == 'Q ')
break;
if (ch != '\n ')
continue;
line++;
}

Rewrite this code without using break or continue.



A: Here is one version:

int line = 0;
char ch;
while (cin.get(ch) && ch != 'Q ')
{
if (ch == '\n ')
line++;
}



[解决办法]
Chapter 7
1: What are the three steps in using a function?

A: The three steps are defining the function, providing a prototype, and calling the function.

2: Construct function prototypes that match the following descriptions:

igor() takes no arguments and has no return value.

tofu() takes an int argument and returns a float.

mpg() takes two type double arguments and returns a double.

summation() takes the name of a long array and an array size as values and returns a long value.

doctor() takes a string argument (the string is not to be modified) and returns a double value.

ofcourse() takes a boss structure as an argument and returns nothing.

plot() takes a pointer to a map structure as an argument and returns a string.

A: void igor(void); // or void igor()

float tofu(int n); // or float tofu(int);

double mpg(double miles, double gallons);

long summation(long harray[], int size);

double doctor(const char * str);

void ofcourse(boss dude);

char * plot(map *pmap);

3: Write a function that takes three arguments: the name of an int array, the array size, and an int value. Have the function set each element of the array to the int value.

A: void set_array(int arr[], int size, int value)
{
for (int i = 0; i < size; i++)
arr[i] = value;
}


4: Write a function that takes three arguments: a pointer to the first element of a range in an array, a pointer to the element following the end of a range in an array, and an int value. Have the function set each element of the array to the int value.

A: void set_array(int * begin, int * end, int value)
{
for (int * pt = begin; pt != end; pt++)
pt* = value;
}


5: Write a function that takes a double array name and an array size as arguments and returns the largest value in that array. Note that this function shouldn 't alter the contents of the array.

A: double biggest (const double foot[], int size)
{
double max;
if (size < 1)
{
cout < < "Invalid array size of " < < size < < "\n ";
cout < < "Returning a value of 0\n ";
return 0;
}
else // not necessary because return terminates program
{
max = foot[0];
for (int i = 1; i < size; i++)
if (foot[i] > max)
max = foot[i];
return max;
}
}




[解决办法]
6: Why don 't we use the const qualifier for function arguments that are one of the fundamental types?

A: We use the const qualifier with pointers to protect the original pointed-to data from being altered. When a program passes a fundamental type such as an int or double, it passes it by value so that the function works with a copy. Thus, the original data is already protected.

7: What are the three forms a C-style string can take in a C++ program?

A: A string can be stored in a char array, it can be represented by a string constant in double quotation marks, and it can be represented by a pointer pointing to the first character of a string.



8: Write a function that has this prototype:

int replace(char * str, char c1, char c2);

Have the function replace every occurrence of c1 in the string str with c2, and have the function return the number of replacements it makes.

9: What does the expression * "pizza " mean? What about "taco "[2]?

A: int replace(char * str, char c1, char c2)
{
int count = 0;
while (*str) // while not at end of string
{
if (*str == c1)
{
*str = c2;
count++;
}
str++; // advance to next character
}
return count;
}


10: What does the expression * "pizza " mean? What about "taco "[2]?

A: Because C++ interprets "pizza " as the address of its first element, applying the * operator yields the value of that first element, which is the character p. Because C++ interprets "taco " as the address of its first element, it interprets "taco "[2] as the value of the element two positions down the line, that is, as the character c. In other words, the string constant acts the same as an array name.

11: C++ enables you to pass a structure by value and it lets you pass the address of a structure. If glitz is a structure variable, how would you pass it by value? How would you pass its address? What are the trade-offs of the two approaches?

A: To pass it by value, just pass the structure name glitz. To pass its address, use the address operator &glitz. Passing by value automatically protects the original data, but it takes time and memory. Passing by address saves time and memory but doesn 't protect the original data unless you use the const modifier for the function parameter. Also, passing by value means you can use ordinary structure member notation, but passing a pointer means you have to remember to use the indirect membership operator.

12: The function judge() has a type int return value. As an argument, it takes the address of a function that takes a pointer to a const char as an argument and that also returns an int. Write the function prototype.

A: int judge (int (*pf)(const char *));



[解决办法]
jiangkeredgirl(地狱卐小怪) ( ) 信誉:100 2007-5-21 8:38:21 得分: 0



我发给你,记得我的邮件哦 jiangkeredgirl@126.com
分我也不要了,只求发张你的照片给我

发了 c++ primer4sourcecode

--------------------------------------
寒一下这个~~


[解决办法]
- -卓越网买一本嘛……送货上门,30几块而已,既然想学,这点钱还是别省了吧……

热点排行