-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathExercise 14.8
37 lines (27 loc) · 2 KB
/
Exercise 14.8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
1. (Practice) Enter and compile Program 14.20. (Hint : The namespace file dataChecks and the
program file are available with the source code provided on this book’s Web site. See this
book’s introduction for the URL.)
2. (For thought) a. What is an advantage of namespaces?
b. What is a possible disadvantage of namespaces?
3. (For thought) What types of classes and functions would you include in a personal
library? Why?
4. (For thought) Why would a programmer supply a namespace file in its compiled form rather
than as source code?
5. (Useful utility) a. Write a C++ function named whole() that returns the integer part of any
number passed to the function. (Hint: Assign the passed argument to an integer variable.)
b. Include the function written in Exercise 5a in a working program. Make sure your function
is called from main() and correctly returns a value to main(). Have main() use a cout
statement to display the returned value. Test the function by passing various data to it.
c. When you’re confident that the whole() function written for Exercise 5a works correctly,
save it in a namespace and a personal library of your choice.
6. (Useful utility) a. Write a C++ function named fracpart() that returns the fractional part
of any number passed to the function. For example, if the number 256.879 is passed to
fracpart(), the number .879 should be returned. Have the fracpart() function call the
whole() function you wrote in Exercise 5a. The number returned can then be determined as
the number passed to fracpart() less the returned value when the same argument is passed
to whole().
b. Include the function written in Exercise 6a in a working program. Make sure the function
is called from main() and correctly returns a value to main(). Have main() use a cout
statement to display the returned value. Test the function by passing various data to it.
c. When you’re confident the fracpart() function written for Exercise 6a works correctly,
save it in the same namespace and personal library selected for Exercise 5c.