Okay guys, I'm sorry if this seems like I'm trying to ask you to do my homework for me, but I assume you that I am not. I'm just really lost as to how to achieve the following.
I need to make the .cpp files that goes along with these header files:
// transacton.h - contains the class specifications for Transaction
#ifndef H_transaction
#define H_transaction
#include <iostream>
#include <iomanip>
#include <string>
usingnamespace std;
enum TransactionType {CashIn,CashOut};
class Transaction
{
private:
string theDate;
string theTime;
int amount;
TransactionType type;
public:
Transaction();
// this construction sets the date & time to the current date and time. In
// addtion, the constructor sets the amount to zero;
Transaction(int);
// this construction, similar to the default construction except that it sets
// the amount to the amount specified in the argument list.
Transaction(int,TransactionType);
// this construction, inaddition to Transaction(int), set the type to the
// specified TransactionType in the argument list
void setDate();
// this function sets theDate to the current date.
void setTime();
// this function sets theTime to the current time.
void setAmount(int);
// this function sets amount to the current amount as specified in
// the argument list. In addtion, this functions sets the date & time
// to the current date and time.
int getAmount();
// this function returns the amount
void setType(TransactionType);
// this function set the type to the TransactionType as specified in
// the argement list
void print();
// this function writes the instance variabbles using cout.
// the following is an example you may want to use:
// string temp("CashOut");
// if (type == CashIn)
// {
// temp="CashIn";
// }
// cout << setw(10) << theDate;
// cout << setw(15) << theTime;
// cout << setw(5) << amount;
// cout << setw(10) << temp;
// cout << endl;
};
#endif
// cashdraw.h - contains the class specifications for the CashDraw object
#ifndef H_cashdraw
#define H_cashdraw
#include "transaction.h"
class CashDraw
{
private:
Transaction cashIn[10];
Transaction cashOut[10];
int sizeCashIn;
int sizeCashOut;
int initialAmount;
public:
CashDraw(int);
// this construction sets teh inital amount as specified
// int the arguement list. In addtion, this constructor sets
// both the size of cash in and out to zero.
int makeSale(int,int);
// this function makes a sale and returns the proper change. The change is
// computed by the amount paid by the sale price, both specified in
// the argument list. In addition to the change, this function creates
// two transaction. One transaction for amount paid and another transaction
// for the change. You must set the proper transaction types.
// Your function must use dynamic allocation when creating the
// Transaction objects. We spoke very briefly about dynamic
// allocation. The following code creates a dynamic transaction:
// Transaction *t1 = new Transaction(paidAmount,CashIn);
// cashIn[sizeCashIn++]=*t1;
// Your function must supply the dynamic cash out transaction.
int getCashOnHand();
// This function is a little tricky. First, let's look and see
// how much cach do we have. To compute this it is the initial
// amount plus the sum of each cash in transaction. Next, how much
// change did we return to the client? This is the sum of the cash
// out transaction. Now just return the difference. For example:
// CashOnHand = (initial amount + sum(CashIn)) - sum(Cashout)
void printCashIn();
// this function prints each transaction in the cash in array
// using cout.
void printCashOut();
// this function prints each transaction in the cash out array
// using cout.
void printAll();
// Use the following code:
// cout << "Initial Amout " << initialAmount << endl;
// cout << "Cash On Hand " << getCashOnHand() << endl;
// printCashIn();
// printCashOut();
};
#endif
Here is what I have come up with so far, but I am running into an issue when trying to set up Transaction(int) in the transaction.cpp file.
//transaction.cpp
#include <ctime>
#include <cerrno>
#include "transaction.h"
Transaction::Transaction()
{
//Find the current time
time_t curtime = time(0);
//convert it to tm
tm now=*localtime(&curtime);
//BUFSIZ is standard macro that expands to a integer constant expression
//that is greater then or equal to 256. It is the size of the stream buffer
//used by setbuf()
char theTime[BUFSIZ]={0};
//Format string determines the conversion specification's behaviour
constchar format[]="%A, %B %d %Y. The time is %X";
//strftime - converts date and time to a string
if (strftime(theTime, sizeof(theTime)-1, format, &now)>0)
std::cout<<theTime<<std::endl;
else
std::cerr<<"strftime failed. Errno code: "<<errno<<std::endl;
}
Transaction(int)
{
}
void print()
{
string temp("CashOut");
if (type == CashIn)
{
temp="CashIn";
}
cout << setw(10) << theDate;
cout << setw(15) << theTime;
cout << setw(5) << amount;
cout << setw(10) << temp;
cout << endl;
}
}
Can anyone provide some assistance that will get me started?
The instructions are pretty clear; that constructor is to initialize the initial cash (no pun intended) to the parameter it receives, and initialize the rest to 0.
Okay, I'm making progress, but what about the following:
1 2 3
Transaction(int,TransactionType);
// this construction, inaddition to Transaction(int), set the type to the
// specified TransactionType in the argument list
I'm a little confused as to what exactly this is requesting be done.