This repository has been archived by the owner on Oct 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calculator8.cpp
67 lines (62 loc) · 1.52 KB
/
Calculator8.cpp
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
// Lab 8a, Write And Apply A Stack Template
// Programmer: Minos Park
// Editor(s) used: Sublime Text 2
// Compiler(s) used: G++
#include <iostream>
using namespace std;
#include <cstring>
#include "Stack.h"
int main()
{
// print my name and this assignment's title
cout << "Lab 8a, Write And Apply A Stack Template\n";
cout << "Programmer: Minos Park\n";
cout << "Editor(s) used: Sublime Text 2\n";
cout << "Compiler(s) used: G++\n";
cout << "File: " << __FILE__ << endl;
cout << "Complied: " << __DATE__ << " at " << __TIME__ << endl << endl;
float num, a, b;
char buf[100];
Stack<float> calc, calc_out;
while(1)
{
cout << "Enter: ";
if (!calc.empty()) calc_out = calc;
while (!calc_out.empty())
{
cout << calc_out.peek() << " ";
calc_out.pop();
}
cin >> buf;
if (buf[0] == 'q' || buf[0] == 'Q') return 0;
else if (buf[0] == '+' || buf[0] == '-' || buf[0] == '*' || buf[0] == '/')
{
if(calc.size() < 2)
{
continue;
}
else
{
b = calc.peek(); calc.pop();
a = calc.peek(); calc.pop();
switch (buf[0])
{
case'+':
calc.push(a + b); continue;
case '-':
calc.push(a - b); continue;
case '*':
calc.push(a * b); continue;
case '/':
calc.push(a / b); continue;
}
}
}
else
{
num = atof(buf);
cin.ignore(numeric_limits<streamsize>::max(), '\n');
calc.push(num);
}
}
}