Question

In: Computer Science

Asks the user "How many parrots do you own?"         2: Reads in that many single...

Asks the user "How many parrots do you own?"

        2: Reads in that many single word names (one for each parrots) from the user and stores the names in an array.

        3: After the user has finished entering names, the program should display the list of all the parrots the user entered.

        4: then display the parrots  in alphabetical order for part 3. Note: string objects can be compared with the “<” operator, which will determine if a given string is alphabetically less than another string.

You may assume the user will own at most 50 parrots.

c++

Solutions

Expert Solution

Solution

Code

#include<bits/stdc++.h>
using namespace std;
bool compareparrots(string a,string b)
{
return a<b;
}
int main()
{
cout<<"How many parrots do you own? ";
int n;
string parrot[50];
cin>>n;
for(int i=0;i<n;i++)
cin>>parrot[i];
cout<<"User owned parrots are:"<<endl;
for(int i=0;i<n;i++)
{
cout<<parrot[i];
cout<<endl;
}
  
sort(parrot,parrot+n,compareparrots);
cout<<"Parrots in alphabetical order: "<<endl;
for(int i=0;i<n;i++)
{
cout<<parrot[i]<<endl;
}
}

Screenshot

Output

---

simplified the code and given

if you have any doubts, question, let me know, love to help

all the best


Related Solutions

Asks the user "How many parrots do you own?"         2: Reads in that many single...
Asks the user "How many parrots do you own?"         2: Reads in that many single word names (one for each parrots) from the user and stores the names in an array.         3: After the user has finished entering names, the program should display the list of all the parrots the user entered.         4: then display the parrots  in alphabetical order for part 3. Note: string objects can be compared with the “<” operator, which will determine if a...
Write a program that asks a user how many classes they are taking this term, the...
Write a program that asks a user how many classes they are taking this term, the name of each class, the credit hours for each class, and their final letter grade for each class, and then calculates their term GPA. Use either a list for each course or a single list-of-lists. The grading system and examples can be found on the TAMU website: http://registrar.tamu.edu/Transcripts-Grades/How-to-Calculate-GPA
Write a program that asks the user for their filing status (single or married) and their...
Write a program that asks the user for their filing status (single or married) and their taxable income. Then, using the below table, compute the tax owed and display the filing status, taxable income, and tax owed. If the filing status is single and the taxable income is overbut not over   the tax is of the amount over$0$9,52510%0$9,526$38,700$952.50 + 12%$9,525$38,701$82,500$4,453.50 +22% $38,700 $82,501unlimited$14,089.50 +24% $82,500 If the filing status is married filing jointly and the taxable income is overbut not overthe...
C++. Write a program that asks the user to enter a single word and outputs the...
C++. Write a program that asks the user to enter a single word and outputs the series of ICAO words that would be used to spell it out. The corresponding International Civil Aviation Organization alphabet or ICAO words are the words that pilots use when they need to spell something out over a noisy radio channel. See sample screen output for an example: Enter a word: program Phonetic version is: Papa Romeo Oscar Golf Romeo Alpha Mike The specific requirement...
A survey asks: On an average evening, how many hours do you spend online sur ng...
A survey asks: On an average evening, how many hours do you spend online sur ng social media? Identify two issues with the wording of this question which could be improved in order to make its response more useful.
​​​​​ 1 Do you own a pet? 2 How old are you? 3 How much do...
​​​​​ 1 Do you own a pet? 2 How old are you? 3 How much do you weigh? (lbs) 4 Male or Female? 5 Do you drink alcohol? 6 How often do you watch movies at the theater per month? 7 How often do you eat fast food per week? 8 Do you like spicy food? 9 Do you prefer Android or iOS? 10 Do you prefer Windows of Mac? 11 How many times a year do you go on...
Write a C# console program that continually asks the user "Do you want to enter a...
Write a C# console program that continually asks the user "Do you want to enter a name (Y/N)? ". Use a "while" loop to accomplish this. As long as the user enters either an upper or lowercase 'Y', then prompt to the screen "Enter First and Last Name: " and then get keyboard input of the name. After entering the name, display the name to the screen. --- Create a Patient class which has private fields for patientid, lastname, firstname,...
Write a C# console program that continually asks the user "Do you want to enter a...
Write a C# console program that continually asks the user "Do you want to enter a name (Y/N)? ". Use a "while" loop to accomplish this. As long as the user enters either an upper or lowercase 'Y', then prompt to the screen "Enter First and Last Name: " and then get keyboard input of the name. After entering the name, display the name to the screen.
Write a C# console program that continually asks the user "Do you want to enter a...
Write a C# console program that continually asks the user "Do you want to enter a name (Y/N)? ". Use a "while" loop to accomplish this. As long as the user enters either an upper or lowercase 'Y', then prompt to the screen "Enter First and Last Name: " and then get keyboard input of the name. After entering the name, display the name to the screen.
Write a C++ program that asks the user to enter a series of single-digit numbers with...
Write a C++ program that asks the user to enter a series of single-digit numbers with nothing separating them. Read the input as a C-string or a string object. The program should display the sum of all the single-digit numbers in the string. For example, if the user enters 2514, the program should display 12, which is the sum of 2, 5, 1, and 4. The program should also display the highest and lowest digits in the string. It is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT