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...
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,...
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 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....
this is the book name. Data Structures and Abstractions with Java 1) Description: The sample programs...
this is the book name. Data Structures and Abstractions with Java 1) Description: The sample programs in Chapter 1 of your textbook are not complete. They are used for illustration purpose only. The implementation of Listing 1-1 on page 39 is explained in Chapter 2. And, in order to see the result of using it, we will need the following set of files: i. BagInteface.java – the specification only. ii. ArrayBag.java – the implementation of BagInerface.java. iii. ArrayBagDemo.java – a...
Question 1 Which statement is false about what Data Types defines Question 1 options: What values...
Question 1 Which statement is false about what Data Types defines Question 1 options: What values a variable cannot hold? How much memory will be reserved for the variable? What value a variable will hold? How the program will use the data type? Question 2 Using the structure below, which of the following statements about creating an array (size 20) of structures are not true? struct Employee{     string emp_id;     string emp_name;     string emp_sex; }; Question 2 options:...
Task 1: You will modify the add method in the LinkedBag class.Add a second parameter to...
Task 1: You will modify the add method in the LinkedBag class.Add a second parameter to the method header that will be a boolean variable: public boolean add(T newEntry, boolean sorted) The modification to the add method will makeit possible toadd new entriesto the beginning of the list, as it does now, but also to add new entries in sorted order. The sorted parameter if set to false will result in the existing functionality being executed (it will add the...