×
Samples Blogs Make Payment About Us Reviews 4.9/5 Order Now

Create a Program to Analyze Park Data in C++ Assignment Solution

July 15, 2024
Dr. Benjamin Hughes
Dr. Benjamin
🇬🇧 United Kingdom
C++
Dr. Benjamin Hughes holds a Ph.D. in Computer Science from the University of Cambridge and has over 10 years of experience in software development and programming education. With expertise in Templated Linked Lists, he has completed over 800 assignments with precision and efficiency, helping students across the globe excel in their programming coursework.
Key Topics
  • Instructions
  • Requirements and Specifications
Tip of the day
Ensure you understand the dataset thoroughly before starting your machine learning assignment. Visualize the data, check for missing values, and identify patterns or anomalies to guide your model-building process effectively.
News
In 2024, universities have introduced new programming courses focusing on cybersecurity, machine learning, and artificial intelligence to better prepare students for modern IT careers.

Instructions

Objective

Write a C++ assignment program to analyze park data.

Requirements and Specifications

program to analyze park data in C++
program to analyze park data in C++ 1

Source Code

#include #include #include #include using namespace std; void read_months(string months[12]) { // First, read the file ifstream inFile; // read months inFile.open("Months.txt"); if (!inFile.is_open()) { cout << "Could not open Months file." << endl; exit(1); } string line; int row = 0; while (inFile >> line) { months[row] = line; row++; } inFile.close(); } void read_visitors(int visitors[12][9]) { // Open Visitors.txt ifstream inFile; inFile.open("Visitors.txt"); if (!inFile.is_open()) { cout << "Could not open Visitors file." << endl; exit(1); } int number; int row = 0; int col = 0; while (inFile >> number) { visitors[row][col] = number; col++; if (col == 9) { col = 0; row++; } } inFile.close(); } void display_menu() { cout << "Enter 1 to display data" << endl; cout << "Enter 2 to diplay total number of Tent + RV + Concession + Backcountry Campers" << endl; cout << "Enter 3 to display total by month" << endl; cout << "Enter 4 to display the number of recreational visitors for a certain month" << endl; cout << "Enter any other number to exit" << endl << endl; } int get_menu_option() { // this function will request to user for an int int number; while (true) p> { cin >> number; return number; } } void display_data(string months[12], int visitors[12][9]) { cout << setfill(' ') << setw(13) << "Month"<< setfill(' ') << setw(13) << "T Rec" << setfill(' ') << setw(13) << "T Non-Rec" << setfill(' ') << setw(13) << "Con lodging" << setfill(' ') << setw(13) << "Tent" << setfill(' ') << setw(13) << "RV" << setfill(' ') << setw(13) << "Con Camp" << setfill(' ') << setw(13) << "BackCounty" << setfill(' ') << setw(13) << "Musc Camp" << setfill(' ') << setw(13) << "T Overnite" << endl; for (int i = 0; i < 12; i++) { cout << setfill(' ') << setw(13) << months[i] << setfill(' ') << setw(13); for (int j = 0; j < 9; j++) { cout << visitors[i][j] << setfill(' ') << setw(13); } cout << endl; } cout << endl; } void display_tent_rv_conc_cb(int visitors[12][9]) { int tent = 0; int rv = 0; int conc = 0; int cb = 0; for (int i = 0; i < 12; i++) { tent += visitors[i][3]; rv += visitors[i][4]; conc += visitors[i][5]; cb += visitors[i][6]; } cout << "The total number of Tent + RV + Concession + Backcountry Campers: " << (tent + rv + conc + cb) << endl << endl; } void display_total_by_month(string months[12], int visitors[12][9]) { cout << "Total all visitors by Month" << endl; int total_month; for (int i = 0; i < 12; i++) { // first, compute the total for month i total_month = 0; for (int j = 0; j < 9; j++) total_month += visitors[i][j]; cout << "\t" << months[i] << "\t" << total_month << endl; } cout << endl; } void display_recreational_by_month(string month, string months[12], int visitors[12][9]) { // first, get the month index int month_idx; for (int i = 0; i < 12; i++) { if (month.compare(months[i]) == 0) { month_idx = i; break; } } // Now, display the data for this month cout << "For the month of " << month << " there were " << visitors[month_idx][0] << " recreational visitors" << endl << endl; } int main() { // get months from files string months[12]; read_months(months); // create array to store visitors int visitors[12][9]; read_visitors(visitors); // BEgin with program int option; while (true) { display_menu(); option = get_menu_option(); if (option == 1) // display data display_data(months, visitors); else if (option == 2) // display Tent + RV + Concession+backcountry campers display_tent_rv_conc_cb(visitors); else if (option == 3) // total by month display_total_by_month(months, visitors); else if (option == 4) // display number of recreational visitors for a certain month { // ask user for month string month; cout << "Enter the month you want the number of recreational visitors" << endl; cin >> month; display_recreational_by_month(month, months, visitors); } else // any other number break; } }

Related Samples

Explore our C++ programming homework help samples to see how we tackle complex coding challenges with precision and clarity. Our curated examples showcase expertise in C++ concepts, from basic syntax to advanced algorithms, ensuring comprehensive assistance for your academic needs.