Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

PLEASE ANSWER THIS QUESTION based on the sample program I posted!!!!!!!!!! I posted this question yesterday the answer I got it's not clear and is

PLEASE ANSWER THIS QUESTION based on the sample program I posted!!!!!!!!!!

I posted this question yesterday the answer I got it's not clear and is not follow checkpoints, Ruberic. If you see the instruction the function types are given below. can you please write the code based on the example code i posted.

it contains all the functions and based on the code i posted below, while the out put functions ,doesn't print out the sample output.And I don't also understand all the numbers in cout <<.... statments.

write a C++program to analyze a small subset of the data that has been collected. See file universities.txt .Use precisely seven parallel arrays: one for name of university, one for state, one for city, one for yearly tuition, one for enrollment, one for average freshman retention, and one for the percent of students who graduate with in six years.

Note that the percentage of student accepted is not stored.An output file is opened in main() and remains open until the end of the execution.

Input: Write a function to input the name of each university, the two-letter abbreviation for the state, the city, tuition, enrollment, average freshman retention rate, percent that graduate within six years.

Repeat until end of file. Assume a maximum of 1000 universities.Use getline(file, string name) to input text with spaces. You will find a very mischievous character to deal with at the end of the six values. You will enjoy knowing about getline(file, tempstr);where tempstr has been declared as a string type.

Output: Write a separate function to output to the file all universities with name of university, state, tuition, enrollment, percentage retention for freshman, and percentage that have graduated after six years for each.NOTE THAT THE

universities.txt

Princeton University

NJ Princeton

41820 8014 0.0740 0.98 0.97

Harvard University

MA Cambridge

43838 19882 0.0580 0.97 0.97

Yale University

CT New Haven

45800 12109 0.0690 0.99 0.98

Columbia University

NY New York

51008 23606 0.0690 0.99 0.96

Stanford University

CA Stanford

44757 18136 0.0570 0.98 0.96

University of Chicago

IL Chicago

48253 12539 0.0880 0.99 0.93

Massachusetts Institute of Technology

MA Cambridge

45016 11301 0.0820 0.98 0.93

Duke University

NC Durham

47488 15465 0.1240 0.97 0.94

University of Pennsylvania

PA Philadelphia

47668 21358 0.1220 0.98 0.96

California Institute of Technology

CA Pasadena

43362 2181 0.1060 0.97 0.93

Dartmouth College

NH Hanover

48108 6342 0.1040 0.98 0.95

Johns Hopkins University

MD Baltimore

47060 21052 0.1710 0.97 0.93

Northwestern University

IL Evanston

47251 20997 0.1400 0.97 0.94

Washington University in St. Louis

MO St. Louis

46467 14032 0.1560 0.97 0.94

Cornell University

NY Ithaca

47286 21593 0.1560 0.97 0.93

Brown University

RI Providence

47434 8943 0.0920 0.98 0.94

University of Notre Dame

IN Notre Dame

46237 12124 0.2230 0.98 0.95

Vanderbilt University

TN Nashville

43838 12757 0.1270 0.97 0.93

Rice University

TX Houston

40566 6628 0.1670 0.97 0.91

University of California-Berkeley

CA Berkeley

25064 36204 0.1770 0.97 0.91

Emory University

GA Atlanta

45008 14513 0.2650 0.95 0.91

Georgetown University

DC Washington

46744 17849 0.1710 0.96 0.92

University of California-Los Angeles

CA Los Angeles

25064 42190 0.2040 0.97 0.90

University of Virginia

VA Charlottesville

42184 23464 0.3010 0.97 0.93

Carnegie Mellon University

PA Pittsburgh

48786 12991 0.2550 0.95 0.88

University of Southern California

CA Los Angeles

48280 41368 0.1980 0.97 0.91

CITY IS NOT OUTPUT.

Processing:

? Call the output function to output to a file all data in the original order.

? Write a separate function to compute and return the average tuition for all universities.

Do not output from this function but return the value and print it out to the screen from main().

? Write a function to ask the user for maximum he/she can pay for tuition. List to the screen the name only of all schools with that amount or less for tuition.Output is from within the function.

? Write a function to prompt the user for a two-letter abbreviation for a state. Output to the file from this function all information for colleges within that state or output message No colleges in XX state in the list.

? Write one and only one function to return the subscript of the university with the lowest tuition. There is no output in this function. Do not assume a sorted array. In main(), the name(s) of the university or universities with this low tuition and the amount of the tuition are output to the screen.

? Use a selection sort to sort universities by enrollment in ascending order. This is written as a separate function with no output.

? Write the sorted array to the file

THEME ISSUES one-dimensional arrays,if statements, file input,file output,searching, sorting

Absolutelyno two-dimensional arrays, no structures and no menu function.

Sample output before sorting:

University State Tuition Enrollment % Fresh %Gradeuate in sixyears

suceed

Princeton University NJ 41820.00 8014 98.00% 97.00%

Harvard University MA 43938.00 19882 97.00% 97.00%

Yale University CT 45800.00 12109 99.00% 98.00%

Columbia University NY 51008.00 23606 99.00% 96.00%

Stanford University CA 44757.00 18136 98.00% 96.00%

University of Chicago IL 48253.00 12539 99.93.00% 93.00%

Massachusetts Institute of Technology MA 45016.00 11301 98.00% 93.00%

How should you do this?Follow these steps carefully!!!!!!!

STEP 1 Write main() and call getData() function which only opens file.Debug.

STEP 2 Complete getdata().Debug.

