Skip to content

TASK 4 TO-DO LIST Build a simple console-based to-do list manager that allows users to add, view, and delete tasks Task Input: Allow users to input tasks they want to add to the list. Add Task: Implement a function to add tasks to the list. View Tasks: Display the list of

Notifications You must be signed in to change notification settings

NBs21/TO-DO-LIST

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Name: TO-DO-LIST

Purpose: Cod Soft TASK-4 (C++)

TO-DO LIST- Build a simple console-based to-do list manager that allows users to add, view, and delete tasks, Task Input: Allow users to input tasks they want to add to the list. Add Task: Implement a function to add tasks to the list. View Tasks: Display the list of tasks with their status (completed or pending). Mark Task as Completed: Allow users to mark tasks as completed. Remove Task: Provide an option to remove tasks from the list.

Author: NURFUL SHAIKH

Created: 21-11-2023

#include #include #include using namespace std; vector pullFile(string fileName); void pushFile(vector totalList, string fileName); bool ifExists(string fileName); void printList(vector totalList, string fileName); int main() { string trash; cout << "\033[2J\033[1;1H"; string fileName; vector totalList; vector names; if (ifExists("lists.txt")){ names = pullFile("lists.txt"); } cout<<"File List: \n"; if(names.size() <= 1){ cout<<"No lists found.\n"; } else{ for(int c = 0; c < names.size(); c++){ cout<<(c+1)<<". "<<names[c]<<"\n"; } } bool flag = true; while (flag){ cout<<"\nEnter the number of the list you would like to load or Enter file name for a new list.\n >", cin>>fileName, cout<<"\n"; if(isdigit(fileName[0])){ int x = fileName[0] - '0'; if(x > 0 && x < names.size()){ fileName = names[x-1]; flag = false; } else{ cout<<"Not a list number.\n"; } } else{ fileName = fileName + ".txt"; names.push_back(fileName); flag = false; } } pushFile(names, "lists.txt");

if (ifExists(fileName)){
    totalList = pullFile(fileName);
}
bool cont = true;
while (cont){
    printList(totalList, fileName);
    int choice = 0;
    cout<<"What would you like to do?\n";
    cout<<"1. Add item.\n";
    cout<<"2. Remove item.\n";
    cout<<"3. Quit.\n";
    cout<<">", cin>>choice, cout<<"\n";
    while(cin.fail()){
        cin.ignore();
        cin.clear();
        rewind(stdin);
        cout<<">", cin>>choice, cout<<"\n";
    }
    if(choice == 1){
        string newItem;
        cout<<"Enter new item: ", cin>>newItem, cout<<"\n";
        if(cin.fail()){
            cin.ignore();
            cin.clear();
            rewind(stdin);
            cout<<"Enter new item: ", cin>>newItem, cout<<"\n";
        }
        totalList.push_back(newItem);
    }
    else if(choice == 2){
        int itemNumber = 0;
        cout<<"Enter item number to delete: ", cin>>itemNumber, cout<<"\n";
        while(cin.fail() || itemNumber < 1 || itemNumber > totalList.size()){
            cin.ignore();
            cin.clear();
            rewind(stdin);
            cout<<"Enter item number to delete: ", cin>>itemNumber, cout<<"\n";
        }
        totalList.erase(totalList.begin() + (itemNumber-1));
    }
    else if(choice == 3){
        cont = false;
        pushFile(totalList, fileName);
        cout<<"Exiting.\n";
    }
    else{
        cout<<"Invalid Input!\n";
        cin.clear();
        cin.ignore();
    }
}

} vector pullFile(string fileName){ vector totalList; fstream ioFile; ioFile.open(fileName.c_str(), fstream::in); string bullet; while (!ioFile.eof()){ getline(ioFile, bullet); if(!bullet.empty()){ totalList.push_back(bullet); } } ioFile.close(); return totalList; } void pushFile(vector totalList, string fileName){ fstream ioFile; ioFile.open(fileName.c_str(), fstream::out); for(int c = 0; c < totalList.size(); c++){ if(!totalList[c].empty()){ ioFile<<totalList[c]<<"\n"; } } ioFile.close(); } bool ifExists(string fileName){ ifstream infile(fileName.c_str()); return infile.good(); } void printList(vector totalList, string fileName){ cout << "\033[2J\033[1;1H"; cout<<"List: "<<fileName<<"...\n"; for(int c = 0; c < totalList.size(); c++) { cout<<(c+1)<<". "<<totalList[c]<<"\n"; } cout<<"\n\n\n\n\n"; }

About

TASK 4 TO-DO LIST Build a simple console-based to-do list manager that allows users to add, view, and delete tasks Task Input: Allow users to input tasks they want to add to the list. Add Task: Implement a function to add tasks to the list. View Tasks: Display the list of

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages