Phone number lookup
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
persons name (or part of a persons name). it should then search for
that person in the people array. If the person is found, it should
get that persons phjone number from the phoneNumbers array and
display it. If the person is not found in the people array, the
program should display a message indicating so.
Can you create a Raptor flowchart, not a pseudocode I already have a pseudocode
Here is a pseudocode
//Constant to hold array sizes.
Constant Integer SIZE = 7
//Array to hold name of friends.
Declare String people[SIZE] = "Ashton Jones", "Mia Ray",
"Penelope Waters", "Mark Grey",
"Stephen Jordan","Rebecca Smith",
"Robert Cheney"
//Array to hold each friend phone numbers.
Declare String phoneNumbers[SIZE] = 8958845, 1898123,
8441294, 7480652, 556278, 5450562, 1210755
//Variable to hold name to be searched.
Declare String name
//Variable to use as a loop variable.
Declare Integer index = 0
// Boolean Variable to indicate whether the name of the //friend is found in the array or not. It is initialized //to false.
Declare Boolean found = False
//Variable to store the index value where name is found.
Declare Integer foundIndex
//Get name from user.
Display "Enter name."
Input name
//Sequential search to find the name in the array.
While Found == False AND index <= SIZE - 1
If contains(people[index],name) Then
Set found = True
Set foundIndex = index
Else
Set index = index + 1
End If
End While
//Display if the name is found or not. If the name is in
//the people array then display their phone number.
If Found == True Then
Display "The phone number of ", people[foundIndex]
Display " is ", phoneNumbers[foundIndex]
Else
Display "The name ", name " is NOT in the people array"
End If
#include <iostream>
using namespace std;
int main()
{
//declaring persons names
string
names[]={"Uday","John","Smith","Rocky","Bolt","Mike","Paul"};
string n;
//declaring phone numbers
int
phones[]={991212,994312,994532,889943,990121,932143,909012};
//reading person name
cout<<"Enter name of the person: ";
cin>>n;
int index=-1;
//starting iterating the person array
for(int i=0;i<7;i++){
//checking if it is equal to given name
//if yes exit loop
if(names[i]==n){
index=i;
break;
}
}
//printing the output
if(index==-1){
cout<<n<<" does not exist in the list ";
}
else{
cout<<n<<"'s phone number is :
"<<phones[index];
}
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.