0

I have to take this program and make a header file, and implementation file, and a driver file. I wrote the original code and with all of the couts int the functions I can only put one function into an implementation file.

#include <iostream>
#include <iomanip>

using namespace std;

void loadChange(int& quarters, int& dimes, int& nickels, int& pennies);
void displayStatus(int quarters, int dimes, int nickels, int pennies);
void totalChange(int quarters, int dimes, int nickels, int pennies);
void dispenceChange(int quarters, int dimes, int nickels, int pennies, double totalMoney);
void showSelections();

    int quarters;
	int dimes;
	int nickels;
	int pennies;
	double totalMoney;

int main() 
{
	char choice;
	
	
	showSelections();
	cin >> choice;
	
	
	
	while (choice != 'Q' && choice != 'q')
	{
		switch (choice)
		{
			case 'S':
			case 's':
			displayStatus(quarters, dimes, nickels, pennies);
			break;
			case 'D':
			case 'd':
			dispenceChange(quarters, dimes, nickels, pennies, totalMoney);
			break;
			case 'L':
			case 'l':
			loadChange(quarters, dimes, nickels, pennies);
			break;
			default:
			   cout << " " << endl;
			   cout << "Invalid selction." << endl;
			   cout << " " << endl;
		}
		
		showSelections();
		cin >> choice;
		
		totalChange(quarters, dimes, nickels, pennies);
	}
	
   }

void showSelections()
{
	   cout << "Please chose an option" << endl;
	   cout << " S - Status " << endl;
	   cout << " D - Dispense change " << endl;
	   cout << " L - Load Change " << endl;
	   cout << " Q - Quit " << endl;
	   cout << " " << endl;
}

void displayStatus(int quarters, int dimes, int nickels, int pennies)
{
	cout << " " << endl;
	cout << "number of quarters " << quarters << endl;
	cout << "number of dimes " << dimes << endl;
	cout << "number of nickels " << nickels << endl;
	cout << "number of pennies " << pennies << endl;
	cout << " " << endl;
}

void loadChange(int& quarters, int& dimes, int& nickels, int& pennies)
{
	cout << " " << endl;
	cout << "Enter number of quarters " << endl;
	cin >> quarters;
	cout << "Enter number of dimes " << endl;
	cin >> dimes;
	cout << "Enter number of nickels " << endl;
	cin >> nickels;
	cout << "Enter number of pennies " << endl;
	cin >> pennies;
	cout << " " << endl;
}

void totalChange(int quarters, int dimes, int nickels, int pennies)
{
	double moneyQuarters;
	double moneyDimes;
	double moneyNickels;
	double moneyPennies;
	
	
	moneyQuarters = (quarters * .25);
	moneyDimes = (dimes * .10);
	moneyNickels = (nickels * .05);
	moneyPennies = (pennies * .01);
	
	totalMoney = moneyQuarters + moneyDimes + moneyNickels + moneyPennies;
	
}

void dispenceChange(int quarters, int dimes, int nickels, int pennies, double totalMoney)
{
	double changeReturn;
	
	cout << totalMoney << endl;
	cout << "Please enter amount you want returned " << endl;
	cin >> changeReturn;
	
	if (changeReturn > totalMoney)
	   cout << "not enough money to make change" << endl;
	else
	{
       quarters = changeReturn / .25;
       changeReturn = changeReturn - (quarters*.25);
       dimes = changeReturn / .10;
       changeReturn = changeReturn - (dimes*.10);
       nickels = changeReturn / .05;
       changeReturn = changeReturn - (nickels*.05);
       pennies = changeReturn / .01;
       changeReturn = changeReturn - pennies;
	
	  cout << "Quarters " << quarters << endl;
	  cout << "Dimes " << dimes << endl;
	  cout << "Nickels " << nickels << endl;
	  cout << "Pennies " << pennies << endl;
	}
}

So I have a constructor and declare my variables but how do i pass these to the functions in the driver file?
I just don't understand how to do the .h, imp, an driver from my code. Here it is.

#include <iostream>

class dispenser
{
   public:
void dispenser(int quarters = 0, int dimes = 0, int nickels = 0, int pennies = 0);
void totalChange(int quarters, int dimes, int nickels, int pennies);

  private:

    int quarters;
	int dimes;
	int nickels;
	int pennies;
	double totalMoney;
};
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Ancient Dragon
0

>>how do i pass these to the functions in the driver file?

The file that contains main() is considered the "driver file". In your first code snippet all you have to do is include the header file that you created, like this

#include <iostream>
#include "myheader.h" // <<<<<<<<<<<<<<<<<<<<< here

int main()
{
  dispenser MyDispenser; // declare an object of type class dispenser
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.