In need of some major help. The program is pretty easy to write myself but the code given to us by the professor is making this a huge headache. The code given to us is the entire TEST.CPP File. So the program I am suppose to code is basically, the user must enter how many courses there are. The user then enters how many students are in the course. Then enters how many student paid. In the end all the math gets sorted out. Here are three examples given by the professor, to give you guys a better idea. I'll post the code I have so far in the bottom. We are suppose to use Static Member Variables.
Please any help would be appreciated. Basically I just need help on how I can give access to the prototype functions coded in TEST.CPP access to the Private members WITHOUT making them class member functions.
How many courses maximum? 6
Now creating an uninitialized course element ....
Now creating an uninitialized course element ....
Now creating an uninitialized course element ....
Now creating an uninitialized course element ....
Now creating an uninitialized course element ....
Now creating an uninitialized course element ....
Enter 'y' to initialize new course data; any other character to quit: y
For course 1:
How many students entered the room? 5
How many students paid? 4
Enter 'y' to initialize new course data; any other character to quit: y
For course 2:
How many students entered the room? 6
How many students paid? 3
Enter 'y' to initialize new course data; any other character to quit: y
For course 3:
How many students entered the room? 7
How many students paid? 2
Enter 'y' to initialize new course data; any other character to quit: y
For course 4:
How many students entered the room? 8
How many students paid? 1
Enter 'y' to initialize new course data; any other character to quit: q
For course 1:
5 students are in the course
The toll collected is $2.00
1 students didn't pay
For course 2:
6 students are in the course
The toll collected is $1.50
3 students didn't pay
For course 3:
7 students are in the course
The toll collected is $1.00
5 students didn't pay
For course 4:
8 students are in the course
The toll collected is $0.50
7 students didn't pay
The average toll per course is $1.25
How many courses maximum? 2
Now creating an uninitialized course element ....
Now creating an uninitialized course element ....
Enter 'y' to initialize new course data; any other character to quit:
For course 1:
How many students entered the room? 5
How many students paid? 6
*** Invalid input: more paying than entered! ***
How many students entered the room? 5
How many students paid? 4
Enter 'y' to initialize new course data; any other character to quit:
For course 2:
How many students entered the room? 10
How many students paid? 12
*** Invalid input: more paying than entered! ***
How many students entered the room? 11
How many students paid? 12
*** Invalid input: more paying than entered! ***
How many students entered the room? 11
How many students paid? 11
For course 1:
5 students are in the course
The toll collected is $2.00
1 students didn't pay
For course 2:
11 students are in the course
The toll collected is $5.50
0 students didn't pay
The average toll per course is $3.75
How many courses maximum? 4
Now creating an uninitialized course element ....
Now creating an uninitialized course element ....
Now creating an uninitialized course element ....
Now creating an uninitialized course element ....
Enter 'y' to initialize new course data; any other character to quit: x
No actual courses
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
|
//TEST.CPP
#include "Tollbooth.h"
//test.cpp
/*
Insert all your include directives here
*/
void inputCourseData (Tollbooth*, int);
void outputCourseInfo (Tollbooth*, float&);
void displayAvgToll (float);
/*
Insert any additional function prototypes for functions called by main here
*/
int main()
{
int maxCourses; //input for dynamic memory allocation
float totalTollAmt = 0; //calculated for all courses
cout << "How many courses maximum? ";
cin >> maxCourses;
Tollbooth* tboothPtr = new Tollbooth;
//Here you must dynamically create an array of TollBooth objects, pointed to by tboothPtr
inputCourseData (tboothPtr, maxCourses);
outputCourseInfo (tboothPtr, totalTollAmt);
displayAvgToll (totalTollAmt);
delete []tboothPtr;//Here you should release your dynamically allocated memory
return 0;
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
//HEADER FILE
#include <iostream>
using namespace std;
class Tollbooth
{
private:
int m_nPayingStus;
int m_nDeadbeatStus;
static int m_nCourseCount;
static int m_totalPay;
bool isValid();
int stucount;
public:
//Planning to make contructors to give access for the prototypes in the TEST.CPP file to have access to the private member Varables up above.
static int getTotalPay();
static int getCourseCount();
};
|
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
|
//IMPLEMENTATION FILE
#include "Tollbooth.h"
int Tollbooth::m_totalPay = 0;
int Tollbooth::m_nCourseCount = 0;
int Tollbooth::getTotalPay()
{
return m_totalPay;
}
int Tollbooth::getCourseCount()
{
return m_nCourseCount;
}
void inputCourseData(int* p, int cc)
{
cout << "For course " << Tollbooth::getCourseCount() << ": ";
cout << "How many students entered the room? ";
cout << "How many students paid? ";
}
void outputCourseInfo(int* p, float& t)
{
cout << "For course : ";
cout << "students are in the course";
cout << "The toll collected is: ";
cout << "students didn't pay";
}
void displayAvgToll()
{
cout << "The average toll per course is: ";
}
|