|
|
|
|
|
|
|
cin.get function to read each character. (This function is just for practice. There's already a library function, cin.ignore, that allows you to do the same thing.) |
|
|
|
|
|
|
|
|
14. Modify the function in Exercise 13 so that it returns a count of the number of characters that were skipped. |
|
|
|
|
|
|
|
|
1. Using functions, rewrite the program developed for Programming Problem 4 in Chapter 6. |
|
|
|
|
|
|
|
|
Develop a top-down design and write a C++ program to determine the number of words encountered in the input stream. For the sake of simplicity, we define a word to be any sequence of characters except whitespace characters (blanks and newlines). Words may be separated by any number of whitespace characters. A word may be any length, from a single character to an entire line of characters. If you are writing the program to read data from a file, then it should echo-print the input. For an interactive implementation, you do not need to echo-print for this program. |
|
|
|
|
|
|
|
|
For example, for the following data, the program would indicate that 26 words were entered. |
|
|
|
 |
|
|
|
|
This isn't exactly an example of gOOd english, but it
does demonstrate that a wOrd is just a sequence of
characters withOut+ any blank$. ##### ....... |
|
|
|
|
|
|
|
|
(Hint: One way to solve this problem involves turning the SkipToBlank function of Programming Warm-Up Exercise 13 into a SkipToWhitespace function.) |
|
|
|
|
|
|
|
|
Now that your programs are becoming more complex, it is even more important for you to use proper indentation and style, meaningful identifiers, and plenty of comments. |
|
|
|
|
|
|
|
|
2. Write a C++ program that reads characters representing binary (base 2) numbers from a data file and translates them to decimal (base 10) numbers. The decimal numbers should be output in a column with an appropriate heading. Each binary number has been placed ''backwards" in the file. That is, the rightmost digit is the first encountered, the second digit from the right is encountered next, and so on. The program reads the digits one at a time. As each digit is read, the program should translate that digit into the corresponding decimal value by multiplying it by the appropriate power of 2 (depending on where the digit was in the number). There is only one number per input line, but there is an arbitrary number of blanks before each number. The program should check for bad data; if it encounters anything except a zero or a one, it should output the message "Bad integer on input." |
|
|
|
|
|
|
|
|
As always, use plenty of comments, proper documentation and coding style, and meaningful identifiers throughout this program. You must decide which of your design modules should be coded as functions to make the program easier to understand. |
|
|
|
|
|
|
|
|
3. Develop a top-down design and write a C++ program to print a calendar for one year, given the year and the day of the week that January 1 falls on. It may help to think of this task as printing 12 calendars, one for each month, given the day of |
|
|
|
|
|