|
Note: If you have problem printing and seeing the entire
document on your print out, CS 161 Walter Morales Due date announced in class, check email Purpose: The purpose of this homework assignment is to become familiar with the programming environment provided by the Borland C++ compiler or MS Visual C++ . Suppose you want to write a program that does simple addition, subtraction, multiplication and division for a seven-year-old child, The following program prompts her/him for two numbers. The program then waits for the user to type an answer. When she/he gives her/his answer, the program displays the correct result so she can compare the response. The program below executes a simple addition problem. Your task is to implement the other three missing functions to subtract, multiply and divide. The user will only input two numbers for each of the calculations and the output will be basically the same as you see for the addition. You will separate each section with: *** Math Practice DIVISION ***, etc. At the end of the program, you will display a formatted table similar to the one below using the manipulators for output setw and setprecision. The box surrounding the output is made up of ---- and | on your keyboard. Some variables will have to be declared as floats, please be aware of the problems that we can encounter when dividing int/int int/float, and other unexpected results by mixing data types. You will need to create several variables to hold the value for each number entered .
Where you see num1 + num2 , num1 and num2 you will be replaced with the actual values for those variables entered by the user.1) Start the C++ compiler (Borland or Turbo). If you already know Visual C++ you can use it instead. Note that if you use Borland you will have to follow the old standard of C++. Appendix D on our text book shows the differences. 2) Enter the attached program exactly as shown.
3) Save the program in a file on you work disk (do this frequently and not just at the end of program entry process). 4) Compile the program (use the compile pull-down menu), then run it. 5) At this point you should try playing with various options provided in the pull-down menus. In particular try to set a few "watches" (Borland) and run the program in step-over mode (Borland) or use the Debug option in Visual C++. 6) Make sure that you have an opening screen where it explains exactly what the program does before starting the program. Remember, this is a child and need all the help possible. Also tell the user of all things to be avoided when data is entered, such as 0s in the division section. partial output:
*Notes:
|
Back to CS
161 Homepage |