From 3f746d08c7dc5e9b936879b53d8e7e56489c9b83 Mon Sep 17 00:00:00 2001 From: Brock Jenkinson Date: Mon, 18 Nov 2024 14:30:20 -0500 Subject: [PATCH 1/4] Changed Subject struct and switched to using namespace std -Using int64_t to store large ints for time. --- src/main.cpp | 1 + src/tracker.h | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 17ed20c..b9459d1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,6 +10,7 @@ int main() { std::vector subjects; //make a dynamic array to hold subjects using a container loadSubjects(subjects); //this will load the subjects from the file, using the function from tracker.cpp + //idea: ask user for name, store subjects file under name to check if it exists addSubject(subjects); } \ No newline at end of file diff --git a/src/tracker.h b/src/tracker.h index 77b4e99..627bcf1 100644 --- a/src/tracker.h +++ b/src/tracker.h @@ -1,15 +1,20 @@ #include #include +using namespace std; //decided this would be easier than typing std:: before everything, and we aren't using any other namespaces // Example struct for a Subject object just to get us started struct Subject { - std::string name; - int hoursStudied; -// int grade; //i don't know if we are going to use this yet, but i'm putting it here just in case + string name; + int64_t timeInSeconds; //storing time as seconds, will convert to minutes for display. Using int64_t to avoid issues with larger numbers. + vector tasks; //we will use a vector to hold the tasks + //int grade; //i don't know if we are going to use this yet, but i'm putting it here just in case }; //function prototypes -void loadSubjects(std::vector& subjects); //this will load the array of subjects from our subjects.txt file +void loadSubjects(vector& subjects); //this will load the array of subjects from our subjects.txt file void saveSubjects(/*filler declaration*/); //this will save the array of subjects to our subjects.txt file -void addSubject(std::vector& subjects); //this will add a subject to the array of subjects -void welcomeMessage(std::string name); //this will print the welcome message \ No newline at end of file +void addSubject(vector& subjects); //this will add a subject to the array of subjects +void addTask(Subject& name) //take the subject, add the task to it and return +void welcomeMessage(string name); //this will print the welcome message +void displayView(string name); //print name (string), tasks (vector), time (int), call convertTime() +void convertTime(); //turn seconds to minutes for the display view From 3fedaa688c01b80cf3200b8109eabd60b56ecc2f Mon Sep 17 00:00:00 2001 From: Brock Jenkinson Date: Mon, 18 Nov 2024 14:49:06 -0500 Subject: [PATCH 2/4] Added function prototypes for CSV parsing. Need to write the actual functions next in tracker.cpp --- src/tracker.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/tracker.h b/src/tracker.h index 627bcf1..3e3bb5e 100644 --- a/src/tracker.h +++ b/src/tracker.h @@ -10,11 +10,26 @@ struct Subject { //int grade; //i don't know if we are going to use this yet, but i'm putting it here just in case }; -//function prototypes +/*Function Prototypes*/ void loadSubjects(vector& subjects); //this will load the array of subjects from our subjects.txt file void saveSubjects(/*filler declaration*/); //this will save the array of subjects to our subjects.txt file void addSubject(vector& subjects); //this will add a subject to the array of subjects -void addTask(Subject& name) //take the subject, add the task to it and return +void addTask(Subject& name); //take the subject, add the task to it and return void welcomeMessage(string name); //this will print the welcome message void displayView(string name); //print name (string), tasks (vector), time (int), call convertTime() void convertTime(); //turn seconds to minutes for the display view + +/*CSV Parsing Prototypes*/ +vector parseTaskArray(const string& taskString); //parse the string of tasks into a vector of strings +string formatTaskArray(const vector& tasks); //format the vector of tasks into a string so it can be written to the csv +Subject parseRow(const string& csvLine); //parse a row of the csv into a Subject object using the struct +string formatRow(const Subject& subject); //formats a Subject object into a string +void readCSV(vector& subjects); //reads the csv file and fills the vector of subjects +void writeCSV(const vector& subjects); //writes to the csv file with the vector of subjects + +/* +Example CSV file (putting this here so we can finish the actual functions to use this format) +subject_name,time_in_seconds,[task1,task2,task3] +Math,3600,[Review calculus,Practice integrals] +Physics,7200,[Read chapter 1,Lab prep] +*/ \ No newline at end of file From 7800a12ffed9feca7a9bee36dd861ed06e78a843 Mon Sep 17 00:00:00 2001 From: Brock Jenkinson Date: Mon, 18 Nov 2024 14:49:26 -0500 Subject: [PATCH 3/4] Updated loadSubjects function to switch from subjects.txt to subjects.csv for file handling --- src/tracker.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/tracker.cpp b/src/tracker.cpp index 0b9f70f..e792a55 100644 --- a/src/tracker.cpp +++ b/src/tracker.cpp @@ -2,16 +2,17 @@ #include #include -//here we will put the actual function definitions for main.cpp to use (protypes in tracker.h) +//here we will put the actual function definitions for main.cpp to use (prototypes in tracker.h) -/*this will load the array of subjects from our subjects.txt file*/ +/*this will load the array of subjects from our subjects.txt file*/ +/* NEED TO SWITCH TO A CSV FILE */ void loadSubjects(std::vector &subjects) { //make a dynamic array to hold subjects using a container std::cout << "Loading subjects..." << std::endl; //loading message to show that the program is working - std::ifstream inFile("subjects.txt"); // open file for reading + std::ifstream inFile("subjects.csv"); // open file for reading //check if the file exists if (!inFile) { //if the file does not exist std::cout << "Error: No Such File Exists. Creating New File" << std::endl; //print the error message - std::ofstream outFile("subjects.txt"); //use ofstream to make a new blank text file + std::ofstream outFile("subjects.csv"); //use ofstream to make a new blank text file return; //return nothing if the file does not exist } //read the file if it exists From dfb617347021d06658e7a377c9c6f5a2a8b4cfd2 Mon Sep 17 00:00:00 2001 From: Brock Jenkinson Date: Mon, 18 Nov 2024 14:49:28 -0500 Subject: [PATCH 4/4] Add src/.vscode/settings.json to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index aee1d95..b4a18f8 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ *.out *.app .vscode/tasks.json +src/.vscode/settings.json