Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@
*.out
*.app
.vscode/tasks.json
src/.vscode/settings.json
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ int main() {
std::vector<Subject> 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);
addSubject(subjects);
Expand Down
9 changes: 5 additions & 4 deletions src/tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
#include <fstream>
#include <algorithm>

//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<Subject> &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
Expand Down
40 changes: 27 additions & 13 deletions src/tracker.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
#include <string>
#include <vector>

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;
std::vector<std::string> tasks;
int hoursStudied;
// int grade; // Uncomment if needed later
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<string> 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

// Constructor to initialize name and hoursStudied
Subject(const std::string& name = "", int hoursStudied = 0)
: name(name), hoursStudied(hoursStudied) {}
};

//function prototypes
void loadSubjects(std::vector<Subject>& subjects); //this will load the array of subjects from our subjects.txt file
/*Function Prototypes*/
void loadSubjects(vector<Subject>& 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<Subject>& subjects); //this will add a subject to the array of subjects
void addTask(std::vector<Subject>& subjects); //this will add a task to a single subject
void welcomeMessage(std::string name); //this will print the welcome message
bool inputCheck(std::string& str); //this will check to see that there are no special characters in an input
void addSubject(vector<Subject>& 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

/*CSV Parsing Prototypes*/
vector<string> parseTaskArray(const string& taskString); //parse the string of tasks into a vector of strings
string formatTaskArray(const vector<string>& 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<Subject>& subjects); //reads the csv file and fills the vector of subjects
void writeCSV(const vector<Subject>& 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]
*/