Question

#include <iostream>
#include <sstream>
#include <string>

using namespace std;

int main()
{
   const int index = 5;
   int head = 0;
   string s[index];

   int flag = 1;
   int choice;

   while (flag)
   {
       cout << "\n1. Add an Item in the Chores List.";
       cout << "\n2. How many Chores are in the list.";
       cout << "\n3. Show the list of Chores.";
       cout << "\n4. Delete an Item from the Chores List.";
       cout << "\n5. Exit.";

       cout << "\n\nEnter your choice : ";
       cin >> choice;

       switch (choice)
       {
       case 1:
       {
           string str;

           if (head < index)
           {
               cout << "Enter strings : ";
               cin >> str;
               s[head] = str;
               head++;
           }
           else
           {
               index = index * 2;
               string temp[index];
               for (int i = 0; i<head; i++)
                   temp[i] = s[i];
               //s = temp;
               s[head] = str;
               head++;
           }

           break;
       }

       case 2:
       {
           cout << "\nThe total number of items in the list is : " << head << "\n";
           break;
       }

       case 3:
       {
           for (int i = 0; i<head; i++)
               cout << s[i] << "\n";
           break;
       }

       case 4:
       {
           head--;
           s[head] = "NULL";
           break;
       }

       case 5:
       {
           flag = 0;
           break;
       }

       default:
       {
           cout << "\nWrong entry. Please try again.\n";
           break;
       }

       }
   }
   return 0;
}

Can you help me fix this code? Im getting 2 errors.1 says expression must be a modifiable value. the second says 'index' you cannot assign to a variable this is const. Both are on line 42. Thank you

Write a program that uses a dynamic list of strings to keep track of a list of chores that you have to accomplish today. The user of the program can request several services: (1) Add an item to the list of chores; (2) Ask how many chores are in the list; (3) Have the list of chores printed to the screen; (4) Delete an item from the list; (5) Exit the program. If you know how to read and write strings from a file, then have the program obtain its initial list of chores from a file. When the program ends, it should write all unfinished chores back to this file.

Write a program for problem 5 in chapter 4.

Use appropriate private data members and provide a public interface for each class that satisfies the description given in the book.

^^^ This is the actual question.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
int index = 5;
int head = 0;
string s[index];
int flag = 1;
int choice;
while (flag)
{
cout << "\n1. Add an Item in the Chores List.";
cout << "\n2. How many Chores are in the list.";
cout << "\n3. Show the list of Chores.";
cout << "\n4. Delete an Item from the Chores List.";
cout << "\n5. Exit.";
cout << "\n\nEnter your choice : ";
cin >> choice;
switch (choice)
{
case 1:
{
string str;
if (head < index)
{
cout << "Enter strings : ";
cin >> str;
s[head] = str;
head++;
}
else
{
index = index * 2;
string temp[index];
for (int i = 0; i<head; i++)
temp[i] = s[i];
//s = temp;
s[head] = str;
head++;
}
break;
}
case 2:
{
cout << "\nThe total number of items in the list is : " << head << "\n";
break;
}
case 3:
{
for (int i = 0; i<head; i++)
cout << s[i] << "\n";
break;
}
case 4:
{
head--;
s[head] = "NULL";
break;
}
case 5:
{
flag = 0;
break;
}
default:
{
cout << "\nWrong entry. Please try again.\n";
break;
}
}
}
return 0;
}

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
#include <iostream> #include <sstream> #include <string> using namespace std; int main() {    const int index...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT