Question
Create a program that takes in user input and stores the input into an array. Also within the program show how you can: show the elements in the array, remove an element from the array, add an element to the array. Do NOT ask the user how many elements they want to add, instead once they are done adding, they should hit ‘q’ and it should break out of the input. This is a c++ program. The input type shall be any kind of type. I.E. it can take in strings, ints, chars etc. Please use comments within the program.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the code below:::

#include <iostream>

#include <string>

using namespace std;

int main()

{

int count=0;

string list[100];

string inData;

while(true){

cin>>inData;

if(inData.compare("q")==0){

break;

}else{

list[count] = inData;

count++;

}

}

int choice;

while(true){

cout<<"\n\nSelect an option"<<endl;

cout<<"1. Display elements"<<endl;

cout<<"2. Remove an element"<<endl;

cout<<"3. Add an element"<<endl;

cout<<"Others to exit"<<endl;

cin>>choice;

if(choice==1){

cout<<"List has following items"<<endl;

for(int i=0;i<count;i++){

cout<<list[i]<<" ";

}

}else if(choice==2){

cout<<"Enter element to delete : ";

string deleteMe;

cin>>deleteMe;

bool found = false;

int i;

for(i=0;i<count;i++){

if(list[i].compare(deleteMe)==0){

found = true;

break;

}

}

if(found){

for(;i<count-1;i++){

list[i] = list[i+1];

}

}else{

cout<<"Element not found"<<endl;

}

count--;

}else if(choice==3){

cout<<"Enter element to add : ";

string addMe;

cin>>addMe;

list[count] = addMe;

count++;

}else{

break;

}

}

return 0;

}

output:

Console <terminated> CPP_Workspace.exe [C/C++ Application] C\Users ,Mohammad Shahrukh\ Desk hello new word 1S here with call to and Select an option 1. Display elements 2. Remove an element 3. Add an element Others to exit List has following items hello new word is here with call to 9999999 and A Select an option 1. Display elements 2. Remove an element 3. Add an element Others to exit 2 Enter element to deleteto Select an option 1. Display elements 2. Remove an element 3. Add an element Others to exit List has following items hello new word is here with call 9999999 and A Select an option

Add a comment
Know the answer?
Add Answer to:
Create a program that takes in user input and stores the input into an array. Also...
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
  • // Program takes 5 numbers from a user (from console), stores them into an // array,...

    // Program takes 5 numbers from a user (from console), stores them into an // array, and then prints them to the screen (on the same line). // Add code to complete this program. You only need to add code where indicated // by "ADD HERE". #include <iostream> using namespace std; int main() { const int SIZE = 5; // size of array // ADD HERE - create an array of integers that will hold 5 integers. cout << "please...

  • Write a Java program that will create an array of Strings with 25 elements. Input Strings...

    Write a Java program that will create an array of Strings with 25 elements. Input Strings from the user and store them in the array until either the user enters “quit” or the array is full. HINT: the sentinel value is “quit” all lowercase. “Quit” or “QUIT” should not stop the loop. HINT: you have to use the equals method (not ==) when you are comparing two Strings. After the input is complete, print the Strings that the user entered...

  • Write a Java program that: 1. Decide on a list of n favorites (songs, bands, movies,...

    Write a Java program that: 1. Decide on a list of n favorites (songs, bands, movies, video games, etc.) (between 5 and 10 favorites is fine). 2. Write a program that lists the n favorites but with a small twist. 3. Read in a file of n favorites (sample file in the Resources/Sample File area)...Please make your own. 4. Print a list of all n favorites to the user (so they know what is coming) 5. Ask if the user...

  • - Write a program that performs several operations on an array of positive ints. The program...

    - Write a program that performs several operations on an array of positive ints. The program should prompt the user for the size of the array (validate the size) and dynamically allocate it. Allow the user to enter the values, do not accept negative values in the array. - Your program should then define the functions described below, call them in order, and display the results of each operation: a) reverse: This function accepts a pointer to an int array...

  • Please help C++ language Instructions Write a program that prompts the user to enter 50 integers...

    Please help C++ language Instructions Write a program that prompts the user to enter 50 integers and stores them in an array. The program then determines and outputs which numbers in the array are sum of two other array elements. If an array element is the sum of two other array elements, then for this array element, the program should output all such pairs.

  • Write a C Language Program that will ask the user how many elements the "maxminarray" will...

    Write a C Language Program that will ask the user how many elements the "maxminarray" will have. Read the elements from user and fill the "maxminarray” with it. Find maximum value and minimum value in maxminarray See the output below: Input number of elements of the array :6 Input 6 elements for the maxminarray : element [0]: 23 element [1] : 56 element [2] : 11 element [3]: 78 element [4]: 21 element [5]: 400 The Maximum element is :...

  • Write a program that asks the user to input 10 integers of an array. The program...

    Write a program that asks the user to input 10 integers of an array. The program then inserts a new value at position (or index) given by the user, shifting each element right and dropping off the last element. For example, in the sample input/output below, the program will insert the value 30 at index 3. All the previous numbers of the array starting from position 3 (i.e., 7 1 20 9 23 8 22 will be shifted one position...

  • Write a complete C++ program that will: Declare a vector of integers Use a pointer to...

    Write a complete C++ program that will: Declare a vector of integers Use a pointer to dynamically allocate an array of 10 elements Ask the user how many values they would like to have in the data structures Read in the user’s response and make sure that it is greater than 20 (error loop) Generate the number of integers that the user asked for and store them into both data structures. The integer values should be unique unordered values (no...

  • C++ Program Takes Strings Until 'QUIT' Input then Displays Strings in Reverse Order

    Write a C++ program that reads strings until "QUIT" input, which then displays all strings in the reverse order they were entered.Tell the user the program will read strings until "QUIT" is entered.LoopAsk user for a stringIf the string is "QUIT" break the loop, otherwise store data3. Inform user data will be displayed in reverse.4. Display ALL strings in reverse.5. Free the space used to store the strings.

  • Write a C++ program by using array with the size 10. The user will input the...

    Write a C++ program by using array with the size 10. The user will input the number between 0 to -10. Then, calculate and display by how many numbers in the array within the range -9 to -2.

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