I have a header file.
#include <iostream>
class coinReturn
{
public:
coinReturn();
coinReturn(int quarters, int dimes, int nickels, int pennies);
void setChange(int quarters, int dimes, int nickels, int pennies);
void getChange(int& quarters, int& dimes, int& nickels, int& pennies);
void print ();
private:
int countQuarters;
int countDimes;
int countNickels;
int countPennies;
double totalQuarters;
};
an implementation file
#include <iostream>
#include "change.h"
using namespace std;
coinReturn::coinReturn()
{
countQuarters = 0;
countDimes = 0;
countNickels = 0;
countPennies = 0;
}
coinReturn::coinReturn(int quarters, int dimes, int nickels, int pennies)
{
setChange(quarters, dimes, nickels, pennies);
}
void coinReturn::getChange(int& quarters, int& dimes, int& nickels, int& pennies)//output. returns a value
{
quarters = countQuarters;
dimes = countDimes;
nickels = countNickels;
pennies = countPennies;
}
void coinReturn::setChange(int quarters, int dimes, int nickels, int pennies)//input
{
countQuarters += quarters;
countDimes += dimes;
countNickels += nickels;
countPennies += pennies;
}
void totalChange(int countQuarters, int dimes, int nickels, int pennies)// which one is correct countQuarters or quarters?
{
double totalQuarters;
totalQuarters = countQuarters * .25;// where do i declare this?
}
void coinReturn::print()
{
cout << "Quarters " << countQuarters << endl;
cout << "Dimes " << countDimes << endl;
cout << "Nickels " << countNickels << endl;
cout << "Pennies " << countPennies << endl;
cout << totalQuarters << endl; //how do i get it to output?
}
and a driver file
#include <iostream>
#include "change.h"
void loadChange(int& quarters, int& dimes, int& nickels, int& pennies);
int quarters;
int dimes;
int nickels;
int pennies;
using namespace std;
int main()
{
coinReturn myReturn;
loadChange(quarters, dimes, nickels, pennies);
myReturn.setChange(quarters, dimes, nickels, pennies);
myReturn.print();
loadChange(quarters, dimes, nickels, pennies);
myReturn.setChange(quarters, dimes, nickels, pennies);
myReturn.print();
}
void loadChange(int& quarters, int& dimes, int& nickels, int& pennies)
{
coinReturn myReturn;
cout << "Please enter number of quarters " << endl;
cin >> quarters;
cout << "Please enter number of dimes " << endl;
cin >> dimes;
cout << "Please enter number of nickels " << endl;
cin >> nickels;
cout << "Please enter number of pennies " << endl;
cin >> pennies;
}
My first question is in the imp file in the print function, how do i get totalQuarters to print. I plan on using this function for each coin. My second question is which way do I pass objects in the function, do i call the set or the get object?
Code blocks are created by indenting at least 4 spaces
... and can span multiple lines