Question

Phone number lookup Design a program that has two parallel arrays: a string array named people...

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

Homework Answers

Answer #1

#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;

}

Know the answer?
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
Similar Questions
Build two arrays[ ] (Integer and String) and convert them to two ArrayLists and write two...
Build two arrays[ ] (Integer and String) and convert them to two ArrayLists and write two overloaded generic static search method to find the index locations of a specified value. One of the search methods applies to the array type while the other (overloaded) search method applies to the collection type. Implement the following generic linear search method and write a client program to display results: (Here is the header) public static <E extends Comparable<E>> int search(E[] list, E key)...
Write the following program in MIPS: a) declare an array A of the following numbers: 3,...
Write the following program in MIPS: a) declare an array A of the following numbers: 3, 5, 8, 10, 12, 2, 76, 43, 90, 44 b) declare a variable called size which stores the number of element in array A, that is 10. c) write a subroutine to search for a number stored in an array and return true or false. In C++ the subroutine is as follows: search(array, size, number_To_Search) e.g. search(A, 10, 12) The subroutine should return 0...
n this lab, you use what you have learned about parallel arrays to complete a partially...
n this lab, you use what you have learned about parallel arrays to complete a partially completed C++ program. The program should: Either print the name and price for a coffee add-in from the Jumpin’ Jive Coffee Shop Or it should print the message Sorry, we do not carry that. Read the problem description carefully before you begin. The file provided for this lab includes the necessary variable declarations and input statements. You need to write the part of the...
10. Number Array Class Design a class that has an array of floating-point numbers. The constructor...
10. Number Array Class Design a class that has an array of floating-point numbers. The constructor should accept an integer argument and dynamically allocate the array to hold that many numbers. The private data members of the class should include the integer argument in a variable to hold the size of the array and a pointer to float type to hold the address of the first element in the array. The destructor should free the memory held by the array....
In C++ Employee Class Write a class named Employee (see definition below), create an array of...
In C++ Employee Class Write a class named Employee (see definition below), create an array of Employee objects, and process the array using three functions. In main create an array of 100 Employee objects using the default constructor. The program will repeatedly execute four menu items selected by the user, in main: 1) in a function, store in the array of Employee objects the user-entered data shown below (but program to allow an unknown number of objects to be stored,...
In this lab, you complete a partially prewritten C++ program that uses an array. The program...
In this lab, you complete a partially prewritten C++ program that uses an array. The program prompts the user to interactively enter eight batting averages, which the program stores in an array. The program should then find the minimum and maximum batting average stored in the array as well as the average of the eight batting averages. The data file provided for this lab includes the input statement and some variable declarations. Comments are included in the file to help...
Topics Arrays Accessing Arrays Description Write a C++ program that will display a number of statistics...
Topics Arrays Accessing Arrays Description Write a C++ program that will display a number of statistics relating to data supplied by the user. The program will ask the user to enter the number of items making up the data. It will then ask the user to enter data items one by one. It will store the data items in a double array. Then it will perform a number of statistical operations on the data. Finally, it will display a report...
Assignment 1 - ITSC 2214 I have to complete the array list for a shopping list...
Assignment 1 - ITSC 2214 I have to complete the array list for a shopping list code and can't figure out how to complete it: Below is the code Complete the three empty methods (remove(), find(), and contains()) in the ShoppingListArrayList.java file. These methods are already implemented in the ShoppingListArray class. /////////////////////////////////////////////////////////////////////////////////////////////////////////// Grocery Class (If this helps) package Shopping; public class Grocery implements Comparable<Grocery> { private String name; private String category; private int aisle; private float price; private int quantity;...
Write a program that reads in a line consisting of a student’s name, Social Security number,...
Write a program that reads in a line consisting of a student’s name, Social Security number, user ID, and password. The program outputs the string in which all the digits of the Social Security number and all the characters in the password are replaced by x. (The Social Security number is in the form 000-00-0000, and the user ID and the password do not contain any spaces.) Your program should not use the operator [] to access a string element....
Write a template-based class that implements a template-based implementation of Homework 3 that allows for any...
Write a template-based class that implements a template-based implementation of Homework 3 that allows for any type dynamic arrays (replace string by the template in all instances below). • The class should have: – A private member variable called dynamicArray that references a dynamic array of type string. – A private member variable called size that holds the number of entries in the array. – A default constructor that sets the dynamic array to NULL and sets size to 0....