seperate functions file

my professor has reassigned an old lad, but has told us to place all of our functions in a separate file. I would love some help. I can't seem to get the calculate package functions to compile. here is the assignment followed by the working code i have.

***********************************************************************
* PROGRAM 5 FUNCTIONS COSC 1436
***********************************************************************

An Internet service provider has three different subscription
packages for its customers:

Package A: For $15 per month with 50 hours of access provided.
Additional hours are $2.00 per hour over 50 hours.
Assume usage is recorded in one-hour increments,


Package B: For $20 per month with 100 hours of access provided.
Additional hours are $1.50 per hour over 100 hours.


Package C: For $25 per month with 150 hours access is provided.
Additional hours are $1.00 per hour over 150 hours



Write a program that calculates a customer’s monthly charges.
Implement with the following functionsin a separate functions.cpp file:
getPackage
validPackage
getHours
validHours
calculatePkg_A
calculatePkg_B
calculatePkg_C
calculateCharges
showBill
Validate all input.
Demonstrate valid and invalid cases.
Show console dialog. It must be readable.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;

#include "functions.h"

int main()
{
	char pkg;
	pkg = getValidPkg();
	cout<<"Pkg: "<<pkg<<endl;
	
	int hrs;
	hrs = getValidHrs();
	cout<<"Hrs: "<<hrs<<endl;
	






}//endmain 




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
#include <iostream>
using namespace std;

bool isValidPkg(	char p	)								//checkpkg
{
	return (p>='A' && p<='C') || (p>='a' && p<='c');
}

char getValidPkg()											//getpkg
{
	char p=0;

	do
	{
		cout<<"Enter pkg: ";
		cin>>p;
	}
	while(	!isValidPkg(p)	);

	return p;
	
}

bool isValidHrs(	int h	)								//checkhrs
{
	return (h>=0 && h<=720);
}

char getValidHrs()											//gethrs
{
	int h;

	do
	{
		cout<<"Enter hours: ";
		cin>>h;
	}
	while(	!isValidHrs(h)	);

	return h;
}




1
2
3
4
5
6
7
8
9
10
11
//functions.h

char getValidPkg();

char getValidHrs();

char calculatePkg_A();

char calculatePkg_B();

char calculatePkg_C();

For isValidPkg and isValidHrs, the parameters you have in the source file don't match with the function declaration
i dont understand what you mean. that portion complies and runs as desired. i would like some help with the calculation of the packages.
1. What is each function supposed to do. Specifically, what is the input and output for each function supposed to be? This information can be inferred from some of the function names, but for a function like getPackage, it's unclear what exactly that function should do. What package are you getting? How are you getting that package?

2. Your getValidPkg function is only allowing you to select Package A or C. It will not allow you to select Package B.

3. getValidHrs should return type int, not type char. Char type is 8 bit, and limited to a maximum int value of 255.

Once you have the package type and number of hours used, calculating the bill is just a bit of math.
initialize bill variable to zero.
Add monthly rate to bill.
subtract monthly hour allowance from hours used.
if hours used is greater than zero, multiply hours used by hourly rate and add that to bill.
Send bill to customer.
Topic archived. No new replies allowed.