"C ++ primer plus" program review questions and exercises (01)

A review questions

What 1 C ++ program modules called?

 

2 The following preprocessor directive is what to do with?

#include <iostream>

 

3 The following statement is what to do with?

using namespace std;

 

4 What statement can be used to print the phrase "Hello, world", and then start a new line?

 

5 What statement can be used to create an integer variable named cheeses of?

 

6 What statement can be used to value 32 to the variable cheeses?

 

7 What statement can be used to read the value of the variable cheeses from the keyboard input?

 

8 What statement can be used to print "We have X variables of cheese,", where X is the current value of the variable cheeses.

 

9 following function prototype indicates which information about the function?

int froop(double t);

 

void rattle(int n);

 

int prune(void);

 

10-defined functions, under what circumstances do not have to use the keyword return?

 

11 suppose you write main () function contains the following code:

cout <<  " please enter your PIN: ";

The compiler pointed out that cout is an unknown identifier. The cause of this problem is what might be? 3 ways to fix this problem is proposed.

 

Two programming exercises

1. Write a C ++ program that displays your name and address.

 

A program written in C ++ 2, it requires the user to enter a long distance unit, which is then converted into a code (a long code at 220).

 

3 to write a C ++ program that uses three user-defined functions (including main ()), and generates the following output:

Three blind mice

Three blind mice

See how they run

See how they run

Wherein a function to be called twice, first two lines of the function generator; also another function is called twice, and generates the remaining output.

 

4 Write a program that allows users to input their age, and then displays the number of months of age contains. as follows:

Enter your age: 29

 

5 to write a program in which the main () calls a user-defined function (the parameter value is in degrees Celsius, and returns the corresponding value Fahrenheit).

The following format program requires the user to enter values ​​Celsius, and displays the result:

Please enter a Celsius value : 20

20 degrees Celsius is 68 degree Fahrenheit.

The following is a conversion formula:

= 1.8 X Fahrenheit temperature + 32.0 ° C

 

6 write a program that main () calls a user-defined function (light years parameter value, and returns the value corresponding to AU)

The program requires the user to the following format input light years value, and displays the result:

Enter the number of light years : 4.2

4.2 linght years = 265608 astronomical units.

Astronomical unit is the average distance from the Earth to the Sun (about 150 million kilometers or 93 million miles), light year is the distance light year away (about

10 trillion kilometers or 6 trillion miles) (except the sun, the nearest star is about 4.2 light years from Earth). Please double type (see Listing 2.4)

Conversion formula: 1 light astronomical unit = 63240

 

7 to write a program, it requires the user to enter the number of hours and minutes. In the main () function, these two values ​​are passed to a void function, the latter

A display format such as the following two values:

Enter the number of hours : 9

Enter the number of minutes : 28

Time: 9:28

 

Guess you like

Origin www.cnblogs.com/mrray1105/p/11963866.html