Creating a driver.cpp file

I need an explanation on the basic structure of a driver for a class I've created. The header file is stored in the "header files" folder of my project, and the class is stored in the "source files" folder. This is my class' code if you want to use this to help in the explanation. Otherwise, some sort of basic structure example/description to help me understand a driver would be appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//header file
#ifndef PAYROLL_H

class Payroll
{
private:
	char emp[20];
	double payrate;
	int numberPayPeriods;
	double yearToDate;

public:
	Payroll();

	Payroll (char name[20], double rate);

	~Payroll();

	void empName();
	int getNumPayPeriods();
	double getyearToDate();
	void update(int hours);
};
#endif 


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

Payroll::Payroll(){
	strcpy_s(emp, 20, "-");
	payrate = 0;
	numberPayPeriods = 0;
	yearToDate = 0;
}

Payroll::Payroll(char name[20], double rate){
	strcpy_s(emp, 20, name);
	payrate = rate;
	numberPayPeriods = 0;
	yearToDate = 0;
}

Payroll::~Payroll(){
	cout << emp << "done";
}
A driver is generally a piece of software that bridges between hardware and an operating system. I'm guessing you don't want one of those, so what exactly are you asking? Are you asking how you can actually use your class?
Err, yes. My professor calls it a driver (I guess incorrectly?). I would like to know the structure of the int main() function I need to have to use this class.

**I only want to know how to create the file that causes a class to operate. It doesn't have to be able to run this class. I just provided my class as an example to use.
Last edited on
the driver.cpp program would have a reference to your header file for your class and any other header files needed to run main.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "payroll.h"
#include <iostream>//most commonly used with hw assignmenst it seems...

using namespace std;

int main(){

payroll myPayroll; // new payroll object
myPayroll.setPayPeriod(52);//or whatever functions you want to use/create for this class

 



return 0;
}

the driver.cpp goes in your source code folder and you build the solution.
All of this gets compiled together and you can run the executable from your debug folder where the source is stored ( i am assuming you are using visual studio)

Dan Schwartz
Last edited on
My professor calls it a driver (I guess incorrectly?)


Not so much incorrect as just colloquial; if its sole purpose is to drive an instance of a class, why not call it the driver. In context, it makes sense.
Topic archived. No new replies allowed.