Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > Standard C, C++

Reply
 
LinkBack Thread Tools Display Modes
Old 04-01-2005, 12:49 PM   #1 (permalink)
cleverest
Registered User
 
Join Date: Mar 2005
Posts: 22
cleverest is on a distinguished road
Exclamation Assignment I have, it's crazy for little 'ol me...help?

The goal is to use a few functions (at least one passed by value, and one passed by reference). any kind of loops....No pointers/arrays cause we haven't got to those yet..... and I think I can only use the iostream/string headers and 'using namespace std;'

What I have so far below is very rough and it's only the start of the program, but if someone could suggest a foundation to start with I will steer is that direction, or at least tell me if I'm building upon the correct foundation already....like what exactly in the program dialog below should be FUNCTIONS and what should just be variables int he main() function?? I think this would help clarify things for me....thanks.

THIS IS WHAT THE PROGRAM SHOULD LOOK LIKE WHEN RAN
(3 examples are given below that the program should display,
BOLD text is user inputted values)

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


This is what I have so far which really only covers the very start of it...(with some comments).....just don't know if I'm going in the right direction and don't want to start witha shaky foundation.....I don't want my program completely written for me (not that I'm refusing) but I just need a good design plan/foundation so I can accomplish this the easiest way possible cause I REALLY WANT TO LEARN IT....



Code:
 
#include <iostream>
#include <string>
using namespace std;

int Semester(const int, const int, const int, const int); 
// is consst necessary/recommended for these?

int main()
{
    
    char inSemester;
    char pause;       // using this temporarily to PAUSE the output
    const int F = 30;
    const int W = 27;
    const int S = 30;
    const int M = 27;
    
    cout << "Student Fee Calculator:\n";
    cout << "What semester am I calculating fees for? [F]all/[W]inter\n";
    cout << "[S]pring/su[M]mer]:";
    cin >> inSemester;
    if (inSemester == 'F' || 'f')
    {
    int Semester(F);
    cout << Semester;   // just to confirm that it is reading the correct int value
    }
    if (inSemester == 'W' || 'w')
    {
    int Semester(W);
    cout << Semester;  // just to confirm that it is reading the correct int value
    }
    if (inSemester == 'S' || 's') /  
    {
    int Semester(S);
    cout << Semester;  // just to confirm that it is reading the correct int value
    }
    if (inSemester == 'M' || 'm')
    {
    int Semester(M);
    cout << Semester;  // just to confirm that it is reading the correct int value
    }

    
    
    cin >> pause;  // will remove later
    return 0;
}



int Semester(const int F = 30, const int W = 27, const int S = 30, const int M = 27)
{

    
     return F,W,S,M;  // is there a clearer and easier way for a beginner to do these functions?  Am I making this too complicated?
     
}
Oh also these are the rates to use for the calculation...

Description Cost:
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


Thanks for any help at all! I really appreciate it! I'm just overwhelmed by this.
cleverest is offline   Reply With Quote
Old 04-01-2005, 02:22 PM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Why don't you start with the core of the app first? Keep it simple, then combine these functions (I've implemented one as a sample on how simple it can be):
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(bool fsws);
double parking_cost(bool fsws);
double student_sticker_refund(bool fsws);
//r: 'c' =  california, 'u' = US residents, 'v' =  visa holders;
double enrollment_cost(char r);

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

int main()
{
    
  return 0;
}

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

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

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

double parking_cost(bool fsws)
{
}  

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

double student_sticker_refund(bool fsws)
{
}

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

double enrollment_cost(char r)
{
}
Make a neat menu later.
__________________
Valmont is offline   Reply With Quote
Old 04-01-2005, 03:07 PM   #3 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,696
redhead is on a distinguished road
Here is one in strict ANSI C
Code:
#include <stdio.h>

#define LENGTH 64

int get_user_input(int* description, int* parking, int* enrolment, 
		   int* sticker, int* units, int verbose);


