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

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

  • (C++) Write a function, remove, that takes three parameters: an array of integers, the number of...

    (C++) Write a function, remove, that takes three parameters: an array of integers, the number of elements in the array, and an integer (say, removeItem). The function should find and delete the first occurrence of removeItem in the array. (Note that after deleting the element, the number of elements in the array is reduced by 1.) Assume that the array is unsorted. Also, write a program to test the function. Your program should prompt the user to enter 10 digits...

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

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