Concept explainers
Given a file with data for names and marks you will read them into two arrays You will then display the data, do a linear search and report if found, sort the data, do a binary search. Be sure to test for found and not found in your main program.
- Read Data
Write a function that reads in data from a file using the prototype below. The function can define and open the file, read the names and marks into the arrays and keep track of how many names there are in numElts, and then closes the file. The list of names and marks can be found at the end of the lab and copied into a text file.
void getNames(string names[], int marks[], int& numElts);
- Display Data
Write a function to display the contents of names and marks using the prototype given below.
void displayData(const string names[], const int marks[], int numElts);
- Linear Search
Write the searchList function given the prototype below so that it searches for a given name. The functions returns and int which is the index of the name found.
The main program will decide if -1 is returned then it will say name is not found otherwise it will write out the name and the mark for that name.
int linearSearch(const string list[], int numElts, string value);
- Selection Sort
Write the selectionSort given the prototype below so that it sorts by name in ascending order. Be sure to accept both arrays name and mark for sorting purposes.
void selectionSort(string name[], int marks[], int numElts);
- Binary Search
Write the binarySearch function given the prototype below so that it searches for a given name.The functions returns and int which is the index of the name found.
The main program will decide if -1 is returned then it will say name is not found otherwise it will write out the name and the mark for that name.
int binarySearch(const stringt array[], int numElts, string value);
- Main Function
Write a main function that declares the names, marks, number of elements as well as the value to be searched for and the index of the returned function calls.
- Read and display the contents of names and marks.
- Ask the user for a name and using the linear search return the index to the user. If -1 is returned then the name is not in the file. Otherwise write out the name and mark for that student.
- Sort the arrays and write them out.
- Ask the user for a name to search for. This time use the binarySearch to return -1 or an index. Display the student’s name and mark if found.
- Test your program for found and not found for each type of search.
void getNames(string names[], int marks[], int& numElts);
int linearSearch(const string names[], int numElts,string who);
int binarySearch(const string names[], int numElts,string who);
void selectionSort(string names[], int marks[],int numElts);
void displayData(const string names[], const int marks[], int numElts);
const int NUM_Names = 20;
int main()
{
string names[NUM_NAMES];
int marks[NUM_NAMES];
int numElts;
int index;
string searchWho;
// Function calls here
return 0;
}
File for names and marks:
Collins,Bill 80
Smith,Bart 75
Allen,Jim 82
Griffin,Jim 55
Stamey,Marty 90
Rose,Geri 78
Taylor,Terri 56
Johnson,Jill 77
Allison,Jeff 45
Looney,Joe 89
Wolfe,Bill 63
James,Jean 72
Weaver,Jim 77
Pore,Bob 91
Rutherford,Greg 42
Javens,Renee 74
Harrison,Rose 58
Setzer,Cathy 93
Pike,Gordon 48
Holland,Beth 79
this is one whole question or program not a multipart question please answer all of it, thanks!!
answer in beginner C++,
Step by stepSolved in 2 steps
- Jupyter Notebook Fixed Income - Certicificate of Deposit (CD) - Compound Interest Schedule An interest-at-maturity CD earns interest at a compounding frequency, and pays principal plus all earned interest at maturity. Write a function, called CompoundInterestSchedule, that creates and returns a pandas DataFrame, where each row has: time (in years, an integer starting at 1), starting balance, interest earned, and ending balance, for an investment earning compoundedinterest. Use a for(or while) loop to create this table. The equation for theith year's ending balance is given by: Ei =Bi (1+r/f)f where: Ei is year i's ending balance Bi is year i's beginning balance (note: B1 is the amount of the initial investment (principal) r is the annual rate of interest (in decimal, e.g., 5% is .05) f is the number of times the interest rate compounds (times per year) The interest earned for a given year is Ei - Bi Note the term of the investment (in years) is not in the above equation; it is used…arrow_forwardIt's important to note that the name of an array by itself is really a pointer to the first element of the array. Therefore passing an array to function is simple since you can just specify the name of the array. Are these statements true?arrow_forwardWrite a C++ program that reads a list of numbers from a file into an array, then uses that array to find the average of all the numbers, the average of the positive and negative numbers (0 is neither positive nor negative!), and the largest number. The point is to be able to store data in an array and do things with it Your program must contain at least the following four functions... read_list() This function will take as input parameters an array of integers and a string filename. It will open that file and read in numbers, storing them in the array, stopping at the end of the file. Remember that there are tricky issues with extra whitespace at the end of the file. You can assume the file contains only integers. The function will return the number of numbers that were read in.Note: In versions of Visual C++ pre-2010, when using the open function with a string argument, you must call the c_str() function on the string variable, such as:my_input_stream.open( filename.c_str() ) 2.…arrow_forward
- This is for C++ Design an application that uses three identical arrays of at least 20 integers. It should call each module on a different array, and display the number of swaps made by each algorithm. 8 Sorting Benchmarks (bubble, selection & insertion sort) The following represents the output from 3 separate files: BubbleSort, SelectSort and InsertionSort. Don't ask the user to enter any numbers, but 'hard code' the values in the "Original order" as shown. Original order:26 45 56 12 78 74 39 22 5 90 87 32 28 11 93 62 79 53 22 51Bubble Sorted:5 11 12 22 22 26 28 32 39 45 51 53 56 62 74 78 79 87 90 93Number of location swaps: 89 Original order:26 45 56 12 78 74 39 22 5 90 87 32 28 11 93 62 79 53 22 51Selection Sorted:5 11 12 22 22 26 28 32 39 45 51 53 56 62 74 78 79 87 90 93Number of location swaps: 19 Original order:26 45 56 12 78 74 39 22 5 90 87 32 28 11 93 62 79 53 22 51Insertion Sorted:5 11 12 22 22 26 28 32 39 45 51 53 56 62 74 78 79 87 90 93Number of location…arrow_forwardA1: File Handling with struct C++ This program is to read a given file and display the information about employees according to the type of employee. Specifically, the requirements are as follows. Read the given file of the information of employees. Store the information in an array or arrays. Display all the salaried employees first and then the hourly employees Prompt the user to enter an SSN and find the corresponding employee and display the information of that employee. NOTE : S- salaryemployee , H- Hourly employee S 135-25-1234 Smith Sophia DevOps Developer 70000H 135-67-5462 Johnaon Jacob SecOps Pentester 30 60.50S 252-34-6728 William Emma DevOps DBExpert 100000S 237-12-1289 Miller Mason DevOps CloudArchitect 80000S 581-23-4536 Jones Jayden SecOps Pentester 250000S 501-56-9724 Rogers Mia DevOps Auditor 90000H 408-67-8234 Cook Chloe DevOps QAEngineer 40 45.10S 516-34-6524 Morris Daniel DevOps ProductOwner 300000H 526-47-2435 Smith Natalie DevOps…arrow_forwardHow can solve this problem using for looparrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education