View Single Post
Old 04-02-2005, 04:38 AM   #9 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
And when testing something isn't right.
This definitions isn't clear:
Quote:
Student Fee Calculator:
What semester am I calculating fees for? [F]all/[W]inter/
[S]pring/su[M]mer]:W
Are you a California resident? [y/n]: y
Do you need a parking sticket? [y/n]: y
Are you requesting an AS sticker refund? [y/n]: n
How many units will you enroll in? 12
Your 12 units will cost 374.00


Student Fee Calculator:
What semester am I calculating fees for? [F]all/[W]inter/
[S]pring/su[M]mer]:F
Are you a California resident? [y/n]: y
Do you need a parking sticket? [y/n]: y
Are you requesting an AS sticker refund? [y/n]: n
How many units will you enroll in? 12
Your 12 units will cost 412.00


Student Fee Calculator:
What semester am I calculating fees for? [F]all/[W]inter/
[S]pring/su[M]mer]:F
Are you a California resident? [y/n]: n
Are you a US citizen? [y/n]: n
Are you an F1 visa holder? [y/n]: y
Do you need a parking sticket? [y/n]: y
Are you requesting an AS sticker refund? [y/n]: n
How many units will you enroll in? 12
Your 12 units will cost 2157.00
vs this

Quote:
Student Services
$30.00 for Fall or Spring semester
$27.00 for Winter or Summer session

Parking
$75.00 for Fall or Spring semester
$35.00 for Winter or Summer session

Enrollment Per Unit
$26.00 / unit for California residents
$149.00 / unit for US residents
$171.00 / unit for F1 Visa holders

Associated Student Sticker Refund
$10.00 refund in Fall or Spring semester, if requested
$9.00 refund in Winter or Summer session, if requested
Besides, I advised you to wait with he menu. That's a whole different project.
First we do tests on the engine:
Code:
#include <iostream>

using namespace std;

//--
const double FALLSPRING_COST = 30.00;
const double WINTERSUMMER_COST = 27.00;
const double PARK_FALLSPRING_COST = 75.00;
const double PARK_WINTERSUMMER_COST = 45.00;
const double ENROLL_CALI = 26.00;
const double ENROLL_US = 149.00;
const double ENROLL_VISA = 171.00;
const double REFUND_FALLSPRING =  10.00;
const double REFUND_WINTERSUMMER = 9.00;
//--

//fsws true = FALLSPRING COST, false is WINTERSUMMER.
double student_services_cost(const bool fsws);
double parking_cost(const bool fsws);
double student_sticker_refund(const bool fsws);
//r: 'c' =  california, 'u' = US residents, 'v' =  visa holders;
double enrollment_cost(const char r, const unsigned units);

//---------------------------------------------

int main()
{
  bool bServiceSeason = false;
  bool bParkingSeason = false;
  bool bRefundSeason = false;
  char EnrollSeason = 'v';
  unsigned nParkingUnits = 12;
  
  double TotalCost = 0.0;
  
  TotalCost = student_services_cost(bServiceSeason) + parking_cost(bParkingSeason) +
  enrollment_cost(EnrollSeason, nParkingUnits) - student_sticker_refund(bRefundSeason);
  
  cout<<TotalCost<<endl;
  cin.get();
  return 0;
}

//----------------------------------------------

double student_services_cost(const bool fsws)
{
   if(fsws == true)
   {
      return FALLSPRING_COST;
   }
   return WINTERSUMMER_COST;
}

//----------------------------------------------

double parking_cost(const bool fsws)
{
  if(fsws == true)
   {
      return PARK_FALLSPRING_COST;
   }
   return PARK_WINTERSUMMER_COST;
}  

//----------------------------------------------

double student_sticker_refund(const bool fsws)
{
  if(fsws == true)
   {
      return REFUND_FALLSPRING;
   }
   return REFUND_WINTERSUMMER;
}

//----------------------------------------------

double enrollment_cost(const char r, const unsigned units)
{
  switch(r)
  {
    case 'c': return ENROLL_CALI*units;
    case 'u': return ENROLL_US*units;
    case 'v': return ENROLL_VISA*units;
  }  
}
Test until you're convinced.
Then make a single function to "hide" the implementation of the formula.
Something like this:
Code:
void total_cost(const bool serviceSeason, const bool parkingSeason, const bool refundSeason,
  const char enrollSeason, const unsigned units, double& total );
Observe the ampsersand for total. We pass a double by reference because your teacher want you to demonstrate it's usage. Well here is a neat one: just pass your double like this in main():
Code:
double TheCost(0);
total_cost(..., ..., ..., ..., ..., TheCost);
cout<<TheCost<<endl;
Once you go to structs and classes, things will look much neater. For now don't take this code seriously at all!
__________________
Valmont is offline   Reply With Quote