0

I have been working on this code all week and can not figure out why its saying that my identifiers are undefined.... Please Help!

class Invoice
{
public:
   // constructor initializes the four data members
   Invoice( string, string, int, int );

   // set and get functions for the four data members
   void setPartNumber( string ); // part number
   string getPartNumber(); 

   void setPartDescription( string ); // part description
   string getPartDescription();

   void setQuantity( int ); // quantity
   int getQuantity();

   void setPricePerItem( int ); // price per item
   int getPricePerItem();

   // calculates invoice amount by multiplying quantity x price per item
   int getInvoiceAmount(); 

private:
   string partNumber; // the number of the part being sold
   string partDescription; // description of the part being sold
   int quantity; // how many of the items are being sold
   int pricePerItem; // price per item

}; // end class Invoice


#include <iostream>
#include "Invoice.h"
using namespace std;

// Invoice constructor initializes the class's four data members
Invoice::Invoice( string number, string description, int count, int price )
{
   setPartNumber( number );				// store partNumber
   setPartDescription( description );	// store partDescription
   setQuantity( count );				// validate and store quantity
   setPricePerItem( price );			// validate and store pricePerItem
} // end Invoice constructor


// set part number
void Invoice::setPartNumber( string number )
{
   PartNumber = number;  // no validation needed

} // end function setPartNumber


// get part number
string Invoice::getPartNumber()
{
   return PartNumber;

} // end function getPartNumber


// set part description
void Invoice::setPartDescription( string description )
{
   PartDescription = description;		// no validation needed

} // end function setPartDescription


// get part description
string Invoice::getPartDescription()
{
   return PartDescription;

} // end function getPartDescription


// set quantity; if not positive, set to 0
void Invoice::setQuantity( int count )
{
   quantity = ( count < 0 ) ? 0 : count;
   

} // end function setQuantity

   
// get quantity
int Invoice::getQuantity()
{
	return quantity;

} // end function getQuantity

   
// set price per item; if not positive, set to 0
void Invoice::setPricePerItem( int price )
{
  pricePerItem = ( price < 0.0 ) ? 0.0 : price;

} // end function setPricePerItem


// get price per item
int Invoice::getPricePerItem()
{
  return pricePerItem;

} // end function getPricePerItem


// calulates invoice amount by multiplying quantity x price per item
int Invoice::getInvoiceAmount()
{
    return getQuantity() * getPricePerItem();

} // end function getInvoiceAmount

#include <iostream>
#include "Invoice.h"
using namespace std;

// function main begins program execution
int main()
{
   // create an Invoice object
   Invoice invoice( "12345", "Hammer", 100, 5 ); 

   // display the invoice data members and calculate the amount
   cout << "Part number: " << invoice.getPartNumber() << endl;
   cout << "Part description: " << invoice.getPartDescription() << endl;
   cout << "Quantity: " << invoice.getQuantity() << endl;
   cout << "Price per item: $" << invoice.getPricePerItem() << endl;
   cout << "Invoice amount: $" << invoice.getInvoiceAmount() << endl;

   // modify the invoice data members
   invoice.setPartNumber( "123456" );
   invoice.setPartDescription( "Saw" );
   invoice.setQuantity( -5 ); // negative quantity, so quantity set to 0 
   invoice.setPricePerItem( 10 );
   cout << "\nInvoice data members modified.\n\n";

   // display the modified invoice data members and calculate new amount
   cout << "Part number: " << invoice.getPartNumber() << endl;
   cout << "Part description: " << invoice.getPartDescription() << endl;
   cout << "Quantity: " << invoice.getQuantity() << endl;
   cout << "Price per item: $" << invoice.getPricePerItem() << endl;
   cout << "Invoice amount: $" << invoice.getInvoiceAmount() << endl;
} // end main
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Clinton Portis
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.