Assignment 5

Back Up Next

Home
Assignment 1
Assignment 2
Assignment 3
Assignment 4
Assignment 5
Assignment 6
Assignment 7

 

CS 161
50 POINTS

DUE announced in class, check email, visit the online calendar 

Purpose: To implement functions and the switch statement in your program.

The switch structure will work so that the user will make a selection from a well designed menu, offering the user an option to enter any of 10 (ten) math functions.

Problem:

You are to implement in your "calculator" program, functions (preferably value returning and passing arguments) for each math section of your program. So, the Addition, subtraction, etc.  will be a function. Also, you will add the switch statement control structure as part of your menu selection so that the user can select which operation he/she wants to perform and go to that function on your program. The user will be able to go to any section of your program with a main menu such as the one below.

You will have your program setup similar to:

switch (choice)
    'a' : call your add function.
    's' : call your subtractions function.
    .
    .
    'x': out of the program

You will have a function to read the values for the operation and pass those values as parameters to your function.

Think about what implementation would be most effective, reducing the size of your current code, such as if the reading of the input values should take place inside of the function or before or inside the switch statement. Avoid repetition of code, meaning that if you see parts of code that repeat on your program most likely you will use functions. For instance the feedback for correctness of the user's answer " you got it right x ? x is ?" it will repeat in several parts of your program, so this would be a function call.  

You will have the menu in a loop so that the user will have the choice to do as many calculations as he/she wishes by making the selection on the menu. So, every time that the user does an addition for example. It will go back to the main menu and allow the user to make a new selection.

The user will perform the addition for instance, then the result will be displayed and the menu would show up on the screen again for another choice until user selects x to exit.

Your code should be much shorter than the previous assignments, if you notice that your code is longer, it probably means that you are not making enough use of functions on your program.

Note : Please do not implement commands that have not been covered in class. This calculator assignment is progressive in difficulty and implementation. The challenge is to implement a section at a time, using just what we have learned during the previous weeks. For instance, if we have learned functions, do not use classes. You are to use functions, otherwise points will be deducted.

Clear Screen (CLS)

Here is how you clear your screen in Visual C++

First, include stdlib.h at the top of your program. Then, just insert the following call whenever you want to clear the screen.

system("CLS");

- or -

system("cls"); // The command is not case sensitive.

The program below is an example of how to use this method of clearing the screen

Note You must have the "endl" after the cout, or it will not work.

#include <iostream.h>
#include <stdlib.h>

int main()
{
   cout << "Text before the clear screen." << endl;
   system("CLS");
   cout << "Text following the clear screen." <<   endl;
return 0;
}

Another example

#include <iostream>
#include <cstdlib>

using namespace std;

int main()

{

 char ch;
  cout << "This is on one page" << endl;
  cout << "When you press enter, the screen should clear" << endl;
  cin.get(ch);
 system("cls");
 cout << "This is on a new page" << endl;
return 0;

}

 

Submit:

1) A hard copy of the source code (well documented-comments) (no need for an algorithm for this one)

2) A copy of above file on a 3.5" DOS formatted disk. Specify which compiler was used. At this point I would prefer if you write your program using MS Visual C++

 

 

Back to CS 161 Homepage
This page was last modified May 20, 2001
wmorales@pcc.edu