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
  • #include <iostream> #include <vector> #include <iomanip> using namespace std; int main() { const int NUM_ITEMS =...

    #include <iostream> #include <vector> #include <iomanip> using namespace std; int main() { const int NUM_ITEMS = 8; vector <double> inverse(NUM_ITEMS); int j; double temp; for (int i = 0; i < NUM_ITEMS; i++) { inverse.at(i) = 1 / (i + 1.0); } cout << fixed << setprecision(2); cout << "Original vector..." << endl; for (int i = 0; i < NUM_ITEMS; i++) { cout << inverse.at(i) << " "; } cout << endl; cout << "Reversed vector..." << endl; for...

  • Write a psuedocode for this program. #include <iostream> using namespace std; string message; string mappedKey; void...

    Write a psuedocode for this program. #include <iostream> using namespace std; string message; string mappedKey; void messageAndKey(){ string msg; cout << "Enter message: "; getline(cin, msg); cin.ignore(); //message to uppercase for(int i = 0; i < msg.length(); i++){ msg[i] = toupper(msg[i]); } string key; cout << "Enter key: "; getline(cin, key); cin.ignore(); //key to uppercase for(int i = 0; i < key.length(); i++){ key[i] = toupper(key[i]); } //mapping key to message string keyMap = ""; for (int i = 0,j...

  • #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str);...

    #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str); int numConsonants(char *str); int main() {    char string[100];    char inputChoice, choice[2];    int vowelTotal, consonantTotal;    //Input a string    cout << "Enter a string: " << endl;    cin.getline(string, 100);       do    {        //Displays the Menu        cout << "   (A) Count the number of vowels in the string"<<endl;        cout << "   (B) Count...

  • #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; struct transition{ // transition structure...

    #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; struct transition{ // transition structure char start_state, to_state; char symbol_read; }; void read_DFA(struct transition *t, char *f, int &final_states, int &transitions){ int i, j, count = 0; ifstream dfa_file; string line; stringstream ss; dfa_file.open("dfa.txt"); getline(dfa_file, line); // reading final states for(i = 0; i < line.length(); i++){ if(line[i] >= '0' && line[i] <= '9') f[count++] = line[i]; } final_states = count; // total number of final states // reading...

  • #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str);...

    #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str); int numConsonants(char *str); int main() {    char string[100];    char inputChoice, choice[2];    int vowelTotal, consonantTotal;    //Input a string    cout << "Enter a string: " << endl;    cin.getline(string, 100);       do    {        //Displays the Menu        cout << "   (A) Count the number of vowels in the string"<<endl;        cout << "   (B) Count...

  • CONVERT THE FOLLOWING C/C++ PROGRAM INTO JAVA: //LinkedString.h #pragma once #include<iostream> #include<string> using namespace std; //declare...

    CONVERT THE FOLLOWING C/C++ PROGRAM INTO JAVA: //LinkedString.h #pragma once #include<iostream> #include<string> using namespace std; //declare a node datastruct struct Node {    char c;    Node *next; }; class LinkedString {    Node *head; public:    LinkedString();    LinkedString(char[]);    LinkedString(string);    char charAt(int) const;    string concat(const LinkedString &obj) const;    bool isEmpty() const;    int length() const;    LinkedString substring(int, int) const;    //added helper function to add to linekd list private:    void add(char c); };...

  • #include <iostream> #include <fstream> using namespace std; //constants const int CAP = 100; //function prototypes bool...

    #include <iostream> #include <fstream> using namespace std; //constants const int CAP = 100; //function prototypes bool openFile(ifstream &); void readData(ifstream &, int [], int &); void printData(const int [], int); void sum(const int[], int); void removeItem(int[], int &, int); int main() { ifstream inFile; int list[CAP], size = 0; if (!openFile(inFile)) { cout << "Program terminating!! File not found!" << endl; return -1; } //read the data from the file readData(inFile, list, size); inFile.close(); cout << "Data in file:" <<...

  • CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer;...

    CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer; cout << "MENU" << endl; cout << "a - Add item to cart" << endl; cout << "d - Remove item from cart" << endl; cout << "c - Change item quantity" << endl; cout << "i - Output items' descriptions" << endl; cout << "o - Output shopping cart" << endl; cout << "q - Quit" << endl << endl; while (true) {...

  • #include <iostream> #include <iomanip> #include <cstdlib> #include <fstream> #include <string> #include <vector> #include <sstream> using namespace...

    #include <iostream> #include <iomanip> #include <cstdlib> #include <fstream> #include <string> #include <vector> #include <sstream> using namespace std; void DisplayMenu() {    cout << "1. E games\n";    cout << "2. T games\n";    cout << "3. M games\n";    cout << "4. Total Games\n";    cout << "5. Exit\n"; } double total(double egames, double tgames, double mgames) {    int totalgames = egames + tgames + mgames;    cout << "There are " << totalgames << " games\n";    return...

  • #include <iostream> #include <string> using namespace std; int main() { int number; int sum = 0;...

    #include <iostream> #include <string> using namespace std; int main() { int number; int sum = 0; while(true) { cout << "Please enter a number between 1 and 11: "; cin >> number; if (number >= 1 && number <= 11) { cout << number << endl; sum = sum + number; //only add the sum when number is in range: 1-11, so add wthin this if case } else { cout << number << endl; cout << "Out of range;...

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