int main(int argc, char** argv)
{
  /* do we need debug/verbose output */
  int description, parking, enrolment, sticker, units, verbose = 0;

  /* Student Services
   * $30.00 for Fall or Spring semester
   * $27.00 for Winter or Summer session
   */
  double description_cost[2] = {30.00, 27.00};

  /*
   * Parking
   * $75.00 for Fall or Spring semester
   * $35.00 for Winter or Summer session
   */
  double parking_cost[2] = {75.00, 35.00};
  
  /* 
   * Enrollment Per Unit
   * $26.00 / unit for California residents
   * $149.00 / unit for US residents
   * $171.00 / unit for F1 Visa holders
   */
  double enrolment_cost[3] = {26.00, 149.00, 171.00};
  
  /*
   * Associated Student Sticker Refund
   * $10.00 refund in Fall or Spring semester, if requested
   * $9.00 refund in Winter or Summer session, if requested
   */
  double sticker_refund[2] = {10.00, 9.00};
  
/* we need to display verbose output */
  if(argc > 1 && argv[1][0] == '-' && argv[1][1] == 'v')
    verbose = 1;
  
  /* fetch what ever the user want to calculate */

  printf("Student Fee Calculator:\n");
  if(0 != get_user_input(&description, &parking, &enrolment, 
			 &sticker, &units, verbose))
    {
      printf("Error getting user input\n");
      return -1;
    }
  if(verbose)
    {
      printf("Returned from get_user_input() with:\n");
      printf("\tdescription:\t%d\n", description);
      printf("\tparking:\t%d\n", parking);
      printf("\tenrolment:\t%d\n", enrolment);
      printf("\tsticker:\t%d\n", sticker);
      printf("\tunits:\t\t%d\n", units);
    }
 
  printf("Total cost for student fee:\n");
  printf("\tUnits:\t%d\n", units);
  printf("\tCost:\t%.2lf\n", 
	 (description_cost[description] + (parking ? parking_cost[description] : 0)
	  + units * enrolment_cost[enrolment] - (sticker ? sticker_refund[description] : 0)));
  return 0;
}



int get_user_input(int* description, int* parking, int* enrolment, 
		   int* sticker, int* units, int verbose)
{
  char buffer[LENGTH +1];

  printf("What semester am I calculating fees for?\n");
  printf("\t[F]all\n");
  printf("\t[W]inter\n");
  printf("\t[S]pring\n");
  printf("\tsu[M]mer\n");
  printf("\t\t:");
  fflush(stdout);
  if(!fgets(buffer, LENGTH, stdin))
    {
      if(verbose)
	printf("Error reading semester from stdin\n");
      return -1;
    }
  switch(buffer[0])
    {
    case 'f':
    case 'F':
    case 's':
    case 'S':
      *description = 0;
      break;
    case 'm':
    case 'M':
    case 'w':
    case 'W':
      *description = 1;
      break;
    default:
      if(verbose)
	printf("Error reading semester from stdin\n");
      return -1;
    }
  printf("Are you a California resident? [y/n]\n");
  printf("\t\t:");
  fflush(stdout);
  if(!fgets(buffer, LENGTH, stdin))
    {
      if(verbose)
	printf("Error reading CA resident from stdin\n");
      return -1;
    }
  if(buffer[0] == 'y' || buffer[0] == 'Y')
    *enrolment = 0;
  else
    if(buffer[0] == 'n' || buffer[0] == 'N')
      {
	printf("Are you a US sitizens? [y/n]\n");
	printf("\t\t:");
	fflush(stdout);
	if(!fgets(buffer, LENGTH, stdin))
	  {
	    if(verbose)
	      printf("Error reading US sitizens from stdin\n");
	    return -1;
	  }
	if(buffer[0] == 'y' || buffer[0] == 'Y')
	  *enrolment = 1;
	else
	  if(buffer[0] == 'n' || buffer[0] == 'N')
	    {
	      buffer[0] = '\0';
	      printf("Are you an F1 visa holder? [y/n]\n");
	      printf("\t\t:");
	      fflush(stdout);
	      if(!fgets(buffer, LENGTH, stdin))
		{
		  if(verbose)
		    printf("Error reading F1 visa holder from stdin\n");
		  return -1;
		}
	      if(buffer[0] == 'y' || buffer[0] == 'Y')
		*enrolment = 2;
	      else
		{
		  if(verbose)
		    printf("Error getting decission for F1 visa holder\n");
		  return -1;
		}
	    }
	  else
	    {
	      if(verbose)
		printf("Error getting decission for US sitizens\n");
	      return -1;
	    }
      }
    else
      {
	if(verbose)
	  printf("Error getting decission for CA resident\n");
	return -1;
      }
  printf("Do you need a parking sticker? [y/n]\n");
  printf("\t\t:");
  fflush(stdout);
  if(!fgets(buffer, LENGTH, stdin))
    {
      if(verbose)
	printf("Error reading parking sticker from stdin\n");
      return -1;
    }
  if(buffer[0] == 'y' || buffer[0] == 'Y')
    *parking = 1;
  else
    if(buffer[0] == 'n' || buffer[0] == 'N')
      *parking = 0;
    else
      {
	if(verbose)
	  printf("Error getting decission for parking sticker\n");
	return -1;
      }
  printf("Are you requesting an AS sticker refund? [y/n]\n");
  printf("\t\t:");
  fflush(stdout);
  if(!fgets(buffer, LENGTH, stdin))
    {
      if(verbose)
	printf("Error reading AS sticker refund stdin\n");
      return -1;
    }
  if(buffer[0] == 'y' || buffer[0] == 'Y')
    *sticker = 1;
  else
    if(buffer[0] == 'n' || buffer[0] == 'N')
      *sticker = 0;
    else
      {
	if(verbose)
	  printf("Error getting decission for AS sticker\n");
	return -1;
      }
  printf("How many units will you enrol in?\n");
  printf("\t\t:");
  fflush(stdout);
  if(!fscanf(stdin, "%d", units))
    {
      if(verbose)
	printf("Error reading units stdin\n");
      return -1;
    }
  
  return 0;
}
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001

