course.wilkes.edu/CS125Labs
Welcome to the site for CS 125 labs!

 

calculate.cpp

// calculate.cpp provides a simple 4-function calculator.
//
// Begun by: Joel Adams, for Hands On C++.
// Completed by:
// Date:
// Purpose:
//
// Specification:
// input(keyboard): a char, stored in operation;
//                  two reals, stored in op1 and op2;
// output(screen): the result of the expression (op1 operation op2).
//****************************************************************

#include <iostream> // cin, cout, <<, >>, good(), ... #include <string> // string #include <cassert> // assert() using namespace std;

// ... Replace this line with the prototype of Apply()

int main() { const string MENU = "\nPlease enter:\n" "\t+, to perform addition;\n" "\t-, to perform subtraction;\n" "\t*, to perform multiplication;\n" "\t/, to perform division;\n" "--> ";

double op1, op2; // operands 1 and 2 double result; // result of operation kept here char operation; // operation is +, -, * or /

cout << endl << "Welcome to the 4-function calculator!" << endl << MENU; cin >> operation; assert(operation == '+' || operation == '-' || operation == '*' || operation == '/');

cout << endl << "Now enter your operands: "; cin >> op1 >> op2; assert(cin.good()); assert(operation != '/' || op2 != 0); result = Apply(operation, op1, op2); cout << endl << op1 << operation << op2 << " = " << result << endl;

return 0; }

// ... Replace this line with the definition of Apply()

 
  Home

Help

Lab 0

Lab 1

Lab 2

Lab 3a

Lab 3b

Lab 4

Lab 5

Lab 6

Lab 7

Lab 8

Lab 9

Lab 10

Lab 11

Lab 12

Lab 13



Membership

Login




Last update: Thursday, October 10, 2002 at 1:02:13 PM.
visitors to this page.