THIS IS A C++ CODE i have some of the code but need help with the 2 functions th
ID: 3598779 • Letter: T
Question
THIS IS A C++ CODE i have some of the code but need help with the 2 functions that are incomplete in the code please help
Create a command line TODO list program. Prompt your client. The first character/symbol they enter will be the command. Follow that with a space. Finally, enter the todo list item. Example: "+ Study for Final" (don’t enter the quotes). This causes Study for Final to be entered into the TODO list with today’s date. You will need to have the following fields at a minimum: TODO itself, date added, and TODO Identification number.
Constraints.
Use Object Oriented Programming.
Allow the user to enter tasks with a "+" symbol.
Allow the user to display all tasks.
Allow the user to remove a task with a "-" symbol (use an ID num-
ber to remove the TODO).
Save the item so it persists when the program is restarted.
You can either load the data into a dynamic array like you have
been doing in the last several programs OR you can store your
data on disk and use random access for the data.
Create a command symbol to quit the program.
Display the completed items separately.
Overload « and » operators (Counts as 1 bonus).
Display output as a web page so you can see it with a web browser
instead of the terminal.
Use recursion instead of a loop for some part of your program.
#include<iostream>
#include<iomanip>
#include<string>
#include<fstream>
using namespace std;
// Constriant 1- Using OOP techniques
class Todo{
private:
public:
void add(string);
void del(string);
void view();
};
int main()
{
Todo t;
string item;
char func;
do{
cout<<" Your TODO list"<<endl;
// Constraint 2- + for adding an item to the list.
cout<<"press + then your item to add to the todo list"<<endl;
// Constraint 4- - to remove an item from the list.
cout<<"press - then the item serial number to remove from the list"<<endl;
// Constraint 3- Function to display all the items.
cout<<"Press = to display all the items"<<endl;
// Constraint 7- x quits the program.
cout<<"Press x to quit the program."<<endl;
cin>>func;
}while(func!='+' && func!='-' && func!='=');
// Bonus-Input validation
if(func=='+' || func=='-')
getline(cin,item);
if(func=='+')
{
t.add(item);
}
else if (func=='-')
{
t.del(item);
}
else if(func=='=')
{
t.view();
}
}
void Todo::add(string item)
{
char func;
string data;
int serial=0;
string iitem;
ifstream in;
//constraint 4- assign a serial number.
while(getline(in, data))
serial++;
time_t rawtime;
struct tm* timeinfo;
time( &rawtime );
timeinfo = localtime( &rawtime );
in.open("ToDo list.txt");
ofstream f;
f.open("ToDo list.txt", ios::app);
f<<serial<<" "<<item<<" "<<timeinfo->tm_mon<<" "<<timeinfo->tm_mday<<" "<<(timeinfo->tm_year + 1900)<<endl;
f.close();
cout<<"New task added to the list"<<endl;
cout<<"press + then your item to add to the todo list"<<endl;
cout<<"press - then the item serial number to remove from the list"<<endl;
cout<<"Press = to display all the items"<<endl;
cout<<"Press x to quit the program."<<endl;
cin>>func;
if(func=='+')
{
getline(cin,iitem);
add(iitem);
}
else if(func=='-')
{
getline(cin, iitem);
del(iitem);
}
else if(func=='=')
{
view();
}
else if(func=='x')
{
exit(0);
}
}
void Todo::del(string item)
{
}
void Todo::view()
{
}
Explanation / Answer
Code is not compiled.If any major issues comment it
void Todo::del(string item)
{
string s;
ifstream myfile("ToDo list.txt");
ofstream newfile("temp.txt");
if (myfile.is_open())
{
while ( getline (myfile,line) )
{
s=line;
if(s.find(item)!=std::string::npos)
{
newfile<<s;
}
}
myfile.close();
remove("ToDo list.txt");
rename("temp.txt","ToDo list.txt");
}
}
void Todo::view()
{
ifstream myfile("ToDo list.txt");
if (myfile.is_open())
{
while ( getline (myfile,line) )
{
cout << line << ' ';
}
myfile.close();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.