-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
244 lines (201 loc) · 7.17 KB
/
main.cpp
File metadata and controls
244 lines (201 loc) · 7.17 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
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
//
// Created by Daniel Lipszyc on 4/18/25.
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <SFML/Graphics.hpp>
#include "MergeSort.h"
using namespace std;
void extractBMIsFromFile(vector<Patient*> &list) {
ifstream file("../heart_attack_dataset.csv");
if (!file.is_open()) {
cerr << "Error: Could not open file 'ONE'." << endl;
return;
}
string line;
getline(file, line); // skip header
int count = 0;
while (getline(file, line)) {
size_t start = 0;
size_t end = 0;
int index = 0;
float bmi = 0;
int stressLevel = 0;
int outcome = 0;
string token;
while (end != string::npos && index <= 31) {
end = line.find(',', start);
token = line.substr(start, end - start);
if (index == 5) {
bmi = stof(token);
}
else if(index == 13){
stressLevel = stoi(token);
}
else if (index == 31) {
outcome = (token == "Heart Attack") ? 1 : 0;
break;
}
start = end + 1;
++index;
}
Patient* P = new Patient(bmi, outcome, stressLevel);
list.push_back(P);
++index;
count++;
}
file.close();
}
string RadixSort(int value) {
//Add code for Radix Sort
return "Value Radix";
//Return string
}
string MergeSort(int value) {
//Add code for Merge Sort
int num = 1;
vector<Patient*> Patients = {};
//extractBMIsFromFile(Patients);
time_t start, end;
time(&start);
//radixSort(Patients);
//mergeSort(Patients, 0, Patients.size() - 1);
time(&end);
int input_BMI;
cout << "Enter a number between 20 and 40: ";
//cin >> input_BMI;
for(Patient* p : Patients){
cout << num << ". " << "BMI: " << p->BMI << " Outcome: " << p->HAO << endl;
num++;
}
cout << difftime(end, start) << endl;
return "VAlue Merge";
//Return string
}
int main() {
// Create the main window
sf::RenderWindow window(sf::VideoMode({800, 500}), "SFML window", sf::Style::Titlebar | sf::Style::Close);
//Set main banner
sf::Font fontTitle;
fontTitle.loadFromFile("C:/Windows/Fonts/arial.ttf");
sf::Text textTitle; // a font is required to make a text object
textTitle.setFont(fontTitle);
textTitle.setString("Merge Sort vs Radix Sort");
textTitle.setCharacterSize(30); // in pixels, not points!
textTitle.setFillColor(sf::Color::Blue);
textTitle.setStyle(sf::Text::Bold | sf::Text::Underlined);
textTitle.setPosition((window.getSize().x / 2)- 190, 50);
//Enter Value Label
sf::Font fontLabel;
fontLabel.loadFromFile("C:/Windows/Fonts/arial.ttf");
sf::Text textLabel; // a font is required to make a text object
textLabel.setFont(fontLabel);
textLabel.setString("Enter Value: ");
textLabel.setCharacterSize(20); // in pixels, not points!
textLabel.setFillColor(sf::Color::Blue);
textLabel.setStyle(sf::Text::Bold);
textLabel.setPosition(150, 200);
//Enter Value Text
sf::Font fontInput;
fontInput.loadFromFile("C:/Windows/Fonts/arial.ttf");
sf::Text textInput; // a font is required to make a text object
textInput.setFont(fontInput);
textInput.setString("12");
textInput.setCharacterSize(20); // in pixels, not points!
textInput.setFillColor(sf::Color::Blue);
textInput.setPosition(300, 200);
//Result Label
sf::Font fontResultLabel;
fontResultLabel.loadFromFile("C:/Windows/Fonts/arial.ttf");
sf::Text textResultLabel; // a font is required to make a text object
textResultLabel.setFont(fontResultLabel);
textResultLabel.setString("Result Value: ");
textResultLabel.setCharacterSize(20); // in pixels, not points!
textResultLabel.setFillColor(sf::Color::Black);
textResultLabel.setStyle(sf::Text::Bold);
textResultLabel.setPosition(100, 420);
//Result Label
sf::Font fontResultValue;
fontResultValue.loadFromFile("C:/Windows/Fonts/arial.ttf");
sf::Text textResultValue; // a font is required to make a text object
textResultValue.setFont(fontResultValue);
textResultValue.setCharacterSize(20); // in pixels, not points!
textResultValue.setFillColor(sf::Color::Black);
textResultValue.setStyle(sf::Text::Bold);
textResultValue.setPosition(240, 420);
//Radix Button
sf::Texture radixTexture;
radixTexture.loadFromFile("../btnradixsort.png");
sf::Sprite radixSprite(radixTexture);
radixSprite.setPosition(sf::Vector2f(100,300));
//Merge Button
sf::Texture mergeTexture;
mergeTexture.loadFromFile("../btnmergesort.png");
sf::Sprite mergeSprite(mergeTexture);
mergeSprite.setPosition(sf::Vector2f(468,300));
string input_text;
string output_text;
// Start the game loop
sf::Clock clock;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
if (event.type == sf::Event::MouseButtonPressed) {
if (event.mouseButton.button == sf::Mouse::Left) {
sf::Vector2i mousePos = sf::Mouse::getPosition(window);
if ((mousePos.x >= 100 ) && (mousePos.x <= 332 )
&& (mousePos.y >= 300 ) && (mousePos.y <= 382 )) {
output_text =RadixSort(stoi(input_text));
textResultValue.setString(output_text);
}
if ((mousePos.x >= 468 ) && (mousePos.x <= 700 )
&& (mousePos.y >= 300 ) && (mousePos.y <= 382 )) {
output_text =MergeSort(stoi(input_text));
textResultValue.setString(output_text);
}
}
}
if (event.type == sf::Event::TextEntered) {
if (std::isprint(event.text.unicode))
input_text += event.text.unicode;
}
else if (event.type == sf::Event::KeyPressed) {
if (event.key.code == sf::Keyboard::BackSpace) {
if (!input_text.empty())
input_text.pop_back();
}
if (event.key.code == sf::Keyboard::Return) {
input_text += '\n';
}
}
}
static sf::Time text_effect_time;
static bool show_cursor;
text_effect_time += clock.restart();
if (text_effect_time >= sf::seconds(0.5f))
{
show_cursor = !show_cursor;
text_effect_time = sf::Time::Zero;
}
textInput.setString(input_text + (show_cursor ? '_' : ' '));
// Clear screen
window.clear();
// Update the window
window.clear(sf::Color::White);
window.draw(textTitle);
window.draw(textLabel);
window.draw(textInput);
window.draw(radixSprite);
window.draw(mergeSprite);
window.draw(textResultLabel);
window.draw(textResultValue);
window.display();
}
return 0;
}