-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstack.cpp
More file actions
131 lines (113 loc) · 3.37 KB
/
Copy pathstack.cpp
File metadata and controls
131 lines (113 loc) · 3.37 KB
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
#include "WindowsAPI.h"
#include <stack>
#include <iostream>
using namespace std;
linkedList catalog;
StackNode::StackNode(float revenue, string name, int quantity, float price)
{
this->revenue = revenue;
this->name = name;
this->quantity = quantity;
this->price = price;
this->next = nullptr;
}
void Stack::push(float revenue, string name, int quantity, float price){
StackNode* temp = new StackNode(revenue, name, quantity, price);
if (!temp) {
cout << "\nStack Overflow";
exit(1);
}
temp->next = top;
top = temp;
}
void Stack::pop() {
if (top == nullptr) {
cout << "\nStack Underflow" << endl;
return;
}
StackNode* temp = top;
top = top->next;
delete temp;
}
char* Stack::printStack() {
StackNode* current = top;
char stackOut[10000];
stackOut[0] = '\0';
int i = 1;
strcpy(stackOut, "Sale History: \r\n");
while (current != nullptr) {
int S_IndLen = 0;
int S_QtyLen = 0;
int S_PriceLen = 0;
char S_anotherI[5000];
sprintf(S_anotherI, "%1d", i);
while (S_anotherI[S_IndLen] != '\0')
{
S_IndLen++;
}
char S_anotherQty[5000];
sprintf(S_anotherQty, "%1d", current->quantity);
while (S_anotherQty[S_QtyLen] != '\0')
{
S_QtyLen++;
}
char S_anotherPrice[5000];
sprintf(S_anotherPrice, "%.2f", current->price);
while (S_anotherPrice[S_PriceLen] != '\0')
{
S_PriceLen++;
}
char S_anotherTotalPrice[5000];
sprintf(S_anotherTotalPrice, "%.2f", current->revenue);
string S_name = current->name;
int S_length = S_name.length();
char* S_anotherName = new char[S_length + 1];
strcpy(S_anotherName, S_name.c_str());
char No[] = {"No"};
char Revenue[] = {"Revenue"};
char Name[] = {"Name"};
char Quantity[] = {"Quantity"};
char Price[] = {"Price"};
strcat(stackOut, catalog.PrintCategoryHeader(No, Name, Quantity, Price, Revenue,
S_IndLen, S_length, S_QtyLen, S_PriceLen));
strcat(stackOut, S_anotherI);
strcat(stackOut, ".\t");
strcat(stackOut, S_anotherName);
strcat(stackOut, "\t");
strcat(stackOut, S_anotherQty);
strcat(stackOut, "\t");
strcat(stackOut, S_anotherPrice);
strcat(stackOut, "\t");
strcat(stackOut, S_anotherTotalPrice);
strcat(stackOut, "\r\n");
current = current->next;
delete[] S_anotherName;
i++;
strcat(stackOut, "\r\n");
}
strcat(stackOut, PrintTotal());
strcat(stackOut, "\r\n");
return strdup(stackOut);
}
char* Stack::PrintTotal()
{
float totalrev = 0;
StackNode* current = top;
while (current != nullptr)
{
totalrev = totalrev + current->revenue;
current = current->next;
}
char TotalRev[1000], TotalRevOut[1001];
sprintf(TotalRev, "%.2f", totalrev);
strcpy(TotalRevOut, "Current Total = ");
strcat(TotalRevOut, TotalRev);
return strdup(TotalRevOut);
}
void Stack::clearStack() {
while (top != nullptr) {
StackNode* temp = top;
top = top->next;
delete temp;
}
}