The following code creates a small phone book. An array is used to store a list of names and another array is used to störe the phone numbers that go with each name. For example. Michael Myers’ phone number is 333-8000 and Ash Williams’ phone number is 333-2323. Write the function lookupName so the code properly looks up and returns the phone number for the input target name.
int main ()
{
using namespace std;
string names[] = {“Michael Myers”,
“Ash Williams”,
“Jack Torrance”,
“Freddy Krueger”};
string phoneNumbers[] = {“333–8000”, “333–2323”,
“333–6150”, “339–7570”};
string targetName, targetPhone;
char c;
do
{
cout << “Enter a name to find the ”
<< “corresponding phone number.”
<< endl;
getline(cin, targetName);
targetPhone = lookupName(targetName,
names, phoneNumbers, 4);
if (targetPhone.length() > 0)
cout << “The number is: “
<< targetPhone << endl;
else
cout << “Name not found. ”
<< endl;
cout << “Look up another name? (y/n)”
<< endl;
cin > c;
cin.ignore();
} while (c == ‘y’);
return 0;
}
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Starting out with Visual C# (4th Edition)
Concepts of Programming Languages (11th Edition)
Artificial Intelligence: A Modern Approach
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Software Engineering (10th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
- String [] plants = newstring [] {“onions”, “carrots”, “peas”, “tomatoes”, “bananas”, “lemons”}; Using the array above , write code that 1. Prints the elements of the array in the order they appear in the array using a lambda function 2. Prints the elements of the array in descending order using a Linq function 3. Prints the elements of the array in ascending order using a linq fucntion 4. Prints the elements of the array that contain “ba” using a linq functionarrow_forwardInstructions Write a program in C++ that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and the highest and lowest temperatures for the year. Your program must consist of the following functions: Function getData: This function reads and stores data in the two-dimensional array. Function averageHigh: This function calculates and returns the average high temperature for the year. Function averageLow: This function calculates and returns the average low temperature for the year. Function indexHighTemp: This function returns the index of the highest high temperature in the array. Function indexLowTemp: This function returns the index of the lowest low temperature in the array. These functions must all have the appropriate parameters. An example of the program is shown below: Enter high temperature for each month 60 68 72 72 73 76 80 81 75 72 67 66 Enter low temperature for…arrow_forwardUse C++ programing language Write a modular program that analyzes a year’s worth of rainfall data. In addition to main, the program should have a getData function that accepts the total rainfall for each of 12 months from the user and stores it in an array holding double numbers. It should also have four value-returning functions that compute and return to main the totalRainfall, averageRainfall, driestMonth, and wettestMonth. These last two functions return the number of the month with the lowest and highest rainfall amounts, not the amount of rain that fell those months. Notice that this month number can be used to obtain the amount of rain that fell those months. This information should be used either by main or by a displayReport function called by main to print a summary rainfall report similar to the following: 2019 Rain Report for Springdale County Total rainfall: 23.19 inches Average monthly rainfall: 1.93 inchesarrow_forward
- in C language pweasearrow_forwardC++ Coding Write a program that asks a teacher to enter the student's name and the grades received on her quarterly exams. The datatype for the student's name could be a string and the four grades should be entered in an array of data types int. Test scores are on the base of 100. REMINDER: sum and cap CANNOT be integers. The main() functions describe the average function with the following title line: double avg( int grades[], int cap ) The program prints the student's name, her four grades, and her average grades The main() function also uses the following print function: void print( int grades[], int cap);arrow_forwardThe following code creates a small phone book. An array is used to storea list of names and another array is used to store the phone numbers thatgo with each name. For example, Michael Myers’ phone number is 333-8000 and Ash Williams’ phone number is 333-2323. Write the functionlookupName so the code properly looks up and returns the phone numberfor the input target name.int main(){using namespace std;string names[] = {"Michael Myers","Ash Williams","Jack Torrance","Freddy Krueger"};string phoneNumbers[] = {"333-8000","333-2323","333-6150","339-7970"};string targetName, targetPhone;char c;do{cout << "Enter a name to find the "<< "corresponding phone number."<< endl;getline(cin, targetName);targetPhone = lookupName(targetName,names, phoneNumbers,4);if (targetPhone.length() > 0)cout << "The number is: "<< targetPhone << endl;elsecout << "Name not found. "<< endl;cout << "Look up another name? (y/n)"<< endl;cin >>…arrow_forward
- C++ Coding Write a program that asks a teacher to enter the student's and the grades received on her quarterly exams. The datatype for the student's name could be a string and the four grades should be entered in an array of data types int. Test scores are on the base of 100. The main() functions describe the average function with the following title line: double avg( int grades[] , int cap ): The program prints the student's name, her four grades, and her average grades. The main() function also uses the following print function: void print( int grades[], int cap);arrow_forwardC++arrow_forwardPayroll System In this lab, you're going to be working with partially filled arrays that are parallel with each other. That means that the row index in multiple arrays identifies different pieces of data for the same person. This is a simple payroll system that just calculates gross pay given a set of employees, hours worked for the week and hourly rate. Parallel Arrays First, you have to define several arrays in your main program: 1. employee names for each employee 2 hourly pay rate for each employee 3. total hours worked for each employee 4. gross pay for each employee Second, you will need a two dimension (2-D) array to record the hours worked each day for an employee. The number of rows for the 2-D array should be the same as the arrays above since each row corresponds to an employee. The number of columns represents days of the week (7 last I looked). Functions Needed In this lab, you must read in the employee names first because this identifies how many elements will be in each…arrow_forward
- Exercise 1: //The max function the max between a and b, it returns a if a == //b public double max(double a, double b); //The mult function returns the result of a * b public double mult(double a, double b); //The exist in array function returns the index of the element //‘a’ if //‘a’ exist in array ‘arr’ otherwise returns ‘-1’ public int existsInArray(int [] arr, int a); //Are array equals method compares two arrays and returns true // if the elements of array ‘a’ are equal to elements of array // ‘b’, element by element. If equals it returns 0, it returns - // 1 if not public int areArrayEquals(int [] a, int [] b); Devise four executable test cases for every method in the JUnit notation. See the attached handout for a refresher on the notation.arrow_forwardBirthday: 06/12/2001. AIUB ID: 21-44485-1. Send the code in c++ format.arrow_forwardc++ programming Initialize a string array named person with your first, middle andlast name as separate elements. Print the middle name from the array. Iterate to print all values of the array. Output Example WilliamJohn William Henryarrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr