اجوبة روبرت لافور

advertisement
1. procedural, object-oriented
2. b
3. data, act on that data
4. a
5. data hiding
6. a, d
7. objects
8. False; the organizational principles are different.
9. encapsulation
10. d
11. False; most lines of code are the same in C and C++.
12. polymorphism
13. d
14. B
2. Answers:
-------1. b, c
2. parentheses
3. braces { }
4. It’s the first function executed when the program starts
5. statement
6.
// this is a comment
/* this is a comment */
7. a, d
8. a. 4
b. 10
c. 4
d. 4
9. False
10. a. integer constant
b. character constant
c. floating-point constant
d. variable name or identifier
e. function name
11. a. cout << ‘x’;
b. cout << “Jim”;
c. cout << 509;
12. False; they’re not equal until the statement is executed.
13. cout << setw(10) << george;
14. IOSTREAM
15. cin >> temp;
16. IOMANIP
17. string constants, preprocessor directives
18. true
19. 2
20. assignment (=) and arithmetic (like + and *)
21.
temp += 23;
temp = temp + 23;
22. 1
23. 2020
24. to provide declarations and other data for library functions, overloaded operators, and
objects
25. library
________
3. /**1. Assuming there are 7.481 gallons in a cubic foot, write a
program that asks the user to enter a
4.
number of gallons, and then displays the equivalent in cubic feet.*/
5. #include<iostream.h>
6. #include<conio.h>
7.
8. #define g_per_f 7.481
9.
10. void main(void)
11. {
12.
cout<<"### Programmed By Amahdy(MrJava) ,right
restricted.~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
13.
cout<<"------------------------------------------------------------------------------\n\n";
14.
15.
float n_gallons;
16.
17.
do{
18.
cout<<"Enter the number of gallons : \xdb\t";
19.
cin >>n_gallons;
20.
cout<<"The equivalent in cubic feet : \xdb\t"<<n_gallons /
g_per_f<<endl;
21.
cout<<"\n !Press c to continue or any key to
exit."<<endl<<endl;
22.
}while(getch()=='c');
23. }
24. /**2. Write a program that generates the following table:
25.
1990
135
26.
1991
7290
27.
1992
11300
28.
1993
16200
29.
30.
31. Use a single cout statement for all output.*/
32. #include<iostream.h>
33.
34.
35.
36.
37.
38.
#include<iomanip.h>
#include<conio.h>
void main(void)
{
cout<<"### Programmed By Amahdy(MrJava) ,right
restricted.~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
39.
cout<<"------------------------------------------------------------------------------\n\n";
40.
41.
int i, i_arr[4]={135,7290,11300,16200};
42.
43.
do{
44.
for(i=1990;i<1994;i++) cout<<i<<setw(7)<<i_arr[i-1990]<<endl;
45.
cout<<"\n !Press c to continue or any key to
exit."<<endl<<endl;
46.
}while(getch()=='c');
47. /**3. Write a program that generates the following output:
48.
10
49.
20
50.
19
51.
52.
53.
Use an integer constant for the 10, an arithmetic assignment
operator to generate the 20, and a
54.
decrement operator to generate the 19. */
55. #include<iostream.h>
56. #include<conio.h>
57.
58. #define ten 10
59.
60. void main(void)
61. {
62.
cout<<"### Programmed By Amahdy(MrJava) ,right
restricted.~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
63.
cout<<"------------------------------------------------------------------------------\n\n";
64.
65.
//int ten = 10; //### use this line in the place of "define"
66.
//int second, third;
67.
//second = 2*ten; third = second-1;
68.
//cout<<ten<<endl<<second<<endl<<third<<endl;
69.
do{
70.
cout<<ten<<endl<<2*ten<<endl<<2*ten-1<<endl;
71.
cout<<"\n !Press c to continue or any key to
exit."<<endl<<endl;
72.
}while(getch()=='c');
73. }
74. /*5. A library function, islower(), takes a single character (a
letter) as an argument and returns a
75.
nonzero integer if the letter is lowercase, or zero if it is
uppercase. This function requires the header
76.
file CTYPE.H. Write a program that allows the user to enter a
letter, and then displays either zero or
77.
nonzero, depending on whether a lowercase or uppercase letter was
entered. (See the SQRT
78.
program for clues.)*/
79.
80.
81.
82.
83.
84.
85.
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
void main(void)
{
cout<<"### Programmed By Amahdy(MrJava) ,right
restricted.~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
86.
cout<<"------------------------------------------------------------------------------\n\n";
87.
88.
do{
89.
cout<<"Enter a letter : \xdb\t"<<endl;
90.
cout<<islower(getch())<<"\nthis value must be zero if you
entred an uppercase letter and nonzero case else."<<endl;
91.
cout<<"\n !Press c to continue or any key to
exit."<<endl<<endl;
92.
}while(getch()=='c');
93. }
------------------------------Chapter 3
1. b, c
2. george != sally
3. –1 is true; only 0 is false.
4. The initialize expression initializes the loop variable, the test expression tests the loop
variable, and the increment expression changes the loop variable.
5. c, d
6. True
7.
for(int j=100; j<=110; j++)
cout << endl << j;
8. braces (curly brackets)
9. c
10.
int j = 100;
while( j <= 110 )
cout << endl << j++;
11. False
12. At least once.
13.
int j = 100;
do
cout << endl << j++;
while( j <= 110 );
14.
if(age > 21)
cout << “Yes”;
15. d
16.
if( age > 21 )
cout << “Yes”;
else
cout << “No”;
17. a, c
18. ‘\r’
19. preceding, surrounded by braces
20. reformatting
21.
switch(ch)
{
case ‘y’:
cout << “Yes”;
break;
case ‘n’:
cout << “No”;
break;
default:
cout << “Unknown response”;
}
22. ticket = (speed > 55) ? 1 : 0;
23. d
24. limit == 55 && speed > 55
25. unary, arithmetic, relational, logical, conditional, assignment
26. d
27. the top of the loop
28. b
________
2. ----------chapter 4
Answers:
-------1. b, d
2. True
3. semicolon
4.
struct time
{
int hrs;
int mins;
int secs;
};
5. False; only a variable definition creates space in memory.
6. c
7. time2.hrs = 11;
8. 18 in 16-bit systems (3 structures times 3 integers times 2 bytes), or 36 in 32-bit systems
9. time time1 = { 11, 10, 59 };
10. True
11. temp = fido.dogs.paw;
12. c
13. enum players { B1, B2, SS, B3, RF, CF, LF, P, C };
14.
players joe, tom;
joe = LF;
tom = P;
15. a. No
b. Yes
c. No
d. Yes
16. 0, 1, 2
17. enum speeds { obsolete=78, single=45, album=33 };
18. Because false should be represented by 0.
________
----------------------------------CHAPTER 5—FUNCTIONS
Answers:
-------1. d (half credit for b)
2. definition
3.
void foo()
{
cout << “foo”;
}
4. declaration, prototype
5. body
6. call
7. declarator
8. c
9. False
10. To clarify the purpose of the arguments.
11. a, b, c
12. Empty parentheses mean the function takes no arguments.
13. one
14. True
15. At the beginning of the declaration and declarator.
16. void
17.
main()
{
int times2(int); // prototype
int alpha = times2(37); // function call
}
18. d
19. To modify the original argument (or to avoid copying a large argument).
20. a, c
21.
int bar(char);
int bar(char, char);
22. faster, more
23. inline float foobar(float fvar)
24. a, b
25. char blyth(int, float=3.14159);
26. visibility, lifetime
27. Those functions defined following the variable definition.
28. The function in which it is defined.
29. b, d
30. On the left side of the equal sign.
________
CHAPTER 6—OBJECTS AND CLASSES
Answers:
-------1. A class declaration describes how objects of a class will look when they are created.
2. class, object
3. c
4.
class leverage
{
private:
int crowbar;
public:
void pry();
};
5. False; both data and functions can be private or public.
6. leverage lever1;
7. d
8. lever1.pry();
9. inline (also private)
10.
int getcrow()
{ return crowbar; }
11. created (defined)
12. the class of which it is a member
13.
leverage()
{ crowbar = 0; }
14. True
15. a
16. int getcrow();
17.
int leverage::getcrow()
{ return crowbar; }
18. member functions and data are, by default, public in structures but private in classes
19. three, one
20. calling one of its member functions
21. b, c, d
22. False; trial and error may be necessary.
23. d
24. True
25. void aFunc(const float jerry) const;
________
Download