# CS 1711 - Assignment 4

5 pm, November 6
(This is a hard dead-line for both hard copy and drop-box submission. Do not leave it to the last minute. `I couldn't get my printer to work' or `The network was down at 4:30' are not accepted excuses for lateness.)

### Question 1

We are used to counting in base 10, but that is not the only possible base. A base 8 number can be expressed using the digits 0 through 7. Write a program that has functions which input, display, increment, and decrement three-digit base 8 numbers, where there is one formal parameter per digit. Consider only positive numbers.

A driver program is given here in base8_dr.cpp . Be sure that you test your finished program with suitable values, including those on the boundary like 777.

Functions you must provide:

``` void get_digits(int input, int& dig1, int& dig2, int& dig3) // Pre: a 3 digit base 8 number read from the terminal as if it were // an integer, input // Post: the dig1, dig2, dig3 hold the digits of the integer input //(in the order they were entered, so 642 has dig1 = 6) ```

``` void display(int dig1, int dig2, int dig3) // Displays the base 8 number with digits dig1-3 ```

``` void increment(int& dig1, int& dig2, int& dig3) //Pre: dig1-3 are digits of a base 8 number, N //Post: dig1-3 are digits of N+1 (base 8) ```

``` void decrement(int& dig1, int& dig2, int& dig3) //Pre: dig1-3 are digits of a base 8 number, N //Post: dig1-3 are digits of N-1 (base 8) ```

File name: `base8.cpp`

### Question 2

Write a program to accomplish the following tasks:

Open one file for input and one for output. The input file is to be read and copied to the output file with the addition of line numbers at the beginning of each line.

In addition, the program is to display (on screen) the lengths of the shortest and longest lines of the file and display the average line length of the file.

Your program should allow the user to specify the names of the input and output files. (See text example 5.3.)

File name: `stream.cpp`