Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CAN ANY ONE HELP WITH THIS QUESTION, I posted this question for 9th time, the answer I got no output file at all. I posted

CAN ANY ONE HELP WITH THIS QUESTION,

I posted this question for 9th time, the answer I got no output file at all.

I posted an inventory example program, and can you write a C++ program based on that.Thanks!!!!

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

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.

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.

universities.txt file

______________________

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

please Answer the question according to this example

NOTE THAT IN UNIVERSITY PROGRAM CITY IS NOT OUTPUT!!!!

step1-5 inventory program

#include #include #include #include using namespace std; #define MAX 50 //declare functions int getData(int id[], double price[], int qty[], int rop[]); double avgPrice(double price[], int num); void search(int arr[], int num, double price[], double target); 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; double avg; //Input the entire contents of the product file number = getData( id, price, qty, rop); //These statements will be removed once everything is working //Instead will be a call to output cout << "Number of Items in inventory: " << number << endl; for (int i = 0; i < number; i++) cout << id[i] << " " << price[i] << " " << qty[i] <<" " << rop[i] << endl; //Compute average price avg = avgPrice(price, number); cout << "Average cost of all items in invntory: $" << setprecision(2) << fixed << avg << endl; //Search for items less than $15.00 search(id, number, price, 15.00); system("pause"); return 0; } int getData( int id[], double price[], int qty[], int rop[]) { /* 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 Post: how many products Purpose: Input the inventory from data file */ //Open file ifstream inFile; inFile.open("products.txt"); if(inFile.fail()) { cout << "No Such File" << endl; } int count = 0; while ( count < MAX && !inFile.eof()) { inFile >> id[count] >> price[count] >> qty[count] >> rop[count]; count++; } return count; } double avgPrice(double price[], int num) { double avg = 0; for(int i = 0; i < num; i++) avg += price[i]; if(avg > 0) avg = avg / num; return avg; }//avgPrice void search(int arr[], int num, double price[], double target) { int loc = -1; cout << target; for (int i = 0; i < num; i++) { if (price[i] <= target){ cout << arr[i] << " less that " << target << endl; loc = 1; } } if (loc == -1) cout << "All items greater than: " << target << endl; return; }// 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 6 will be a mutation of the following code:

int search(int arr[], int num, int target) { /* Pre: arr[] - values being searched num - number of values to be searched through target - value being searched for Post: index of where it was found or -1 if not found Purpose: find location of value being searched for*/ int loc = -1; for (int i = 0; i < num; i++) { if (arr[i] == target) loc = i; } return loc; }// Steps 7 & 8 will be a mutation of the following code: void sortSelect(int arr[], int num, double price[], int qty[], int rop[]) { int current; int walker; int smallestIndex; int temp; double tempDbl; for (current = 0; current < num - 1; current++) { smallestIndex = current; for (walker = current; walker < num; walker++) { if (arr[walker] < arr[smallestIndex]) smallestIndex = walker; }//for walker //Swap to position smallest at what is the current position temp = arr[current]; arr[current] = arr[smallestIndex]; arr[smallestIndex] = temp; temp = qty[current]; qty[current] = qty[smallestIndex]; qty[smallestIndex] = temp; temp = rop[current]; rop[current] = rop[smallestIndex]; rop[smallestIndex] = temp; tempDbl = price[current]; price[current] = price[smallestIndex]; price[smallestIndex] = tempDbl; }//for current return; } int mostExpensive(double cost[], int num) { int highIndex = 0; for (int i = 0; i < num; i++) { if (cost[i] > cost[highIndex]) highIndex = i; } return highIndex; } 
Steps 7 & 8 will be a mutation of the following code: void sortSelect(int arr[], int num, double price[], int qty[], int rop[]) { int current; int walker; int smallestIndex; int temp; double tempDbl; for (current = 0; current < num - 1; current++) { smallestIndex = current; for (walker = current; walker < num; walker++) { if (arr[walker] < arr[smallestIndex]) smallestIndex = walker; }//for walker //Swap to position smallest at what is the current position temp = arr[current]; arr[current] = arr[smallestIndex]; arr[smallestIndex] = temp; temp = qty[current]; qty[current] = qty[smallestIndex]; qty[smallestIndex] = temp; temp = rop[current]; rop[current] = rop[smallestIndex]; rop[smallestIndex] = temp; tempDbl = price[current]; price[current] = price[smallestIndex]; price[smallestIndex] = tempDbl; }//for current return; } int mostExpensive(double cost[], int num) { int highIndex = 0; for (int i = 0; i < num; i++) { if (cost[i] > cost[highIndex]) highIndex = i; } return highIndex; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Advanced Database Systems For Integration Of Media And User Environments 98

Authors: Yahiko Kambayashi, Akifumi Makinouchi, Shunsuke Uemura, Katsumi Tanaka, Yoshifumi Masunaga

1st Edition

9810234368, 978-9810234362

More Books

Students also viewed these Databases questions

Question

Describe the five components of the triggers sheet that Kirk used.

Answered: 1 week ago

Question

Evaluate 3x - x for x = -2 Answer:

Answered: 1 week ago

Question

Prepare and properly label figures and tables for written reports.

Answered: 1 week ago