Last edited by redhead; 04-02-2005 at 05:55 AM.
redhead is offline   Reply With Quote
Old 04-01-2005, 05:01 PM   #4 (permalink)
cleverest
Registered User
 
Join Date: Mar 2005
Posts: 22
cleverest is on a distinguished road
Thanks a lot for the suggestions guys and the coding....redhead, sorry forgot to mention but I have to do this in C++....is your code hard to implement to C++ if you don't know any C? (I'm really raw at this stuff as you can tell)

I'll play with it all tonight and try to make it happen....thanks all!!
cleverest is offline   Reply With Quote
Old 04-01-2005, 10:20 PM   #5 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,696
redhead is on a distinguished road
The differences aren't that big (not in this program anyway) a few pointers are:
#include <stdio.h> is changed to #include <iostream>
Since you're working with C++ you need to declare the namespace you want, so remember
using namespace std;
printf() is changed to cout <<
fgets() is changed to cin.getline()
fscanf() is changed to cin >>

But since Valmont provided you with quite a nice foundation, I would suggest you'd use that as your foundation. There the parking_cost/student_sticker_refund/enrolment_cost is using the same logic as student_service_cost() and they just need to be combined with some sort of userinterface, where the user is questioned and uppon that the total cost gets calculated.

The differencies in Valmont and my suggestion, is that mine is filled with alot of error checking, to make sure the user dosn't provide us with input that wouldn't be usefull in the calculation, but since Valmonts isn't providing you with the userinterface (altho the code dos give some hints) he dosn't need to provide that.

Mine is designed on the use of pointers and arrays, since I thought that would be the easiest way of representing the cost for fall/spring/summer/winter parking/enrolment etc. without alot of variables floating around.
Since you mentioned that you'd probably wasn't supposed to use any of that, my version might be a week longer into your course than expected, but on the other hand, it does mention some function using parse by reference and parse by value. Since my get_user_input() uses both, those requirements are met.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 04-02-2005, 12:07 AM   #6 (permalink)
cleverest
Registered User
 
Join Date: Mar 2005
Posts: 22
cleverest is on a distinguished road
Thanks, program continuing :-D

Awesome, thanks for the info! I've worked more on this program and this is what I have so far? Am I on the right track? If not could you show the first initial steps that would be ideal to program in the main() function to assure I'm on the right track?? (please read my comments in the revised code....)

Also are the functions I filled out below good?? The last one is questionable to me...

Thanks again!


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 = 35.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(bool fsws);
double parking_cost(bool fsws);
double student_sticker_refund(bool fsws);
//r: 'c' =  california, 'u' = US residents, 'v' =  visa holders;
double enrollment_cost(char r);

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

int main()
{
        bool fsws; 
	char insemester;
	char pause;

    cout << "Student Fee Calculator:\n";
    cout << "What semester am I calculating fees for? [F]all/[W]inter\n";
    cout << "[S]pring/su[M]mer]:";
    cin >> insemester;  

/*  IS this variable/method not how I should be 
collecting the cin >> input?  or is this OK?? */


/* No matter what I do with the following 
code the number '30' is outputted when I test this 
IF statement block by using cout.....never '27' 
for the SUMMER/WINTER selections.... what am I doing wrong?  
I know it has to be a real simple answer...I'm just not 
getting it.....at worst...would you be willing to do just the initial one for me to 
illustrate for me the ideal way to do such a simple process....it's gonna sink
in eventually, lol  I really appreciate it!
*/


            if (insemester == 'F' || 'S')  
	{
	   fsws = true;
	   double student_services_cost(bool fsws);
	   cout << FALLSPRING_COST;
	   return FALLSPRING_COST;
	}
	if (insemester == 'W' || 'M');
	{
	   fsws = false;
	   double student_services_cost(bool fsws);
	   cout << WINTERSUMMER_COST;
	   return WINTERSUMMER_COST;
	}

	cin >> pause;       // temporary pause for now....


  return 0;
}

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

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

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

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

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

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

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