STEP 3 Write output function.Output is directed to the output file and NOT the screen.Debug.

STEP 4 Write the function to compute the average of tuition at all schools. Output this value to the screen

from main().Debug.

STEP 5 Write a function that will output the name only of each university where the tuition is less than or equal to

the given amount. Output to the screen.

STEP 6 Write a function to prompt the user for a two-letter abbreviation for a state. Output to the file

from this function all information for colleges within that state or output message No colleges in XX state in the

list. Debug.

STEP 7 Write one and only one function to return the subscript of the university with the lowest tuition. There

is no output in this function. Do not assume a sorted array. In main(),the name(s) of the university or

universities with this low tuition and the amount of the tuition are output to the screen.

STEP 8 Write a separate function using the selection sort to sort universities by enrollment in ascending order.Debug

Checkpoints

Documentation throughout to explain general outline of program.Minimum of three (3) comments in each function

(Purpose: Pre: Post:)Include name, e-mail, and lab# as comment and printed to output

Function main() which implements each step outlined in the processing section of the lab write-up.

Input function fills array for names plus four numerical arrays. It should return the number ofuniversities.

Output function

Function to compute the average of tuition at all schools

Function to output to screen universities where tuition is less than or equal to given amount.

Function to prompt the user for a two-letter abbreviation for a state. Output to the file from this function

all information for colleges within that state or output message No colleges in XX state in the list.

Write one and only one function to return the subscript of the university with the lowest tuition. There is

no output in this function. Do not assume a sorted array. In main() the name(s) of the university or

universities with this low tuition and the amount of the tuition are outputto the screen.

Function using the selection sort to sort universities by enrollment in ascending order.

can you do according to this program

/*Using the products.txt file, write a function to input the info into parallel arrays. Output the entire inventory to the screen.

Add to this program a selection sort to output the products from the lowest to the highest. Output the result from main().

Add a function that will output the quantity on hand and the price when given the product ID code.

Add a function to output the product IDs and current number in stock for all products needing to be reordered. */

#include #include using namespace std;

#define MAX 50 //declare functions int getData(ifstream& inFile, int id[], double price[], int qty[], int rop[]); void output(int id[], double price[], int qty[], int rop[], int num); int seqSearch(int id[], int n, int target); void sortSelect(double arr[], int n, int id[], int qty[], int rop[]);

int main(void) { //Declare variables ifstream inFile; int id[MAX]; double price[MAX]; int qty[MAX]; int rop[MAX]; int number; int target; int loc;

//Open file inFile.open("products.txt"); if(inFile.fail()) { cout << "No Such File" << endl; } //Input the entire contents of the product file number = getData(inFile, id, price, qty, rop); //Output each product's id, quantity on hand, re-order point, and price output(id, price, qty, rop, number); //Looking for a particular product cout << "Enter product number your are looking for: "; cin >> target; loc = seqSearch(id, number, target); if(loc == -1) cout << "No such product!" << endl; else cout << "Price:" << price[loc]<< " " << "Quantity: " << qty[loc]<< endl;

//Sort by the price of the product (low to high) sortSelect(price, number, id, qty, rop);

//Output each product's id, quantity on hand, re-order point, and price output(id, price, qty, rop, number); system("pause"); return 0; }//main //////////////////////////////////////// int getData(ifstream& inFile, int id[], double price[], int qty[], int rop[]) { /* Pre: inFile - reference to the data file id[] - array of product identification numbers price[] - array of cost for each product qty[] - array of number of product in the warehouse rop[] - array of when to reorder that product Post: how many products Purpose: Input the inventory from data file */ int count = 0; while ( count < MAX && !inFile.eof()) { inFile >> id[count] >> price[count] >> qty[count] >> rop[count]; count++; } return count; }//getData //////////////////////////////// int seqSearch(int arr[], int n, int target) { /* Pre: arr - array of values n - number of defined values target - what we are looking for Post: Location of what we are looking for or -1 if not found Purpose: Find the location of value */ int loc = -1; for(int i = 0; i < n; i++) { if (target == arr[i]) loc = i; } return loc; }//seqSearch //////////////////////////////////////////////// void sortSelect(double arr[], int n, int id[], int qty[], int rop[]) { /* Pre: arr[] - array of values n - number of elements Post: Nothing Purpose: sort elements from low to high */ int walker; int current; int smallestIndex; double tempDouble; int tempInt; for (current = 0; current < n - 1; current++) { smallestIndex = current; for(walker = current + 1; walker < n; walker++) { if(arr[walker] < arr[smallestIndex]) smallestIndex = walker; }//for walker //Swap tempDouble = arr[current]; arr[current] = arr[smallestIndex]; arr[smallestIndex] = tempDouble;

tempInt = id[current]; id[current] = id[smallestIndex]; id[smallestIndex] = tempInt; tempInt = qty[current]; qty[current] = qty[smallestIndex]; qty[smallestIndex] = tempInt; tempInt = rop[current]; rop[current] = rop[smallestIndex]; rop[smallestIndex] = tempInt;

}//for current } void output(int id[], double price[], int qty[], int rop[], int n) { /* Pre: id[] - array of product identification numbers price[] - array of cost for each product qty[] - array of number of product in the warehouse rop[] - array of when to reorder that product n - number of products in our inventory Post: nothing Purpose: Output the inventory to screen */ for (int i = 0; i < n; i++) cout << id[i] << " " << price[i] << " " << qty[i] <<" " << rop[i] << endl; return; }//output

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions