In: Computer Science
The Community College of Denver is proposing a new cost structure for its courses. The plan is to charge a higher cost for higher level courses in order to hiring highly skilled instructors for those courses. The course levels are as follows:
This new plan also includes a 2 percent per year cost increase for each level over the course of the next five years to bring the college closer to the national average.
Instructions
Design a program that first displays a menu then asks the user the number of credit hours they plan to take in one semester. Use this number to calculate the present semester tuition. The program should then display a menu that asks the user which course level to display in the report. (Note that only one course level can be displayed at a time!). Once the course level is selected, the program MUST use the per credit hour cost listed in the attached text file called tuitionAmounts.txt. Therefore, the initial tuition amounts must be read into the program from the text file and not hard-coded with the program. This allows the initial amounts to be changed in the text file an not in the code.
After the tuition amounts are read, then display the tuition for the level selected for the year by multiplying the semester tuition by 2. Next, create a loop that displays the projected yearly tuition amounts for the next five years. Therefore, the program should display 6 years of tuition with the first year representing the present tuition costs and the subsequent years representing a 2 percent increase each year.
Below is a representation of a sample run of your application. Your output results should be in table format and should resemble the following if the user selected 000 Level Courses:
CCA Tuition Program
-------------------------
1. 000 Level Courses
2. 100 Level Courses
3. 200 Level Courses
4. Exit Program
Select the course level or Exit: 1
Enter the number of credit hours for this semester: 12
Community College of Aurora Tuition Report Level 000 --------------------------------------------- |
|
Year ----- |
Tuition ------- |
Year 1 | $4278.00 |
Year 2 | $4363.56 |
Year 3 | $4450.83 |
Year 4 | $4539.85 |
Year 5 | $4630.64 |
Year 6 | $4723.26 |
Additional Requirements
C++
CODE -
#include<fstream>
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
ifstream infile;
int choice, num_hrs;
float cost_000, cost_100, cost_200;
string level;
float tution_cost;
// Opening file for reading
infile.open("tuitionAmounts.txt");
// Reading the per credit hour cost for different levels from the file.
infile >> cost_000;
infile >> cost_100;
infile >> cost_200;
// Closing the file
infile.close();
ofstream outfile;
// Opening the file for writing
outfile.open("TuitionReportResults.txt");
// Loop to run until user chooses to exit the program
while(true)
{
// Displaying the header and the menu
cout << "\nCCA Tuition Program" << endl;
cout << "-------------------------" << endl;
cout << "1. 000 Level Courses" << endl;
cout << "2. 100 Level Courses" << endl;
cout << "3. 200 Level Courses" << endl;
cout << "4. Exit Program" << endl;
// Taking choice as input from user
cout << "Select the course level or Exit: ";
cin >> choice;
// Loop to make sure user enters a valid choice.
while(choice>4 || choice<1)
{
cout << "Invalid Choice! Try again!" << endl;
cout << "Select the course level or Exit: ";
cin >> choice;
}
// Exiting the loop if user chooses 4
if (choice == 4)
break;
// Taking the no. of credit hours as input from user
cout << "Enter the number of credit hours for this semester: ";
cin >> num_hrs;
// Switch case to evaluate tution cost based on user's choice of level
switch(choice)
{
case 1:
tution_cost = cost_000 * 2 * num_hrs;
level = "000";
break;
case 2:
tution_cost = cost_100 * 2 * num_hrs;
cout << cost_100 << endl;
level = "100";
break;
case 3:
tution_cost = cost_200 * 2 * num_hrs;
level = "200";
break;
}
// Displaying and writing to file the header and the tuition costs for different years
cout << "\nCommunity College of Aurora Tuition Report" << endl;
outfile << "\nCommunity College of Aurora Tuition Report" << endl;
cout << setw(24) << "Level " << level << endl;
outfile << setw(24) << "Level " << level << endl;
cout << "---------------------------------------------" << endl;
outfile << "---------------------------------------------" << endl;
cout << std::left << setw(22) << "Year" << std::right << setw(23) << "Tuition" << endl;
outfile << std::left << setw(22) << "Year" << std::right << setw(23) << "Tuition" << endl;
cout << std::left << setw(22) << "-----" << std::right << setw(23) << "-------" << endl;
outfile << std::left << setw(22) << "-----" << std::right << setw(23) << "-------" << endl;
cout << fixed << setprecision(2);
outfile << fixed << setprecision(2);
cout << std::left << setw(20) << "Year 1" << std::right << setw(18) << "$" << tution_cost << endl;
outfile << std::left << setw(20) << "Year 1" << std::right << setw(18) << "$" << tution_cost << endl;
// Loop to display and write to file years 2 through 6
for (int i=2; i<=6; i++)
{
// Increasing the cost every year by 2%
tution_cost += 0.02 * tution_cost;
cout << "Year " << std::left << setw(15) << i << std::right << setw(18) << "$" << tution_cost << endl;
outfile << "Year " << std::left << setw(15) << i << std::right << setw(18) << "$" << tution_cost << endl;
}
}
// Closing the file.
outfile.close();
return 0;
}
SCREENSHOTS -
CODE -
INPUT TEXT FILE -
OUTPUT -
OUTPUT TEXT FILE -
If you have any doubt regarding the solution, then do
comment.
Do upvote.