double enrollment_cost(char r)
{
   if(r == 'c')
   {
      return ENROLL_CALI;
   }
   if(r == 'u')
   {
      return ENROLL_US;
   }
   if(r == 'v')
   {
      return ENROLL_VISA;
   }


}
cleverest is offline   Reply With Quote
Old 04-02-2005, 04:07 AM   #7 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Sorry, change enrollment function to:
double enrollment_cost(char r, unsigned units)
{ ... }
__________________
Valmont is offline   Reply With Quote
Old 04-02-2005, 04:23 AM   #8 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,696
redhead is on a distinguished road
there are a few errors:
Code:
if (insemester == 'F' || 'S')
can't be done, look at my if(buffer[0]...) for comparison.
Code:
fsws = true;
double student_services_cost(bool fsws);
this isn't allowed, this is the predefinition of the function, when calling it, you need to do it like:
Code:
my_variabel = student_services_cost(fsws);
here's my lil' version in strickt ANSI C++
Code:
#include <iostream>
#include <iomanip>

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 = 35.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(bool fsws);
double parking_cost(bool fsws);
double student_sticker_refund(bool fsws);
//r: 'c' =  california, 'u' = US residents, 'v' =  visa holders;
double enrollment_cost(char r);

int main()
{
  bool fsws;
  double total = 0;
  char input, enrol = '\0';
  int count, units = 0;
  
  cout << "Student Fee Calculator:" << endl;
  
  /* first the question is winter/fall/spring/summer */
  cout << "What semester am I calculating fees for?" << endl;
  cout << "\t[F]all" << endl;
  cout << "\t[W]inter" << endl;
  cout << "\t[S]pring" << endl;
  cout << "\tsu[M]mer" << endl;
  cout << "\t\t:";
  cout.flush();
  cin >> input;
  switch(input)
    {
    case 'f':
    case 'F':
    case 's':
    case 'S':
      fsws = true;
      break;
    case 'm':
    case 'M':
    case 'w':
    case 'W':
      fsws = false;
      break;
    default:
      cout << "Error reading semester from stdin" << endl;
      return -1;
    }
  
  /* next question can be uptimised we
   * can repeat the same steps several times
   */
  for(count = 0; count <= 4; count++)
    {
      if(!count)    /* first time CA question */
	cout << "Are you a California resident? [y/n]";
      if(count == 1)/* second time US question */
	cout << "Are you a US citizen? [y/n]";
      if(count == 2)/* last time visa question */
	cout << "Are you an F1 visa holder? [y/n]";
      if(count == 3)
	cout << "Do you need parking sticker? [y/n]";
      if(count == 4)
	cout << "Are you requesting an AS sticker refund? [y/n]";
      
      cout << endl;
      cout << "\t\t: ";
      cout.flush();
      cin >> input;
      if(input == 'y' || input == 'Y')
	{ 
	  if(!count)
	    {
	      enrol = 'c';
	      /* jump to parking question */
	      count = 2;
	      continue;
	    }
	  if(count == 1)
            {
	      enrol = 'u';
	      /* jump to parking question */
	      count = 2;
	      continue;
	    }
	  if(count == 2)
	    enrol = 'v';
	  if(count == 3)
	    total += parking_cost(fsws);
	  if(count == 4)
	    total -= student_sticker_refund(fsws);
	}
    }
  if(!enrol)
    {
      cout << "Error getting sitizens" << endl;
      return -1;
    }
  cout << "How many units will you enrol in?" << endl;
  cout << "\t\t: ";
  cout.flush();
  cin >> units;
  
  total += units * enrollment_cost(enrol);
  total += student_services_cost(fsws);
  
  cout << "Total cost for student fee:"<< endl;
  cout << "\tUnits:\t" << units << endl;
  cout << "\tCost:\t";
  cout << setprecision(2) << setiosflags(ios::fixed);
  cout << total << endl;

  return 0;
}


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

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

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

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

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

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

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

double enrollment_cost(char r)
{
   switch(r)
     {
     case 'c':
      return ENROLL_CALI;
     case 'u':
       return ENROLL_US;
     case 'v':
       return ENROLL_VISA;
     default:
       return 0;  
     }
}
Note this is not to be taken as a version I've made for your convenience, you can take a look at my way of handling the user interaction and see if that makes any sence..
Then try and see if you can come up with some clever way of handling it, while taking peeks at my code.

