Professional Documents
Culture Documents
In this document you can find exercises related to the content of C++ Programming Language (Fourth Edition).
Solution is provided. However, if you follow the book carefully, you will be able to solve the proposed problems
easily.
Introduction material is very dense and thats why no exercise material is elaborated.
Dont get panic If you have difficulties trying to solve these exercises. The material provided in the Introduction
Material (Part I) and chapter six, allow you to PROPOSE some solution. Some recommendations are:
1. Try to mimic the Programming Technique found in the chapter.
2. For now, dont worry for efficiency, make the program work.
3. Declaration implies definition (initialization).
4. Prove if proposed code behaves correctly in main().
1
2
3
4
5
6
7
8
9
10
11
12
13
14
12;
9;
suma1 ( a , b ) << e n d l ;
suma2 ( a , b ) << e n d l ;
suma3 ( a , b ) << e n d l ;
Now use an IDE and compile. Compare you observations with the IDE output.
(1)
Where e is the Euler constant 2.71828(use this as an approximation of e). Now find the value of: f(2.5), f(5).
20. What is the maximum number that a float, double and int type can store (Hint:Check page 150).
C. Scope
21. Before you compile the code, identify visually the error (if exist):
(a) Code 1
1
2
3
4
5
6
7
8
9
10
11
12
(b) Code 2
1
2
3
4
5
6
7
8
9
10
11
12
(c) Code 3
1
2
3
4
5
6
7
8
9
10
11
12
(d) Code 4
1
2
3
4
5
6
7
8
9
10
11
(e) Code 5
1
2
3
4
5
6
7
8
9
10
11
12
13
D. Initialization
22. Set the most appropriate type for the following:
(a) auto data = 123;
(b) auto data1 = a;
(c) auto data2 = 3.1415;
(d) auto data3 = numericl imits < int >:: max();
(e) auto data4 = 2147483648;
(f) auto data5 = "Mauricio";
(g) auto data6 = Mauricio;
(h) auto data7{12};
(i) auto data8{a};
How can these initialization be improved ?