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 ‘\n’ 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 <iostream>
#include <fstream>
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
#include<iostream>
#include<string>
using namespace std;
int isValid(string input);
string get_input();
int main()
{
string input,re_str;
input = get_input();
int count = 0;
if (input != "")
{
//ask use to re enter
cout << input << " is a
valid password" << endl;
do
{
if (count++
>= 3)
break;
cout <<
"\nre-enter the password for validation: ";
cin >>
re_str;
if (input !=
re_str)
{
cout << "\n\<< password " <<
input << " does not match " << re_str <<"
>>"<< endl;
}
}while (re_str != input);
if (count == 3)
{
cout <<
"Session has been locked" << endl;
exit(-2);
}
if (input == re_str)
{
cout <<
"\n\n" << "*** Password has been approved***\n";
}
}
}
int isValid(string input)
{
if (input.length() < 8)
{
return -1; //in case length of
password not valid
}
int upper=0, lower = 0,number=0;
for (int i = 0; i < input.length(); i++)
{
if (isupper(input[i]))
{
upper++;
}
else if (islower(input[i]))
{
lower++;
}
else
{
if
(isdigit(input[i]))
{
number++;
}
}
}
int ret = 0;
if (upper == 0)
ret = -2;
if (lower == 0)
ret= -3;
if (number == 0)
ret = -4;
if (upper == 0 && number == 0)
ret = -5;
if (lower == 0 && number == 0)
ret= -6;
return ret;
}
string get_input()
{
string input="";
char c;
int count = 0;
do
{
cout <<
"==================================================================="
<< endl;
cout << "Enter a password
that contains: ";
cout << "At least eight (8)
characters, including\nat least one number\nat least one upper case
letter\nand at leaset one lower case letter\n";
cout << "Password: ";
while ((c = getchar()) !=
'\n')
{
input +=
c;
}
if (input == "")
{
cout <<
"Invalid input\n";
++count;
input.clear();
input =
"";
continue;
}
int ret = isValid(input);
if (ret < 0)
switch
(ret)
{
case -1:
cout << "Length of the password must be
atleast 8 char long\n";
break;
case -2:
cout << input << " is not a valid
pasword" << endl;
cout << "It does not contain a uppercase
character\n";
break;
case -3:
cout << input << " is not a valid
pasword" << endl;
cout << "It does not contain a lowercase
character\n";
break;
case -4:
cout << input << " is not a valid
pasword" << endl;
cout << "It does not contain a
number\n";
break;
case -5:
cout << input << " is not a valid
pasword" << endl;
cout << "It does not contain a
number\n";
break;
case -6:
cout << input << " is not a valid
pasword" << endl;
cout << "It does not contain a lowercase"
<< endl;
cout << "It does not contain a
number\n";
break;
}
else
break;
++count;
input.clear();
input = "";
} while (count < 3);
if (count == 3)
{
cout << "Session has been
locked!!";
exit(-1);
}
return input;
}
=========================================================================
/*Output
===================================================================
Enter a password that contains: At least eight (8) characters,
including
at least one number
at least one upper case letter
and at leaset one lower case letter
Password: GoodPassword1
GoodPassword1 is a valid password
re-enter the password for validation: goodPassword1
<< password GoodPassword1 does not match goodPassword1 >>
re-enter the password for validation: GoodPassword1
*** Password has been approved***
*/
/*Run2
===================================================================
Enter a password that contains: At least eight (8) characters,
including
at least one number
at least one upper case letter
and at leaset one lower case letter
Password: 1upperprocessing
1upperprocessing is not a valid pasword
It does not contain a uppercase character
===================================================================
Enter a password that contains: At least eight (8) characters,
including
at least one number
at least one upper case letter
and at leaset one lower case letter
Password: LOWERRANDOMNUMBERPROCESS
LOWERRANDOMNUMBERPROCESS is not a valid pasword
It does not contain a lowercase
It does not contain a number
===================================================================
Enter a password that contains: At least eight (8) characters,
including
at least one number
at least one upper case letter
and at leaset one lower case letter
Password: jhhkjhljlkj
jhhkjhljlkj is not a valid pasword
It does not contain a number
Session has been locked!!
*/
/*Run3
===================================================================
Enter a password that contains: At least eight (8) characters,
including
at least one number
at least one upper case letter
and at leaset one lower case letter
Password: GoodPassword1
GoodPassword1 is a valid password
re-enter the password for validation: goodPassword!
<< password GoodPassword1 does not match goodPassword! >>
re-enter the password for validation: goodpassword1
<< password GoodPassword1 does not match goodpassword1 >>
re-enter the password for validation: goddPassword!
<< password GoodPassword1 does not match goddPassword!
>>
Session has been locked
*/
write a C++program to analyze a small subset of the data that has been collected. See...
Please!!! need help asap!!!! 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...
The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...
Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...
C++ Write a program to compute the mean, median, mode, and sample standard deviation. Output results to output file and screen. Steps: 1. Populate an array of 99 integers (1-9 inclusively) which are generated randomly. 2. Compute mean, median, mode(with histogram) and sample standard deviation. Use similar functions: void populater (int [], int); double mean (const int [], int, ofstream&); void mode (int [], const int [], int, ofstream&); void median (int [], int, ofstream&); void sort (int [], int);...
(C++ programming) Need help with homework. Write a program that can be used to gather statistical data about the number of hours per week college students play video games. The program should perform the following steps: 1). Read data from the input file into a dynamically allocated array. The first number in the input file, n, represents the number of students that were surveyed. First read this number then use it to dynamically allocate an array of n integers. On...
Write a C program that takes inventory data from a file and loads a structure of up to 100 items defined as: struct item { int item_number; char item_name[20]; char item_desc[30]; float item_price; } I called mine: struct item inventory[100]; (you may use any name you wish) I will let you decide the appropriate prompts and edit messages. You will read the data from the data file and store the info in an array. Assume no more than 100 records...
in c++ please program for this code #include <iostream> #include <fstream> #include <string> #include <cstring> // for string tokenizer and c-style string processing #include <algorithm> // max function #include <stdlib.h> #include <time.h> using namespace std; // Extend the code here as needed class BTNode{ private: int nodeid; int data; int levelNum; BTNode* leftChildPtr; BTNode* rightChildPtr; public: BTNode(){} void setNodeId(int id){ nodeid = id; } int getNodeId(){ return nodeid; } void setData(int d){ data = d; } int getData(){ return data;...
Hello I need a small fix in my program. I need to display the youngest student and the average age of all of the students. It is not working Thanks. #include <iostream> #include <iomanip> #include <fstream> #include <vector> #include <algorithm> using namespace std; struct Student { string firstName; char middleName; string lastName; char collegeCode; int locCode; int seqCode; int age; }; struct sort_by_age { inline bool operator() (const Student& s1, const Student& s2) { return (s1.age < s2.age); // sort...
Write a program in C++ that simulates a soft drink machine. The program will need several classes: DrinkItem, DrinkMachine and Receipt. For each of the classes you must create the constructors and member functions required below. You can, optionally, add additional private member functions that can be used for doing implementation work within the class. DrinkItem class The DrinkItem class will contains the following private data members: name: Drink name (type of drink – read in from a file). Type...
Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...