1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
/*
Programmer name: Kris Rossman
date: 10/20/2013
assignment: Lab 8 Part 2
description: First menu based program
INPUTS:
cin - menu choice
OUTPUTS:
cout - menu, user selection, counter table
*/
#include <iostream>
#include <cstdlib>
#include <string>
#include <iomanip>
#include <time.h>
#include <fstream>
#define myDate "October 20th, 2013 "
#define myActivity "Lab 8 Part 2 "
#define line1 " This program asks the user to select an option "
#define line2 " from a menu. Later on in development, there "
#define line3 " will be further information. "
#define over2 "\t\t"
#define over3 "\t\t\t"
#define over4 "\t\t\t\t"
#define down5 "\n\n\n\n\n"
#define down8 "\n\n\n\n\n\n\n\n"
#define down10 "\n\n\n\n\n\n\n\n\n\n"
#define down12 "\n\n\n\n\n\n\n\n\n\n\n\n"
using namespace std;
int menu();
void menuError (int);
void splash();
void welcome();
void equation(string, int, int, char);
int answer();
int main ()
{
int num1, num2, countRight, countWrong, menuChoice;
const int ADDITION = 1,
SUBTRACTION = 2,
MULTI = 3,
DIV = 4,
MODULUS = 5,
EXIT = 6;
unsigned seed = time(0);
srand(seed);
num1 = 1 +rand() % 10;
num2 = 1 +rand() % 10;
do
{
system("CLS");
menuChoice = menu ();
switch (menuChoice)
{
case 1: system("CLS");
cout << down5 << over4;
equation(num1,num2,'+',"Addition");
cout << answer();
system("PAUSE");
break;
case 2: cout << "Subtraction";
break;
case 3: cout << "Multiplication";
break;
case 4: cout << "Division";
break;
case 5: cout << "Modulus";
break;
case 6: cout << "Exit";
break;
}
}while (menuChoice != EXIT);
}
void equation(int num1, int num2, char symbol, string operation)
{
cout << down8;
cout << over4 << operation << endl
<< over4 << "---------" << endl;
cout << over4 << ' ' << setw(3) << num1 << endl
<< over4 << symbol << setw(3) << num2 << endl
<< over4 << "----" << endl << over4;
cin >> userAnswer;
}
int menu ()
{
int menuChoice;
cout << down5;
cout << over3 << "1. Addition \n";
cout << over3 << "2. Subtraction \n";
cout << over3 << "3. Multiplication \n";
cout << over3 << "4. Integer Division \n";
cout << over3 << "5. Modulus \n";
cout << over3 << "6. Exit \n";
cout << over3 << " option: ";
cin >> menuChoice;
return(menuChoice);
}
void splash ()
{
system("CLS");
cout << "\n\n\n"
<< "\n\t\t _ "
<< "\n\t\t (_) _ "
<< "\n\t\t _ .=. (_) "
<< "\n\t\t (_) _ //(`)_ \"By blood a king, "
<< "\n\t\t //`\\/ |\\ 0`\\\\ in heart a clown.\" "
<< "\n\t\t ||-.\\_|_/.-|| ~Alfred Lord Tennyson"
<< "\n\t\t )/ |_____| \\( _ "
<< "\n\t\t 0 #/\\ /\\# 0 (_) "
<< "\n\t\t _| o o |_ "
<< "\n\t\t _ ((|, ^ ,|)) "
<< "\n\t\t (_) `||\\_/||` "
<< "\n\t\t || _ || _ "
<< "\n\t\t | \\_/ | (_) "
<< "\n\t\t 0.__.\\ /.__.0 "
<< "\n\t\t `._ `\"` _.' "
<< "\n\t\t kkr / ; \\ \\ "
<< "\n\t\t 0'-' )/`'-0 "
<< "\n\t\t 0` "
<< "\n\n\n";
system("PAUSE");
}
void welcome()
{
system("CLS");
cout << "\n\n\n";
cout << "\n\t/--------------------------------------------------------------\\";
cout << "\n\t| About This Program |";
cout << "\n\t+--------------------------------------------------------------+";
cout << "\n\t| |";
cout << "\n\t| |";
cout << "\n\t| Programmer's Name: Kris Rossman |";
cout << "\n\t| Date: "myDate "|";
cout << "\n\t| Name of program: "myActivity "|";
cout << "\n\t| |";
cout << "\n\t| /-------------------- Description --------------------\\ |";
cout << "\n\t| | " line1 " | |";
cout << "\n\t| | " line2 " | |";
cout << "\n\t| | " line3 " | |";
cout << "\n\t| \\-----------------------------------------------------/ |";
cout << "\n\t| |";
cout << "\n\t| |";
cout << "\n\t| |";
cout << "\n\t\\--------------------------------------------------------------/";
cout << "\n\n\n";
system("PAUSE");
}
|