This assignment has two parts: a required part and an optional (challenging) part.
The required part of your assignments is to write a program that reads and print (almost) unlimited number of integers.
Your program should give the user 3 choices:
1. Enter numbers 2. Print numbers 3. Quit
If the user chooses to enter numbers, your program should continually prompt the user for an integer. When the user enters 0 your program should return to the main menu. The integers should be stored in a dynamically allocated array. One complication is that you don't know in advance how many integers will be entered. There are many ways to deal with this problem. While you are free to choose your own approach, we recommend the following strategy:
First, you allocate dynamically a small array of integers. When the array becomes full, you double its size. The doubling can be accomplished by first allocating a new array, twice the size of the old one, copying the integers from the old array to the new one, and finally, deallocating the space for the old array.
If the user chooses to print numbers, your program should print all integers entered so far and return to the main menu.
Quit terminates your program.
Here is an example of what your program should do:
Example:
joe@prelude% a.out
Please, choose one of the following 3 options:
1. Enter numbers
2. Print numbers
3. Quit
Your choice: 1
Enter a number: 3
Enter a number: 19
Enter a number: 0
Please, choose one of the following 3 options:
1. Enter numbers
2. Print numbers
3. Quit
Your choice: 2
3
19
0
Please, choose one of the following 3 options:
1. Enter numbers
2. Print numbers
3. Quit
Your choice: 1
Enter a number: 7
Enter a number: 8
Enter a number: 0
Please, choose one of the following 3 options:
1. Enter numbers
2. Print numbers
3. Quit
Your choice: 2
3
19
0
7
8
0
Please, choose one of the following 3 options:
1. Enter numbers
2. Print numbers
3. Quit
Your choice: 3
joe@prelude%
The optional part of your program, is to add two more choices to the main menu:
4. Enter operators 5. Compute
The "Enter operators" option allows the user to enter any number of arithmetic operators (+, -, *, /), one at a time. If the user enters 0 the program should return to the main menu.
The "Compute" option computes with the expression obtained by interleaving the array of integers with array of operators with no operator precedence.
For example, if the array of numbers is: 1, 5, 7, 3 and the array of operators is +,*,-, then the expression is: 1 + 5 * 7 - 3. Without operator precedence this expression evaluates to ((1+5)*7)-3 = 39.
Do all the following while logged into classes.cs.uchicago.edu.
hw2
.
dynamic.cc
, and copy it into this directory.
/********************************************* * * * I, Joe Schmoe, a.k.a. jschmoe@cs, wrote * * and tested this program myself, without * * assistance or collaboration. * * * *********************************************/Of course, this does not preclude you from asking general questions about C++ (to anyone), or from asking the instructor or TA's for clarification of the assignment.
g++ dynamic.cc
at the command line.
all
which properly compiles your program. In this case, test your submission
by typing make
. Make sure you are
on one of the Linux machines (e.g. classes) when you do this!
trial.txt
.
Choose the trial input carefully to demonstrate that your
program functions correctly even on "hard" cases.
The contents of this file must agree with the actual behavior of
your program.
dynamic.cc
and trial.txt
from this directory. (If you are submitting multiple source files and a Makefile, then only delete the compiled versions and junk.)
cd ..
  to change to the parent directory.
hwsubmit 11600 hw2You should get a message indicating that the correct files are being copied. If you get error messages or no message, then send email to one of the TA's before the submission deadline.