Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jhammerberg committed Aug 25, 2024
0 parents commit 55a0863
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"cStandard": "c17",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-x64",
"compilerPath": "/usr/bin/g++"
}
],
"version": 4
}
56 changes: 56 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"files.associations": {
"*.bc": "ini",
"iostream": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"codecvt": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"random": "cpp",
"ratio": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"typeinfo": "cpp"
}
}
1 change: 1 addition & 0 deletions Festifall Cardreader.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Time,Name,Email,UMID,Card ID
4 changes: 4 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
g++ main.cpp -std=c++17 -o card_reader_linux_x86 --static
aarch64-linux-gnu-g++ main.cpp -std=c++17 -o card_reader_arm --static
x86_64-w64-mingw32-g++ main.cpp -std=c++17 -o card_reader_windows_x64 --static
Binary file added card_reader_arm
Binary file not shown.
Binary file added card_reader_linux_x86
Binary file not shown.
Binary file added card_reader_windows_x64.exe
Binary file not shown.
107 changes: 107 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
#include <iomanip>
#include <sstream>
#include <filesystem>

using namespace std;
namespace fs = std::filesystem;

struct Student {
string name;
string email;
string umid;
string cardID;
};

string getCurrentTime() {
std::time_t now = std::time(nullptr);
std::tm* localTime = std::localtime(&now);

std::ostringstream oss;
oss << std::put_time(localTime, "%Y-%m-%d %H:%M:%S");
return oss.str();
}

Student parseStudent(string input) {
// Example input: %B6008475938410415^HAMMERBERG/J^2806120JACKMH?;6008475938410415=2806120=816877446?
// Name: J HAMMERBERG
// Email: [email protected]
// UMID: 59384104
// Card ID: 6008475938410415
Student student;
size_t start, end;
// Get the card ID
start = input.find("%") + 2;
end = input.find("^");
student.cardID = input.substr(start, end - start);
// Get the last name
start = input.find("^") + 1;
end = input.find("/");
string lastName = input.substr(start, end - start);
// Get the first name
start = end + 1;
end = input.find("^", start);
// Concatenate the first and last name to get the full name
student.name = input.substr(start, end - start) + " " + lastName;
// Get the UMID
start = input.find("^") - 10;
end = input.find("^") - 2;
student.umid = input.substr(start, end - start);
// Get the email
start = input.find("^", input.find("/")) + 8; // Find the next ^ after the the / character
end = input.find("?;");
student.email = input.substr(start, end - start) + "@umich.edu";
return student;
}

int main() {
string header = "Time,Name,Email,UMID,Card ID";
string filename = (fs::current_path() / "Festifall Cardreader.csv").string();
ifstream infile(filename);
bool headerMatches = false;

if (infile.is_open()) {
string firstLine;
getline(infile, firstLine);
if (firstLine == header) {
headerMatches = true;
}
infile.close();
}

ofstream file;
if (headerMatches) {
file.open(filename, ios::app);
cout << "Existing file found" << endl;
file.close();
} else {
file.open(filename);
file << header << endl;
cout << "New file created" << endl;
file.close();
}

while (true) {
string input;
cout << "Type 'exit' to stop" << endl;
cout << "Enter student info: ";
cin >> input;
if (input == "exit" || input == "Exit" || input == "EXIT") {
break;
}
Student student = parseStudent(input);
string time = getCurrentTime();
file.open(filename, ios::app);
if (!file.is_open()) {
cout << "Error opening file" << endl;
return 1;
}
file << time << "," << student.name << "," << student.email << "," << student.umid << "," << student.cardID << endl;
cout << time << ", " << student.name << ", " << student.email << ", " << student.umid << ", " << student.cardID << endl;
file.close();
}
return 0;
}

0 comments on commit 55a0863

Please sign in to comment.