C++ program that reads N family names (N should be declared as a constant in your program
and it should be equal to the largest digit of your student id number), stores them in an array, sorts them
in ascending order and searches for the given name. The program should display and execute a menu
with the following options. A switch statement must be used to execute the following menu options:
1. Read N family names and store them in an array
2. Sort family names in ascending order
3. Search for a given family name
4. Display all family names which start with the letter "A"
5. Display all family names which end with the letter "H"
6. Display all family names
7. Exit
1. Read N family names and store them in an array
This option reads N family names from the keyboard and stores them in an array.
2. Sort family names in ascending order
This option sorts the family names in ascending order. The function to sort the family names must use
two “for loops” and one “if statement”.
3. Search for a given family name
This option searches for the family name. It asks the user to enter a family name and searches for it, if it
is found, it displays the message “family name - found” and array location otherwise displays a message
“family name - not found”.
4. Display all family names which start with the letter "A"
This option displays all family names stored in array which start with the letter "A".
5. Display all family names which end with the letter "H"
This option displays all family names stored in array which end with the letter "H".
6. Display all family names
This option displays all family names stored in the array.
7. Exit
The program should display the message “Thank you.” and your student id number and exit.
The whole program should work in a loop to enable the user to read N family names, sort them in
ascending order, search for the given family name and display all family names until the user chooses to
exit.
A possible starting place is the main loop to display the menu and get the user choice.
EG
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
void DisplayMenu();
int main()
{
int choice=0;
do
{
DisplayMenu();
cin >> choice;
//Your switch statement here
} while (choice<>7);
return 0;
}
void DisplayMenu()
{
//Your code to display the menu here
}
In the first instance the switch statement can just output what the choice should do so you can tell if you have it working.
Once you are happy with the loop, start to add the more complex functionality - Input the names and display all are the obvious first two to work on. Then build on that.
If you need more help just ask, but don't expect people to do all the work for you:-)
Hi, have a look at this example http://newdata.box.sk/bx/c/htm/ch14rv2.htm from "Sams Teach Yourself C++ in 21 Days"
It is about sorting numbers in a linked list. If you use a char type array, you might be able to enter characters as well. Note that this document is old and you have to remove the ".h" from the header inclusion "#include <iostream.h>" There is also a similar example in the other edition "Sams Teach Yourself C++ in 10 minutes", but maybe not available online. I would like to use this example to create a list view as in VB.