-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompound Data Types Project.cpp
202 lines (155 loc) · 5 KB
/
Compound Data Types Project.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
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// 11/27/19 - Ben Grudzien
// This is very similar to my previous project relative to output. However, this code uses pointers, data structures
// and dynamic arrays.
#include <iostream>
#include <stdio.h>
#include <stdlib.h> // Allows the flush funciton, clears the terminal screen
#include <string>
#include <sstream> // Converts the string input from the user to a boolean value
#include <string>
#include <vector> // Dynamic array library
using namespace std;
int selection;
int * s_ptr;
int n = 1;
string mystr;
bool a;
bool b;
bool output; // Stores bits to be operated on
bool OPERATION_OUT; // Stores operation values
vector<int> history; // dynamic array basically
struct operation { // data structure
string all_ops;
} AND, NAND, OR, NOR, XOR, XNOR;
void print_operations(operation display)
{
cout << display.all_ops; // uses data structure to display variables
}
void display_all()
{
print_operations(NAND);
print_operations(OR);
print_operations(NOR);
print_operations(XOR);
print_operations(XNOR);
print_operations(AND);
}
void Previous_Bits()
{
int h = 1;
for (int n : history)
{
cout << n;
if (h % 2 == 0) // Formats how history is displayed
{
cout << "\n";
}
h++;
}
cout << "\n";
}
int main()
{
//void clear() noexcept; // Clears history from past executions
s_ptr = &selection;
bool * a_ptr;
a_ptr = &a;
bool * b_ptr;
b_ptr = &b;
bool * out_ptr;
out_ptr = &output;
bool * op_ptr;
op_ptr = &OPERATION_OUT;
AND.all_ops = "AND => a b output\n 0 0 0 \n 0 1 0 \n"
" 1 0 0 \n 1 1 1 \n--------------------\n";
NAND.all_ops = "NAND => a b output\n 0 0 1 \n 0 1 1 \n"
" 1 0 1 \n 1 1 0 \n--------------------\n";
OR.all_ops = "OR => a b output\n 0 0 0 \n 0 1 1 \n"
" 1 0 1 \n 1 1 1 \n--------------------\n";
NOR.all_ops = "NOR => a b output\n 0 0 1 \n 0 1 0 \n"
" 1 0 0 \n 1 1 0 \n--------------------\n";
XOR.all_ops = "XOR => a b output\n 0 0 0 \n 0 1 1 \n"
" 1 0 1 \n 1 1 0 \n--------------------\n";
XNOR.all_ops = "XNOR => a b output\n 0 0 1 \n 0 1 0 \n"
" 1 0 0 \n 1 1 1 \n--------------------\n";
while (1)
{
cout << "Currently entered bits: " << *a_ptr << *b_ptr << "\n\n";
cout << "Enter the corresponding number to select option: \n"
" 1 : Change Bits\n 2 : Display all operators \n 3 : AND\n 4 : NAND\n"
" 5 : OR\n 6 : NOR\n 7 : XOR\n 8 : XNOR\n 9 : History\n 10: Exit Program\n=> ";
cin >> *s_ptr; // selects new option
switch (*s_ptr)
{
case 1:
system("CLS");
cout << flush; // Clears previous stuff displayed on terminal window
cout << "ENTER TWO BITS (seperated by a space)\n => ";
cin >> *a_ptr >> *b_ptr;
cout << "--------------------\n" << "You entered = " << *a_ptr << *b_ptr << "\n--------------------\n\n";
mystr = *a_ptr;
mystr += " ";
mystr += *b_ptr;
mystr += "\n";
history.push_back(*a_ptr); // stores previoulsy entered bits
history.push_back(*b_ptr);
break;
case 2:
system("CLS");
cout << flush; // Clears previous stuff displayed on terminal window
display_all();
break;
case 3:
system("CLS");
cout << flush; // Clears previous stuff displayed on terminal window
print_operations(AND);
*op_ptr = (*a_ptr & *b_ptr);
cout << *a_ptr << " AND " << *b_ptr << " = " << *op_ptr << "\n--------------------\n\n";
break;
case 4:
system("CLS");
cout << flush; // Clears previous stuff displayed on terminal window
print_operations(NAND);
*op_ptr = !(*a_ptr & *b_ptr);
cout << *a_ptr << " NAND " << *b_ptr << " = " << *op_ptr << "\n--------------------\n\n";
break;
case 5:
system("CLS");
cout << flush; // Clears previous stuff displayed on terminal window
print_operations(OR);
*op_ptr = (*a_ptr | *b_ptr);
cout << *a_ptr << " OR " << *b_ptr << " = " << *op_ptr << "\n--------------------\n\n";
break;
case 6:
system("CLS");
cout << flush; // Clears previous stuff displayed on terminal window
print_operations(NOR);
*op_ptr = !(*a_ptr & *b_ptr);
cout << *a_ptr << " NOR " << *b_ptr << " = " << *op_ptr << "\n--------------------\n\n";
break;
case 7:
system("CLS");
cout << flush; // Clears previous stuff displayed on terminal window
print_operations(XOR);
*op_ptr = (*a_ptr ^ *b_ptr);
cout << *a_ptr << " XOR " << *b_ptr << " = " << *op_ptr << "\n--------------------\n\n";
break;
case 8:
system("CLS");
cout << flush; // Clears previous stuff displayed on terminal window
print_operations(XNOR);
*op_ptr = !(*a_ptr ^ *b_ptr);
cout << *a_ptr << " XNOR " << *b_ptr << " = " << *op_ptr << "\n--------------------\n\n";
break;
case 9:
system("CLS");
cout << flush; // Clears previous stuff displayed on terminal window
cout << "Previously Entered Bits (Oldest to Newest)\n";
Previous_Bits();
break;
case 10:
exit(0);
}
}
return 0;
}