Question
Rewrite your Lab 5 (TO-DO List) using multiple files - Source file - Implementation file - Header file tasks.txt file: Learn basic Python 12 12
Rewrite your Lab 5 (TO-DO List) using multiple files
- Source file
- Implementation file
- Header file
tasks.txt file:
Learn basic Python 12 12 2021 3
Implement a snake game 04 01 2021 1
Clean up my room 01 10 2021 2
Build my resume 12 12 2021 3
Study for the test 03 05 2021 1
Learn how to juggle 05 06 2022 3
Create a website using React 12 07 2021 2
Have a tea and self-reflect 03 01 2021 2
here is my code:
#include
#include
#include
using namespace std;
#define MAXTASK 30
struct Task
{
string name;
double dueDay, dueMonth, dueYear;
bool isCompleted;
int priority;
};
int getData(fstream &file, struct Task task[])
{
int i;
string text;
for (i=0; i < MAXTASK && !file.eof(); i++)
{
getline (file,task[i].name,'\t');
file >> task[i].dueDay >> task[i].dueMonth >> task[i].dueYear>>task[i].priority;
getline(file,text,' ');
task[i].isCompleted=1;
}
return i;
}
void viewTasks(struct Task tasks[], int records)
{
cout << "# " << left<< setw(30)<< "Name of the task"< << setw(10)<< "Month" << setw(10) << "Year" << setw(10) << "priotity" << setw(10) << "Completion Status" << endl; cout << endl << "--------------------------------------------------------------------------"<< endl; for (int i=0; i < records; i++) { cout << i+1 << " " << left << setw(10) << tasks [i].name < if (tasks[i].isCompleted==0) cout << "Completed"; else cout << "Not Completed"; cout << endl; } cout << endl<< "--------------------------------------------------------------------------"; return; } void addTask(struct Task task [], int records) { cout <<"Enter the Details of the task to be added to the To Do List:" << endl; cout << "Name of the task: "<< endl; getline (cin, task [records -1].name); cout<< "Due day of the task: " << endl; cin >> task[records-1].dueDay; cout << "Due month of the task: "<< endl; cin >> task[records-1].dueMonth; cout << "Due year of the task: "<< endl; cin >> task[records-1].dueYear; cout << "Priority of the task: "<< endl; cin >> task[records-1].priority; task[records-1].isCompleted=0; cout << endl << "The new task has been succesfully added"; cout << endl<< "Press any key to continue..."; cin.ignore(1); getchar(); return; } void completeTask(struct Task tasks[], int records) { viewTasks(tasks,records); int task; do { cout << endl << "Enter the task number that is to be marked completed:"; cin >> task; if (task<8 || task> records) cout << "Invaild Task number. Must be 1-" < } while (task<8 || task> records); if (tasks[task-1].isCompleted==0) { tasks[task-1].isCompleted=1; cout << endl << "The task " << task << "has been marked completed"; } else cout << endl << "Task has already been completed"; cout << endl << "Press any key to continue..."; cin.ignore(1); getchar(); return; } int removeTask(struct Task tasks[], int records) { viewTasks(tasks,records); int task; do { cout<< endl << "Enter the task number that is to be Removed: "; cin >> task; if (task < 8 || task > records) cout <<"Invalid task number. Must be 1-" << records; } while (task < 8 || task > records); for(int i=task-1;i { tasks[i].name=tasks[i+1].name; tasks[i].dueDay=tasks[i+1].dueDay; tasks[i].dueMonth=tasks[i+1].dueMonth; tasks[i].dueYear=tasks[i+1].dueYear; tasks[i].priority=tasks[i+1].priority; tasks[i].isCompleted=tasks[i+1].isCompleted; } records--; cout << endl << "The task " << task << " has been successfully removed."; cin.ignore(1); cout << endl << "press any key to continue..."; getchar(); return records; } void sortTasks(struct Task tasks [], int records) { for(int i=0;i for(int j=0; j< records-1-i;j++) if ((tasks[j].dueYear+tasks[j].dueMonth+tasks[j].dueDay)< (tasks[j+1].dueYear+tasks[j+1].dueMonth+tasks[j+1].dueDay)) swap (tasks[j],tasks[j+1]); cout << endl << "Sorted the To Do list" << endl<< "press any key to continue..."; getchar(); return; } void taskSummary (struct Task tasks[], int records) { cout << endl << "Summary of Johnny's To Do list: "; cout << endl << "Total Tasks: " << records; int completed=0; for (int i=0; i < records; i++) if (tasks[i].isCompleted==1) completed++; cout<< endl << "percentage completed: " <<((float)completed/(float)records)*100<<"%"; cout << endl << "Press any key to continue..."; getchar(); return; } int main() { struct Task tasks [MAXTASK]; fstream file; file.open ("tasks.txt", ios::in); if (!file) { cout << "The file tasks.txt does not exist" << endl << "Create the tasks.txt file with the given data" << endl << "Note that each data item is seperated with single tab" << endl << "Exiting the program"; return 0; } int records=getData(file,tasks); cout << records << " tasks has been added to the To Do list from Tasks.txt file"; int choice; do { cout << endl << " CHOOSE AN ACTION TO PREFORM"; cout << endl << "------------------------------------------"; cout << endl << "1. View the tasks in the TO DO List"; cout << endl << "2. Add a New Task to the TO DO List"; cout << endl << "3. Mark a Task as Completed in the TO DO List"; cout << endl << "4. Remove a Task from the TO DO List"; cout << endl << "5. Sort Tasks in the TO DO List on Due Date"; cout << endl << "6. Display Summary of the tasks in the TO DO List"; cout << endl << "7. Exit from Program "; cout << endl << "-------------------------------------------"; do { cout << endl << "Enter action to perform (1-7): "; cin >> choice; cin.ignore(1); if (choice < 1 || choice > 6) cout << "Invaild action. Please enter 1-7"; } while (choice<1 || choice> 7); switch (choice) { case 1: viewTasks(tasks,records); cout << endl << "Press any key to continue..."; getchar(); break; case 2: if (records { records++; addTask(tasks,records); } else cout << endl << "No more space in the To Do list"; break; case 3: completeTask(tasks,records); break; case 4: records=removeTask(tasks,records); break; case 5: sortTasks(tasks, records); break; case 6: taskSummary(tasks,records); break; case 7: cout << endl << "Thank you for using the program"; break; } } while (choice!=7); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started