Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //York Li Project 1
- /*Suppose that the tuition for a university is $10,000 and increases 5% every year.
- Write a function that uses a loop to compute the tuition in ten years.
- Write another function in the same program that computes the total cost of four year's worth of tuition starting ten years from now.
- Write a driver main program to test each of your functions.
- */
- #include <cstdlib>
- #include <iostream>
- #include <iomanip>
- using namespace std;
- void tuition(double [],double); //function prototypes
- double future(const double []);
- int main()
- {
- double yearlyIncrease[14]; //Tuition history
- yearlyIncrease[0] = 10000; //Setting array 0 to starting tuition of $10,000
- double totalTuition; //Total cost of four year's worth of tuition starting ten years from now
- const double rate = 0.05; //Annual tuition increase rate
- tuition(yearlyIncrease,rate); //Map out tuition costs for next 13 years
- totalTuition = future(yearlyIncrease); //Calculates the total cost of four year's worth of tuition starting ten years from now
- cout<<"The tuition after 10 years is $"<<yearlyIncrease[10]<<endl; //Accessing the 11th array to find the tuition cost of one year tens years from now.
- cout<<"The total cost for 4 year's worth of tuition starting ten years from now is"<<endl<<"$"<<totalTuition<<endl;
- system("pause");
- return 0;
- }
- void tuition(double history [],double rate) //Function that uses a loop to compute the tuition in thirteen years
- {
- for(int i = 1; i < 14; i++)
- history[i]=history[i-1]+history[i-1]*rate; //Next year's tuition cost is 105% of last year's
- }
- double future(const double history []) //Function that computes the total cost of four year's worth of tuition starting ten years from now
- {
- double total=0;
- for(int i = 10; i < 14; i++) //Adds up tuition 10,11,12,13 years from now
- total+=history[i];
- return total;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement