Question

Design a program that allows the user to enter 20 names into a String array. Sort...

Design a program that allows the user to enter 20 names into a String array. Sort the array in ascending (alphabetical) order and display its contents. Can I get this in C++ Language Flowchart please

0 0
Add a comment Improve this question Transcribed image text
Answer #1

In the following C++ program we ask the user to enter 20 names that we store in an array of strings, name[ ].

Then we call the function, sortname() that takes in the array, name[] as the parameter.

In the function we use simple bubble sort to sort the names in the array.

At last we print the names in the sorted order.

FLOWCHART:

CODE:

#include<iostream>
using namespace std;

void sortnames(string name[])
{
   int i,j;
   string temp;
   for(i=0; i<20; i++)
   {
       for(j=0; j<20-i-1; j++)
       {
           if(name[j] > name[j+1])   //if current name is greater than next
           {   //then swap the names
               temp = name[j];
               name[j] = name[j+1];
               name[j+1] = temp;
           }
       }
   }
}
int main()
{
   string name[20];
   cout<<"Enter the 20 names: \n";
   for(int i=0; i<20; i++)
       cin>>name[i];   //input names
   sortnames(name);   //calling the function
   cout<<"\nNames after sorting are:\n";
   for(int i=0; i<20; i++)
       cout<<name[i]<<endl;   //printing the names
  
   return 0;
}

OUTPUT:

Add a comment
Answer #2

I've used a sorting technique known as bubble sorting , you can use any sorting technique to implement sorting .

In bubble sorting in every iteration a position from last gets it's proper value, and if do not perform any swap during a whole iteration then array is sorted so at that time we stop sorting.

I've attached both flowchart and the program for the above question

here is the flowchart:

here is the program code:

#include<iostream>
using namespace std;
int main()
{
string arr[20];
cout<<"enter 20 strings in new lines";
for(int i=0;i<20;i++) // take input of 20 strings
{
cin>>arr[i];
}
// bubble sorting technique is used
for(int i=0;i<20;i++)
{
bool swapbool = false; // this will check if we do not make any swap in an iteration then array is sorted
for(int j=0;j<20-i-1;j++)
{
if(arr[j].compare(arr[j+1])>0)
{
swapbool=true;
swap(arr[j],arr[j+1]);
}
}
if(swapbool==false) // as no change is swapbool so array is sorted
{
break;
}
}
for(int i=0;i<20;i++)
{
cout<<"\n"<<arr[i];
}
}

thanks. I hope it'll help you so please give positive ratings.

Add a comment
Know the answer?
Add Answer to:
Design a program that allows the user to enter 20 names into a String array. Sort...
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
  • Design a program that allows the user to enter 5 names into a String array. Sort...

    Design a program that allows the user to enter 5 names into a String array. Sort the array in ascending (alphabetical) order and display its contents. Search the array for a specific name that the user wants. For this problem you will be submitting python homework, no flowchart

  • This is with microsoft studio visual basic Sorted Names Design a program that allows the user...

    This is with microsoft studio visual basic Sorted Names Design a program that allows the user to enter 20 names into a String array. Sort the array in ascending (alphabetical) order and display its contents.

  • 3. Name Search Modify the Sorted Names program that you wrote for exercises #2 so it...

    3. Name Search Modify the Sorted Names program that you wrote for exercises #2 so it allows you to search the array for a specific name. design a flowchart for it exercises 2 is as follow: Sorted Names Design a program that allows the user to enter 20 names into a String array. Sort the array in ascending (alphabetical) order and display its contents. Pseudocode for number 3 as follow: Initialize i=0 Get the name to search for If i<20...

  • Design a program that has two parallel arrays: a String array named people that is initialized...

    Design a program that has two parallel arrays: a String array named people that is initialized with the names of seven of your friends, and a String array named phoneNumbers that is initialized with your friends’ phone numbers. The program should allow the user to enter a person’s name (or part of a person’s name). It should then search for that person in the people array. If the person is found, it should get that person’s phone number from the...

  • Design a program using a RAPTOR flowchart that has two parallel arrays: a String array named...

    Design a program using a RAPTOR flowchart that has two parallel arrays: a String array named people that is initialized with the names of twenty of your friends, and a String array named phoneNumbers that is initialized with your friends’ phone numbers. The program should allow the user to enter a person’s name. It should then search for that person in the people array. If the person is found, it should get that person’s phone number from the phoneNumbers array...

  • Design a program that prompt the user to enter 10 integer numbers into an array. Program...

    Design a program that prompt the user to enter 10 integer numbers into an array. Program should print the numbers in a reverse order (flowchart) c++

  • a. Design the logic for a program that allows a user to enter 12 numbers, then...

    a. Design the logic for a program that allows a user to enter 12 numbers, then displays them in the reverse order of entry. b. Modify the reverse-display program so that the user can enter any amount of numbers up to 12 until a sentinel value is entered. ( I really could use more of a pseudocode rather than actual code. also an explanation of each step. The answer I got last time was just c++ code that including a...

  • 1. Backward String Design a program that prompts the user to enter a string and then...

    1. Backward String Design a program that prompts the user to enter a string and then displays the string contents backward. For instance, if the user enters “gravity” the program should display “ytivar" -VB or Visual Studio. It must be turned into a GUI program. Make sure to write comments and include pseudocode. -Paste a screenshot of the pseudocode, the VB code, and of the program running into a PDF.

  • Design a program that asks the user to enter a series of 20 numbers. The program...

    Design a program that asks the user to enter a series of 20 numbers. The program should store the numbers in the array and then display the following data: The lowest number in the array The highest number in the array The total of the number in the array The average of the numbers in the array PLEASE GIVE THE PSEUDOCODE AND CODE IN C PROGRAMMING

  • Design the logic for a program that allows the user to enter a maximum of 10...

    Design the logic for a program that allows the user to enter a maximum of 10 numbers. If the use enters a -1 the input loop stops early. The value -1 is not data but a quit flag value that is not entered into the array. Then the program displays the count of the numbers entered and numeric average of the numbers (not including the -1 of course). After display the average of all the entered numbers, the program will...

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