J
Joe
Can someone look at this code and tell me why I can not
read in the input characters.
//Invoice.hpp file
#include <iostream>
#include <string.h>
using namespace std;
class Invoice
{
public:
Invoice(char
[40],int& ,double& ,double& ); //constructor
~Invoice(); //destructor
//public accessors
int GetQuantity()const;
void SetQuantity(int&);
int GetItemName()const;
void SetItemName(char[40] );
int GetItemPrice()const;
void SetItemPrice(double& );
int GetTotal()const;
void SetTotal(double&);
private:
int *itsQuantity;
char itsItemName[40];
double *itsItemPrice;
double *itsTotal;
};
//Invoice.cpp file
#include "Invoice.hpp"
Invoice::Invoice(char cItem[40],int &iQuantity,double
&dItemPrice,double &dTotal)
{
itsQuantity = &iQuantity;
itsItemName[40] = cItem[40];
itsItemPrice = &dItemPrice;
itsTotal = &dTotal;
return;
}
Invoice::~Invoice()
{
return;
}
int Invoice::GetQuantity()const
{
return *itsQuantity;
}
void Invoice::SetQuantity(int &inPutQuantity)
{
itsQuantity = &inPutQuantity;
return;
}
int Invoice:: GetItemName()const
{
return itsItemName[40];
}
void Invoice::SetItemName(char cInPutItem[40] )
{
itsItemName[40] = cInPutItem[40];
return;
}
int Invoice::GetItemPrice()const
{
return *itsItemPrice;
}
void Invoice::SetItemPrice(double &dInputPrice)
{
itsItemPrice = &dInputPrice;
return;
}
int Invoice::GetTotal()const
{
return *itsTotal;
}
void Invoice::SetTotal(double &dInputTotal)
{
itsTotal = &dInputTotal;
return;
}
int main()
{
//input variables
int iNewQuantity;
char cNewItemName[40];
double dItemPrice;
double dNewTotal;
//invoice object
Invoice SalesInvoice
(cNewItemName,iNewQuantity,dItemPrice,dNewTotal);
// The user enters the Item Name he or she is
buying
cout <<"\nEnter your Item Name " ;
cin.getline(cNewItemName,40);
SalesInvoice.SetItemName(cNewItemName);
// The user enters the Item Quantity he or she is
buying
cout <<"Enter the quantity of items : " ;
cin >> iNewQuantity;
SalesInvoice.SetQuantity(iNewQuantity);
// The user enters the Item price he or she is
buying
cout <<"Enter Item Price: ";
cin >> dItemPrice ;
SalesInvoice.SetItemPrice(dItemPrice);
// The user enters the item total he or she is
buying
cout <<"Enter your total: ";
cin >> dNewTotal;
SalesInvoice.SetTotal(dNewTotal);
// before printing to the screen clear it
// system("cls");
//preview of the item name before it is set
cout <<"\nItem Name is "<< cNewItemName <<endl;
//output to the screen
cout << "\nItem Name: " <<
SalesInvoice.GetItemName() <<endl;
cout << "Item Quantity: "<<
SalesInvoice.GetQuantity() <<endl;
cout << "Item Price: $" <<
SalesInvoice.GetItemPrice() <<endl;
cout << "Total Item Price: $" <<
SalesInvoice.GetTotal() << endl;
return 0;
}
read in the input characters.
//Invoice.hpp file
#include <iostream>
#include <string.h>
using namespace std;
class Invoice
{
public:
Invoice(char
[40],int& ,double& ,double& ); //constructor
~Invoice(); //destructor
//public accessors
int GetQuantity()const;
void SetQuantity(int&);
int GetItemName()const;
void SetItemName(char[40] );
int GetItemPrice()const;
void SetItemPrice(double& );
int GetTotal()const;
void SetTotal(double&);
private:
int *itsQuantity;
char itsItemName[40];
double *itsItemPrice;
double *itsTotal;
};
//Invoice.cpp file
#include "Invoice.hpp"
Invoice::Invoice(char cItem[40],int &iQuantity,double
&dItemPrice,double &dTotal)
{
itsQuantity = &iQuantity;
itsItemName[40] = cItem[40];
itsItemPrice = &dItemPrice;
itsTotal = &dTotal;
return;
}
Invoice::~Invoice()
{
return;
}
int Invoice::GetQuantity()const
{
return *itsQuantity;
}
void Invoice::SetQuantity(int &inPutQuantity)
{
itsQuantity = &inPutQuantity;
return;
}
int Invoice:: GetItemName()const
{
return itsItemName[40];
}
void Invoice::SetItemName(char cInPutItem[40] )
{
itsItemName[40] = cInPutItem[40];
return;
}
int Invoice::GetItemPrice()const
{
return *itsItemPrice;
}
void Invoice::SetItemPrice(double &dInputPrice)
{
itsItemPrice = &dInputPrice;
return;
}
int Invoice::GetTotal()const
{
return *itsTotal;
}
void Invoice::SetTotal(double &dInputTotal)
{
itsTotal = &dInputTotal;
return;
}
int main()
{
//input variables
int iNewQuantity;
char cNewItemName[40];
double dItemPrice;
double dNewTotal;
//invoice object
Invoice SalesInvoice
(cNewItemName,iNewQuantity,dItemPrice,dNewTotal);
// The user enters the Item Name he or she is
buying
cout <<"\nEnter your Item Name " ;
cin.getline(cNewItemName,40);
SalesInvoice.SetItemName(cNewItemName);
// The user enters the Item Quantity he or she is
buying
cout <<"Enter the quantity of items : " ;
cin >> iNewQuantity;
SalesInvoice.SetQuantity(iNewQuantity);
// The user enters the Item price he or she is
buying
cout <<"Enter Item Price: ";
cin >> dItemPrice ;
SalesInvoice.SetItemPrice(dItemPrice);
// The user enters the item total he or she is
buying
cout <<"Enter your total: ";
cin >> dNewTotal;
SalesInvoice.SetTotal(dNewTotal);
// before printing to the screen clear it
// system("cls");
//preview of the item name before it is set
cout <<"\nItem Name is "<< cNewItemName <<endl;
//output to the screen
cout << "\nItem Name: " <<
SalesInvoice.GetItemName() <<endl;
cout << "Item Quantity: "<<
SalesInvoice.GetQuantity() <<endl;
cout << "Item Price: $" <<
SalesInvoice.GetItemPrice() <<endl;
cout << "Total Item Price: $" <<
SalesInvoice.GetTotal() << endl;
return 0;
}