Now this diverts a bit from the orriginal description, which stated there should be functions taking call by value and call by reference, this does not have function calls, which takes call by reference.
But that can be achieved by moving the user interaction into a function by itself, which will take the total as an argument, and fill it with the total value, while returning an int or something simular. This is however left as an exercise for the reader.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001

Last edited by redhead; 04-02-2005 at 06:31 AM.
redhead is offline   Reply With Quote
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
Old 04-02-2005, 06:20 AM   #10 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,696
redhead is on a distinguished road
Quote:
Originally Posted by Valmont
This definitions isn't clear:
True, theres not much in those three examples, which shows what should be done.. When selecting a CA resident, it seems as tho they are not allowed to select Visa payment, yet a US citizents are.. Shouldn't CA citizents be alowed too ?? or should it only be if the request is comming from one who isn't from CA or US at all, thus removing the posibility to chose it for US citizents aswell.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 04-02-2005, 11:30 AM   #11 (permalink)
cleverest
Registered User
 
Join Date: Mar 2005
Posts: 22
cleverest is on a distinguished road
Sorry for the vague program dialogue examples given...unfortunately those are what was given to me to work with and the table values I gave you...and that was all...so I guess whatever gets the program to run as its shown in the paragraphs.... with no extra frills would be the best ave to take.... since I'm overwhelmed by what we've worked on so far anyways...lol....

thanks a lot for all the help and thanks for correcting my errors in the example above Red...

I'll try to implement what you've all given and for me at this point it's just understanding the logic behind what all these commands do and how they interact...at what point Val, should I start implementing the menu system? How do I go about "starting the test"?

Also what does #include <iomanip> allow you to do? Haven't seen that one yet...

Do you think you could give me the very first part of the menu so I implement the rest on the right track? Thanks.
cleverest is offline   Reply With Quote
Old 04-02-2005, 11:49 AM   #12 (permalink)
cleverest
Registered User
 
Join Date: Mar 2005
Posts: 22
cleverest is on a distinguished road
Quote:
Originally Posted by redhead
Note this is not to be taken as a version I've made for your convenience, you can take a look at my way of handling the user interaction and see if that makes any sence..
Then try and see if you can come up with some clever way of handling it, while taking peeks at my code.

Now this diverts a bit from the orriginal description, which stated there should be functions taking call by value and call by reference, this does not have function calls, which takes call by reference.
But that can be achieved by moving the user interaction into a function by itself, which will take the total as an argument, and fill it with the total value, while returning an int or something simular. This is however left as an exercise for the reader.

The code you have given int his post is very nicely done, I appreciate the attention you've given me on this, and I'll try to study and implement this system of coding into my own later tonight (I work today, argh). How long have you both been doing C++?? I think the only thing that might stump me now is the REFERENCE Function to integrate into this coding, but hopefully with all the help you've given me I'll figure it out quick (and still be able to play with my new PSP this weekend some!)
cleverest is offline   Reply With Quote
Old 04-02-2005, 11:59 AM   #13 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,696
redhead is on a distinguished road
Quote:
Originally Posted by cleverest
Also what does #include <iomanip> allow you to do? Haven't seen that one yet...
It makes it possible to use the setprecision() and setiosflags(), which enables the output of the total amount to have <value>.00 instead of just <value>
Quote:
How long have you both been doing C++??
I live and breath for ANSI C, I've been programming proffesionaly since 1996. But I havn't touched C++ that much in the last 5 years or so..

Since I noticed you deleted (or tried to delete) one of your posts I took the liberty to physicaly removing it.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 04-03-2005, 01:41 AM   #14 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Quote:
How do I go about "starting the test"?
Try out variations until you are convinced that they do what you want.

Quote:
at what point Val, should I start implementing the menu system?
When you think you have completed your tests.

Quote:
Do you think you could give me the very first part of the menu so I implement the rest on the right track?
Not yet.
I want you to build something you can understand. When you have something working, we could check out together what improvements are left.
Try to approach the menu system as a independent project. Make it a "do-nohting" menu. A sort of a skeleton. And let's see the structure of it.

Quote:
think the only thing that might stump me now is the REFERENCE Function to integrate into this coding...
Watch out with the word "reference function".
Anyway, we do have a function that takes a reference as a parameter. I am not sure if you noticed it. Check out total_cost(...).
__________________
Valmont is offline   Reply With Quote