Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given the following C++ program below. Complete the program by wrting the functions InputRideData, AvgDuration, CountGender, AvgAgeOfGender, and SearchForBikeID. What each function should contain is

Given the following C++ program below. Complete the program by wrting the functions InputRideData, AvgDuration, CountGender, AvgAgeOfGender, and SearchForBikeID. What each function should contain is in the comment above the name of the function as shown. The two filnames are data1.txt and data2.txt. The files contain in a single row; the bikeid, duration, gender, and birthyear. Data1.txt contains the following: 3808 311 1 1984 1756 309 1 1991 253 524 1 1973 253 423 1 1973 881 477 1 1990 519 535 1 1972 1756 321 1 1993 Data2.txt contains the following data: 609 1045 1 1993 1207 1035 1 1993 4369 1166 1 1988 2703 1348 2 1992 3828 1101 1 1987 4377 199 1 1984 3115 439 1 1984 After filling out the functions, run the program and produce your output. #include #include #include #include #include #include using namespace std; // // InputRideData // // Inputs the ride data from the given file, storing each ride across the // 4 arrays. The # of rides stored into the arrays is returned. // int InputRideData(string filename, int bikeids[], int durations[], int genders[], int birthyears[]) { // // TODO: // return 0; } // // AvgDuration // // Returns the average ride duration. // double AvgDuration(int durations[], int N) { // // TODO: // return 0.0; } // // CountGender // // Counts and returns the # of riders that identify as the // given gender. // int CountGender(int gender, int genders[], int N) { // // TODO: // return 0; } // // AvgAgeOfGender // // Computes the average age of riders that identify as the // given gender. The age of a rider is roughly determined // by the current year 2018 - their birthyear. // double AvgAgeOfGender(int gender, int genders[], int birthyears[], int N) { // // TODO: // return 0.0; } // // SearchForBikeID // // Searches for the given bikeid to see if it was ridden at least once. // Returns true if so, false if not. // bool SearchForBikeID(int bikeid, int bikeids[], int N) { // // TODO: // return false; } // // Main: // int main() { int bikeids[5000]; int durations[5000]; int genders[5000]; int birthyears[5000]; int N; string filename; cin >> filename; cout << std::fixed; cout << std::setprecision(2); cout << "** Divvy Ride Analysis **" << endl; cout << endl; N = InputRideData(filename, bikeids, durations, genders, birthyears); cout << "# of rides: " << N << endl; double male = CountGender(1, genders, N); double female = CountGender(2, genders, N); double percentMale = (male / N) * 100.0; double percentFemale = (female / N) * 100.0; cout << "% of male riders: " << percentMale << "%" << endl; cout << "% of female riders: " << percentFemale << "%" << endl; double avg = AvgDuration(durations, N) / 60.0; cout << "Avg duration: " << avg << " mins" << endl; double avgMaleAge = AvgAgeOfGender(1, genders, birthyears, N); double avgFemaleAge = AvgAgeOfGender(2, genders, birthyears, N); cout << "Avg age of male riders: " << avgMaleAge << " years old" << endl; cout << "Avg age of female riders: " << avgFemaleAge << " years old" << endl; // // allow user to search for a bike: // int bikeid; cout << endl; cout << "Bike id? > "; cin >> bikeid; while (bikeid > 0) { if (SearchForBikeID(bikeid, bikeids, N)) cout << bikeid << " was ridden" << endl; else cout << bikeid << " was *not* ridden" << endl; cout << "Bike id? > "; cin >> bikeid; } // // Done: // cout << endl; cout << "** Done **" << endl; return 0; }

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

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

Students also viewed these Databases questions

Question

25.0 m C B A 52.0 m 65.0 m

Answered: 1 week ago

Question

1. PricewaterhouseCoopers

Answered: 1 week ago

Question

3. SCC Soft Computer

Answered: 1 week ago