Pages

Tuesday, August 13, 2013

Write a program that calculate Strange College Fees in C++

This program prints the tuition at Strange College Fees. Strange Charges $10 for
registration, plus $10 per unit and a penalty of $50 for each 12 units,
 or fraction of 12, over 12.

Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
    #include <iostream.h>
    #include <conio.h>
   using namespace std;
   
   const int regFee      = 10;
   const int unitFee     = 10;
   const int excessFee   = 50;
   // Prototype Declarations
   int calculateFee   (int firstTerm,
                       int secondTerm,
                       int thirdTerm);
   int termFee (int units);
   int main ()
   {
       cout << " Enter units for  First term:     ";
       int firstTerm;
       cin  >> firstTerm;
       
       cout << " Enter units for Second term:     ";
       int secondTerm;
       cin  >> secondTerm;
       
       cout << " Enter units for  Third term:     ";
       int thirdTerm;
       cin  >> thirdTerm;
       
       int totalFee;
       totalFee = calculateFee
                   (firstTerm, secondTerm, thirdTerm);
       cout << "\n The total tuition is :\t" << totalFee;
       getch ();
       return 0;
       }// main
       /* ================ CalculateFee =====================
       Calculate the total fees for the year.
              Pre  The number units to be taken each term 
              Post Return the annual fees            */
       int calculateFee (int firstTerm, 
                         int secondTerm,
                         int thirdTerm)
     { 
           int fee = termFee (firstTerm)
                   + termFee(secondTerm)
                   + termFee (thirdTerm);
      getch ();             
      return fee;
     }// calculationFee
     /* ================ termfees =======================
             Calculate the tuition for one term.
        Pre  units contains units to be taken in the term
        Post the fee is calculated and returned        */
     
     int termFee (int units) 
     {
         int totalFee = regFee
                   + ((units - 1) / 12 * excessFee)
                   +  (units * unitFee);
      
      return (totalFee);
      getch();
      } // termFee   

Result:


 Enter units for  First term:     10
 Enter units for Second term:     20
 Enter units for  Third term:     30 

 The total tuition is :   780

No comments:

Post a Comment