Question

Create a program that takes in user input and stores the input into an array. Also...

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
  • Java Code please read comments and add the code to required lines....LINE 1 to LINE 5...

    Java Code please read comments and add the code to required lines....LINE 1 to LINE 5 ********************************************************************** * Program Summary: This program demonstrates these basic Java concepts: * - Creating an array based on user input * - Accessing and displaying elements of the array * * The program should declare an array to hold 10 integers. * The program should then ask the user for an integer. * The program should populate the array by assigning the user-input integer...

  • In C plus plus Objective: Create an array of numbers based upon user input. Program logic:...

    In C plus plus Objective: Create an array of numbers based upon user input. Program logic: Ask the user for how big to size the array. Create an array based upon that size. Ask for a number, add that number to the array. Repeat adding to the end until all numbers have been entered or until they enter -1 for the number. Print the list.

  • // 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...

  • Write a program that will create an array of ten integers, allow the user to enter...

    Write a program that will create an array of ten integers, allow the user to enter those integers, and eventually search through the array based on index position: 1. Declare the array. You cannot assign elements to an array until it has first been created. 2. Next, run a for loop so that the user can enter an integer to save in each index position of the array. Since you this array holds ten elements , the index position starts...

  • 2. Write a program to do the following: • ask the user to input the size...

    2. Write a program to do the following: • ask the user to input the size of an array of integers and allocate space for the array • ask the user to input the integer values for the array and store these values into the array • calculate and display the sum and the average of elements of the array.

  • java Create a program that utilized a multi-dimensional array for the user to input the name...

    java Create a program that utilized a multi-dimensional array for the user to input the name of a team and their number of wins. The user should be able to input up to 10 teams and the wins for each team.

  • Flowchart and pseudocode for a program that takes a user input consisting of an integer number...

    Flowchart and pseudocode for a program that takes a user input consisting of an integer number between 0 and 99 and outputs its conversion as binary. For example, if a user enters 25, the output should be 11001. The program should also validate the input and continuously ask for a new input if the number is not within the appropriate range of values. Additional instructions: check that the user enters a number between 0 and 99.

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