Advertisement
Guest User

Untitled

a guest
Sep 17th, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. //York Li Project 1
  2. /*Suppose that the tuition for a university is $10,000 and increases 5% every year.
  3. Write a function that uses a loop to compute the tuition in ten years.
  4. Write another function in the same program that computes the total cost of four year's worth of tuition starting ten years from now.
  5. Write a driver main program to test each of your functions.
  6. */
  7. #include <cstdlib>
  8. #include <iostream>
  9. #include <iomanip>
  10. using namespace std;
  11.  
  12. void tuition(double [],double); //function prototypes
  13. double future(const double []);
  14.  
  15. int main()
  16. {
  17. double yearlyIncrease[14]; //Tuition history
  18. yearlyIncrease[0] = 10000; //Setting array 0 to starting tuition of $10,000
  19. double totalTuition; //Total cost of four year's worth of tuition starting ten years from now
  20. const double rate = 0.05; //Annual tuition increase rate
  21.  
  22. tuition(yearlyIncrease,rate); //Map out tuition costs for next 13 years
  23. totalTuition = future(yearlyIncrease); //Calculates the total cost of four year's worth of tuition starting ten years from now
  24.  
  25. 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.
  26. cout<<"The total cost for 4 year's worth of tuition starting ten years from now is"<<endl<<"$"<<totalTuition<<endl;
  27.  
  28. system("pause");
  29. return 0;
  30. }
  31. void tuition(double history [],double rate) //Function that uses a loop to compute the tuition in thirteen years
  32. {
  33. for(int i = 1; i < 14; i++)
  34. history[i]=history[i-1]+history[i-1]*rate; //Next year's tuition cost is 105% of last year's
  35. }
  36. double future(const double history []) //Function that computes the total cost of four year's worth of tuition starting ten years from now
  37. {
  38. double total=0;
  39. for(int i = 10; i < 14; i++) //Adds up tuition 10,11,12,13 years from now
  40. total+=history[i];
  41. return total;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement