Create pseudocode and flowchart for a program in C++ that simulates a simple con
ID: 3884371 • Letter: C
Question
Create pseudocode and flowchart for a program in C++ that simulates a simple contact manager application given the following requirements:
The program is to store individual names and associated telephone numbers in parallel arrays.
The program should input from the user 10 people’s names and their telephone numbers and add the data to the parallel arrays.
When data input is finished, the program should sort both data arrays in ascending order based on telephone numbers maintaining the associations between names and telephone numbers.
The program will print the list of users and their telephone numbers after sorting.
After printing the list, the program will ask for a name to search for.
The user will then enter a name. The program will then search for the name and print the name and the associated telephone number for that person. If the person is not in the array, the program will print that the user cannot be found.
The program must use at least one menu at the beginning with multiple options including an option to exit the program. The program must run continuously, in a cyclic manner until the user chooses to exit. Sublevel menus are allowed. The program must use: multiple data types, multiple mathematical operators, decision structures, iterative structures, and functions.
Explanation / Answer
// C++ code
#include <iostream>
using namespace std;
int main()
{
int size = 10;
//2 parallel arrays
string names[10];
string phones[10];
cout << "Enter contact information for 10 people -" << endl;
for(int i = 0; i < size; i++)
{
cout << "Contact " << (i+1) << endl;
cout << " Name: ";
cin >> names[i];
cout << " Phone: ";
cin >> phones[i];
cout << endl;
}
//sort the 2 arrays based on ascending order of phones, selection sorting
int minIdx;
for(int i = 0; i < size; i++)
{
minIdx = i;
for(int j = i+1; j < size; j++)
{
if(phones[j] < phones[minIdx])
minIdx = j;
}
if(minIdx != i)
{
//swap both name and telephone number together
string temp = names[i];
names[i] = names[minIdx];
names[minIdx] = temp;
temp = phones[i];
phones[i] = phones[minIdx];
phones[minIdx] = temp;
}
}
//display the names and phones after sorting
cout << "The list of contacts sorted on phone numbers is - " << endl;
for(int i = 0; i < size; i++)
{
cout << names[i] << " " << phones[i] << endl;
}
//search for a given name and retrieve the phone number
string search;
cout << "Enter a name to search: ";
cin >> search;
int idx = -1;
for(int i = 0; i < size; i++)
{
if(names[i] == search) //if found the name, save the index
{
idx = i;
break;
}
}
if(idx == -1)
cout << "Name not found" << endl;
else
cout << "Name: " << names[idx] << " Phone: " << phones[idx] << endl;
return 0;
}
output
Enter contact information for 10 people -
Contact 1
Name: John
Phone: 455332
Contact 2
Name: Bob
Phone: 438325
Contact 3
Name: Alice
Phone: 853932
Contact 4
Name: Peter
Phone: 385932
Contact 5
Name: Henry
Phone: 298392
Contact 6
Name: Donald
Phone: 821013
Contact 7
Name: Michael
Phone: 103593
Contact 8
Name: Robin
Phone: 949245
Contact 9
Name: Stella
Phone: 194832
Contact 10
Name: George
Phone: 359953
The list of contacts sorted on phone numbers is -
Michael 103593
Stella 194832
Henry 298392
George 359953
Peter 385932
Bob 438325
John 455332
Donald 821013
Alice 853932
Robin 949245
Enter a name to search: Peter
Name: Peter
Phone: 385932
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.