Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Add the following functionality in the code given below: 1) Support ToDo List items that take a space (i.e. Got to Store) 2) Save

C++ Add the following functionality in the code given below: 1) Support ToDo List items that take a space (i.e. "Got to Store") 2) Save any existing list items to a file using the class destructor (i.e. ~ToDo() ) 3) If saved file exists, use constructor to open file pre-populate todo list. 4) Change `Done` function so a user can select which item to finish.

# ToDo.cpp

#include "ToDo.h"
using namespace std;
ToDo::ToDo(){
ToDo(5);
}
ToDo::ToDo(int len){
length = len;
list = new string[length];
}
ToDo::~ToDo(){
delete [] list;
}
// Add an item to list
void ToDo::add(string item){
if(next < length){
list[next] = item;
next++;
}
}
// Finish the last thing in list
void ToDo::done(){
next--;
list[next] = "";
}
// Print list
void ToDo::print(){
for(int i=0;i
cout << " " << i << " " << list[i] << endl;
}

}

# ToDo.h

#include
#include
using namespace std;
// g++ main.cpp ToDo.cpp
class ToDo {
private:
string *list;
int length = 0;
int next = 0;
public:
// Default Constructor
ToDo();
// Create list of length len
ToDo(int len);
// Destroy out list
~ToDo();
// Add an item to list
void add(string item);
// Finish the last thing in list
void done();
// Print list
void print();

};

# main.cpp

#include
#include
#include "ToDo.h"
using namespace std;
int main(){
char next = 'y';
int len = 0;
string action;
cout << "How long to you want your list: ";
cin >> len;
ToDo list(len);
// Array of ToDo objects
// Make sure you have a () constructor
ToDo manylists[10];
// manylists[2].print();
// manylists[1].print();
while(next != 'x'){
cout << "Add to list (a)" << endl;
cout << "Done list item (d)" << endl;
cout << "Print list (p)" << endl;
cout << "Exit list app (x)" << endl;
cout << "What do you want to do: ";
cin >> next;
switch(next){
case 'a':
cout << "Name a todo item: ";
cin >> action;
list.add(action);
break;
case 'd':
list.done();
break;
case 'p':
list.print();
break;
case 'x':
// All done with todo list
break;
}
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mastering Big Data Interview 751 Comprehensive Questions And Expert Answers

Authors: Mr Bhanu Pratap Mahato

1st Edition

B0CLNT3NVD, 979-8865047216

More Books

Students also viewed these Databases questions

Question

c. Determine the confidence intervals of the linearised parameters.

Answered: 1 week ago