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 168 169 170 171
|
#include <iostream>
#include <sstream>
#include <vector>
#include "Double.h"
#include "Integer.h"
#include "Menu.h"
using namespace std;
using Norman::Double;
using Norman::Integer;
using Norman::Menu;
void doubleCheck();
void doubleAdd();
void doubleSub();
void doubleMul();
void doubleDiv();
void intCheck();
void intAdd();
void intSub();
void intMul();
void intDiv();
void Exit();
int main()
{
Menu *m = Menu::Instance();
m->addMenu("1. Add Doubles.", doubleAdd);
m->addMenu("2. Sub Doubles.", doubleSub);
m->addMenu("3. Mul Doubles.", doubleMul);
m->addMenu("4. Div Doubles.", doubleDiv);
m->addMenu("5. Add Integers.", intAdd);
m->addMenu("6. Sub Integers.", intSub);
m->addMenu("7. Mul Integers.", intMul);
m->addMenu("8. Div Integers.", intDiv);
m->addMenu("9. Check doubles.", doubleCheck);
m->addMenu("10. Check Integers.", intCheck);
m->addMenu("11. Exit.", Exit);
m->runMenu();
return 0;
}
void doubleCheck()
{
string s;
Double d;
cout << "Please enter a double." << endl;
cin >> s;
d.equals(s);
if (d.isNan())
cout << "Cannot assign a non-number to class Double" << endl;
if (d.isNan() == false)
cout << "Valid number set to " << d.toString() << endl;
Menu *m = Menu::Instance();
m->waitKey();
}
void intCheck()
{
string s;
Integer i;
cout << "Please enter an integer." << endl;
cin >> s;
i.equals(s);
if (i.isNaN())
cout << "Cannot assign a non-number to class Integer." << endl;
if (i.isNaN() == false)
cout << "Valid number set to " << i.toString() << endl;
Menu *m = Menu::Instance();
m->waitKey();
}
void doubleAdd()
{
Double d, d2, d3;
cout << "Enter your first double." << endl;
cin >> d;
cout << "Enter your second double." << endl;
cin >> d2;
d3 = d + d2;
cout << d3.toDouble() << endl;
Menu *m = Menu::Instance();
m->waitKey();
}
void doubleSub()
{
Double d, d2, d3;
cout << "Enter your first double." << endl;
cin >> d;
cout << "Enter your second double." << endl;
cin >> d2;
d3 = d - d2;
cout << d3.toDouble() << endl;
Menu *m = Menu::Instance();
m->waitKey();
}
void doubleMul()
{
Double d, d2, d3;
cout << "Enter your first double." << endl;
cin >> d;
cout << "Enter your second double." << endl;
cin >> d2;
d3 = d * d2;
cout << d3.toDouble() << endl;
Menu *m = Menu::Instance();
m->waitKey();
}
void doubleDiv()
{
Double d, d2, d3;
cout << "Enter your first double." << endl;
cin >> d;
cout << "Enter your second double." << endl;
cin >> d2;
d3 = d / d2;
cout << d3.toDouble() << endl;
Menu *m = Menu::Instance();
m->waitKey();
}
void intAdd()
{
Integer i, i2, i3;
cout << "Enter your first Integer." << endl;
cin >> i;
cout << "Enter your second Integer." << endl;
cin >> i2;
i3 = i + i2;
cout << i3.toInt() << endl;
Menu *m = Menu::Instance();
m->waitKey();
}
void intSub()
{
Integer i, i2, i3;
cout << "Enter your first Integer." << endl;
cin >> i;
cout << "Enter your second Integer." << endl;
cin >> i2;
i3 = i - i2;
cout << i3.toInt() << endl;
Menu *m = Menu::Instance();
m->waitKey();
}
void intMul()
{
Integer i, i2, i3;
cout << "Enter your first Integer." << endl;
cin >> i;
cout << "Enter your second Integer." << endl;
cin >> i2;
i3 = i * i2;
cout << i3.toInt() << endl;
Menu *m = Menu::Instance();
m->waitKey();
}
void intDiv()
{
Integer i, i2, i3;
cout << "Enter your first Integer." << endl;
cin >> i;
cout << "Enter your second Integer." << endl;
cin >> i2;
i3 = i / i2;
cout << i3.toInt() << endl;
Menu *m = Menu::Instance();
m->waitKey();
}
void Exit()
{
cout << "Thanks for using the program." << endl;
exit(0);
}
| |