170k views
0 votes
Write a C++ program using object-oriented principles that will display the National Champion of NCAA College Football for the year the user enters. The valid years that may be entered are from 1998 - 2022. An input file - named NationalChampionship.txt - has been created that contains: the year and the school team that won the National Championship. It should be located in the current directory. To begin, the program should declare two arrays: one array to hold the year and another array to hold the school and team name. Populate the arrays with the values read in from the input file. Close the input file. Next, the program should prompt the user to enter a year. Validate the user's input value. If the user enters an invalid year, display an error message and let the user retry as many times as needed. When a good input year is entered, the program must find the corresponding year in the first array. Then, the program must look in the second array to find the name of the team that won the national championship for that year. Display that value. Continue to prompt the user for another year until the user wishes to stop. Make it clear how you would like for the user to stop.

User Jan Doggen
by
7.8k points

1 Answer

4 votes

Final answer:

The student's question about writing a C++ program to display NCAA College Football Champions by year involves using object-oriented principles to read from a file, store the data in arrays, and respond to user queries. The provided outline demonstrates how one might structure such a program using a ChampionDatabase class and a main function that manages user interaction.

Step-by-step explanation:

The student requested help with writing a C++ program that displays the National Champion of NCAA College Football for a year entered by the user. This program relies on object-oriented principles and file I/O operations to function correctly.

The years range from 1998 to 2022. In response to this request, an example of such a program is presented here. The program reads the champion data from 'NationalChampionship.txt', stores it in arrays, allows the user to query the data by entering a year, and continues to prompt for years until the user decides to stop. Below is a potential implementation skeleton that fulfills the requirements:

#include
#include
#include

class ChampionDatabase {
private:
int years[25];
std::string teams[25];

public:
ChampionDatabase() { /* Read file and populate arrays */ }
std::string GetChampion(int year) { /* Return the champion for the given year */ }
// ... additional methods as appropriate ...
};

int main() {
ChampionDatabase db;
int year;
std::string input;
std::string champion;

do {
std::cout << "Enter the year to find the National Champion (1998-2022), or type 'quit' to exit: ";
std::cin >> input;

if (input == "quit") break;

// Input validation and querying logic here...

} while (true);

return 0;
}

Notice that the ChampionDatabase class is responsible for reading from the input file and providing a method to lookup the champion given a year.

The main function handles the user interaction. This is only the skeleton of the program, and further implementation of reading the file, populating the arrays, handling input validation, and providing output would be required for a full solution.

User Pepper
by
7.7k points