Skip to content

Commit 55a0863

Browse files
committed
First commit
0 parents  commit 55a0863

File tree

8 files changed

+184
-0
lines changed

8 files changed

+184
-0
lines changed

.vscode/c_cpp_properties.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Linux",
5+
"includePath": [
6+
"${workspaceFolder}/**"
7+
],
8+
"defines": [],
9+
"cStandard": "c17",
10+
"cppStandard": "gnu++17",
11+
"intelliSenseMode": "linux-gcc-x64",
12+
"compilerPath": "/usr/bin/g++"
13+
}
14+
],
15+
"version": 4
16+
}

.vscode/settings.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"files.associations": {
3+
"*.bc": "ini",
4+
"iostream": "cpp",
5+
"array": "cpp",
6+
"atomic": "cpp",
7+
"bit": "cpp",
8+
"*.tcc": "cpp",
9+
"cctype": "cpp",
10+
"chrono": "cpp",
11+
"clocale": "cpp",
12+
"cmath": "cpp",
13+
"codecvt": "cpp",
14+
"compare": "cpp",
15+
"concepts": "cpp",
16+
"cstdarg": "cpp",
17+
"cstddef": "cpp",
18+
"cstdint": "cpp",
19+
"cstdio": "cpp",
20+
"cstdlib": "cpp",
21+
"ctime": "cpp",
22+
"cwchar": "cpp",
23+
"cwctype": "cpp",
24+
"deque": "cpp",
25+
"string": "cpp",
26+
"unordered_map": "cpp",
27+
"vector": "cpp",
28+
"exception": "cpp",
29+
"algorithm": "cpp",
30+
"functional": "cpp",
31+
"iterator": "cpp",
32+
"memory": "cpp",
33+
"memory_resource": "cpp",
34+
"numeric": "cpp",
35+
"random": "cpp",
36+
"ratio": "cpp",
37+
"string_view": "cpp",
38+
"system_error": "cpp",
39+
"tuple": "cpp",
40+
"type_traits": "cpp",
41+
"utility": "cpp",
42+
"fstream": "cpp",
43+
"initializer_list": "cpp",
44+
"iomanip": "cpp",
45+
"iosfwd": "cpp",
46+
"istream": "cpp",
47+
"limits": "cpp",
48+
"new": "cpp",
49+
"numbers": "cpp",
50+
"ostream": "cpp",
51+
"sstream": "cpp",
52+
"stdexcept": "cpp",
53+
"streambuf": "cpp",
54+
"typeinfo": "cpp"
55+
}
56+
}

Festifall Cardreader.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Time,Name,Email,UMID,Card ID

build.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
g++ main.cpp -std=c++17 -o card_reader_linux_x86 --static
3+
aarch64-linux-gnu-g++ main.cpp -std=c++17 -o card_reader_arm --static
4+
x86_64-w64-mingw32-g++ main.cpp -std=c++17 -o card_reader_windows_x64 --static

card_reader_arm

2.25 MB
Binary file not shown.

card_reader_linux_x86

2.54 MB
Binary file not shown.

card_reader_windows_x64.exe

2.91 MB
Binary file not shown.

main.cpp

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#include <iostream>
2+
#include <fstream>
3+
#include <string>
4+
#include <ctime>
5+
#include <iomanip>
6+
#include <sstream>
7+
#include <filesystem>
8+
9+
using namespace std;
10+
namespace fs = std::filesystem;
11+
12+
struct Student {
13+
string name;
14+
string email;
15+
string umid;
16+
string cardID;
17+
};
18+
19+
string getCurrentTime() {
20+
std::time_t now = std::time(nullptr);
21+
std::tm* localTime = std::localtime(&now);
22+
23+
std::ostringstream oss;
24+
oss << std::put_time(localTime, "%Y-%m-%d %H:%M:%S");
25+
return oss.str();
26+
}
27+
28+
Student parseStudent(string input) {
29+
// Example input: %B6008475938410415^HAMMERBERG/J^2806120JACKMH?;6008475938410415=2806120=816877446?
30+
// Name: J HAMMERBERG
31+
32+
// UMID: 59384104
33+
// Card ID: 6008475938410415
34+
Student student;
35+
size_t start, end;
36+
// Get the card ID
37+
start = input.find("%") + 2;
38+
end = input.find("^");
39+
student.cardID = input.substr(start, end - start);
40+
// Get the last name
41+
start = input.find("^") + 1;
42+
end = input.find("/");
43+
string lastName = input.substr(start, end - start);
44+
// Get the first name
45+
start = end + 1;
46+
end = input.find("^", start);
47+
// Concatenate the first and last name to get the full name
48+
student.name = input.substr(start, end - start) + " " + lastName;
49+
// Get the UMID
50+
start = input.find("^") - 10;
51+
end = input.find("^") - 2;
52+
student.umid = input.substr(start, end - start);
53+
// Get the email
54+
start = input.find("^", input.find("/")) + 8; // Find the next ^ after the the / character
55+
end = input.find("?;");
56+
student.email = input.substr(start, end - start) + "@umich.edu";
57+
return student;
58+
}
59+
60+
int main() {
61+
string header = "Time,Name,Email,UMID,Card ID";
62+
string filename = (fs::current_path() / "Festifall Cardreader.csv").string();
63+
ifstream infile(filename);
64+
bool headerMatches = false;
65+
66+
if (infile.is_open()) {
67+
string firstLine;
68+
getline(infile, firstLine);
69+
if (firstLine == header) {
70+
headerMatches = true;
71+
}
72+
infile.close();
73+
}
74+
75+
ofstream file;
76+
if (headerMatches) {
77+
file.open(filename, ios::app);
78+
cout << "Existing file found" << endl;
79+
file.close();
80+
} else {
81+
file.open(filename);
82+
file << header << endl;
83+
cout << "New file created" << endl;
84+
file.close();
85+
}
86+
87+
while (true) {
88+
string input;
89+
cout << "Type 'exit' to stop" << endl;
90+
cout << "Enter student info: ";
91+
cin >> input;
92+
if (input == "exit" || input == "Exit" || input == "EXIT") {
93+
break;
94+
}
95+
Student student = parseStudent(input);
96+
string time = getCurrentTime();
97+
file.open(filename, ios::app);
98+
if (!file.is_open()) {
99+
cout << "Error opening file" << endl;
100+
return 1;
101+
}
102+
file << time << "," << student.name << "," << student.email << "," << student.umid << "," << student.cardID << endl;
103+
cout << time << ", " << student.name << ", " << student.email << ", " << student.umid << ", " << student.cardID << endl;
104+
file.close();
105+
}
106+
return 0;
107+
}

0 commit comments

Comments
 (0)