#include<iostream>
#include <string>


using std::cout;
using std::cin;
using std::endl;
using std::string;
using namespace std;

class Invoice
{
public:

	void setPrice(int price);
	int getPrice();
	void setQuantity(int quantity);
	int getQuantity();
	void setPartnumber(string);
	string getPartnumber();
	void setDescription(string);
	string getDescription();
	int getInvoiceAmount(int Quantity, int Price);
	

private:
	int Quantity;
	int Price;
	string Partnumber;
	string Description;
	
};
void Invoice::setPrice( int price )
{
	if (price >= 0)
		price = Price;
	else
		Price = 0;
}
int Invoice::getPrice()
{
	return Price;
}

void Invoice::setQuantity( int quantity )
{
	if (quantity > 0)
		quantity = Quantity;
	else
		Quantity = 0;
}	

int Invoice::getQuantity()
{
	return Quantity;
}
        
void Invoice::setPartnumber( string partnumber )
{
	partnumber = Partnumber;
}	

string Invoice::getPartnumber()
{
	return Partnumber;
}

void Invoice::setDescription( string description )
{
	description = Description;
}	

string Invoice::getDescription()
{
	return Description;
}    

int getInvoiceAmount(int Quantity, int Price)
{
	int total;
	total = (Quantity * Price);

	return total;

}

int main()
{
   int price,quantity;
   Invoice description();
   Invoice partnumber();
   
	cout << "Please enter the part number: ";
	cin  >> partnumber;
	cout << "\nPlease enter the description: " ;
	cin  >> description;
	cout << "Please enter the price: ";
	cin  >> price;
	cout << "\nPlease enter quantity: " ;
	cin  >> quantity;
	
	partnumber.setPartnumber(partnumber);
	description.setDescription(description);
	Invoice::setPrice(price);
	Invoice::setQuantity(quantity);


	cout << "Your invoice is as follows:" << endl << endl
		<< "Part Number: " << Invoice.getPartnumber() <<endl
		<< "Description: " << Invoice.getDescription() << endl
		<< "Price:       " << Invoice.getPrice() << endl
		<< "Quantity:    " << Invoice.getQuantity() <<endl
		<< "Total Cost:  " << Invoice.getInvoiceAmount() << endl;

		
   return 0;
}

Recommended Answers

All 5 Replies

Where's the question in this code?

Before you post again please read this about code tags and this about asking clear questions, meaningfull titles .

Niek

I apologize Niek. The question is I am not sure if I am using the correct reference to the following. I am having trouble with "classes".

Towards the end of the code.

int main()
{
   int price,quantity;
   Invoice description();
   Invoice partnumber();
   
	cout << "Please enter the part number: ";
	cin  >> partnumber;
	cout << "\nPlease enter the description: " ;
	cin  >> description;
	cout << "Please enter the price: ";
	cin  >> price;
	cout << "\nPlease enter quantity: " ;
	cin  >> quantity;
	
	partnumber.setPartnumber(partnumber);
	description.setDescription(description);
	Invoice::setPrice(price);
	Invoice::setQuantity(quantity);


	cout << "Your invoice is as follows:" << endl << endl
		<< "Part Number: " << Invoice.getPartnumber() <<endl
		<< "Description: " << Invoice.getDescription() << endl
		<< "Price:       " << Invoice.getPrice() << endl
		<< "Quantity:    " << Invoice.getQuantity() <<endl
		<< "Total Cost:  " << Invoice.getInvoiceAmount() << endl;

		
   return 0;
}

line 8 fails because cin requires a POD (Plain Old Data) type, unless you specifically write an operator >> overload method for the class. If you want to get the partnumber then do it something like this:

Invoice inv;
string partnumber;
string description;
cout << "Enter part number\n";
cin >> partnumber;
inv.setPartnumber(partnumber);

cout << "Enter description\n";
cin >> description;
inv.setDescription(description);

// Do the same for all the other class fields.

Ancient Dragon -

Thank you for your time. I apologize

Ancient Dragon -

Thank you for your time.

Hope it helped :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.