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

int main() {

    string description;
    double price;
    int quantity;

    cout << "Enter the description: ";
    getline(cin, description);

    cout << "Enter the unit price: ";
    cin >> price;

    cout << "Enter the quantity: ";
    cin >> quantity;
    cout << endl;//a new line

    //create an invoice using default constructor
    Invoice hammers;
    hammers.setDescription(description);
    hammers.setPrice(price);
    hammers.setQuantity(quantity);

    //now print the invoice
    hammers.print();
    cout << endl;

    //create an invoice using constructor with parameters
    Invoice ductTape("Duct Tape",2.99,10);

    cout << "[Invoice for object created using constructor]" <<endl;
    ductTape.print();
    cin.ignore(255,'\n');//ignore any leftover new lines
    cin.get();//pause the output...
    return 0;
}

***********************
^^^end of code for .cpp file.. here is the code for my Invoice.h file..
***********************

#include <iostream>
#include <string>
using namespace std;

class Invoice
{

public:

        void hammers(string bagofhammers);
        {
        setDescription = bag of hammers;
        }
            void hammers(int);
            {
            setQuantity = 1;
            }
                void hammers (int);
                {
                setPrice = 12.99;
                }


        void ductTape (string, int);
{
        void setDescription ( string description);
        setDescription = Duct Tape;
        void setPrice
        setPrice = 2.99;
        setQuantity = 10;
        }

string getDescription()
{
        return description;
    }

string getQuantity()
{
        return quantity;
    }

string getPrice()
{
        return price;
    }

void print()        
{   
    cout <<"Invoiced item is:  " << getDescription << endl;

    cout <<"Quantity ordered:  "<< getQuantity << endl;

    cout <<"Each unit's price is:   "<< getPrice << endl;

    cout <<"Total Amount:    "<< (setPrice*setQuantity) << endl;
        };



}

**************
i feel like im way off on making it work, but its probably simple to fix.... heres the directions to this problem, below.

thanks so much if you help me with this.

Write a C++ class definition that will model an Invoice for some purchase. An invoice contains the item description,
the unit price (in dollars), the quantity purchased, and the total amount (price * quantity).
Your class definition needs to support setting all of the data members (except total amount), getting all of the data
members, a default constructor, and a constructor that takes in all of the necessary data for an invoice. In addition,
provide a print method that will print a copy of the Invoice object in an easy to read format.

I need my code once run to look like this:

Enter the description: bag of hammers
Enter the unit price: 12.99
Enter the quantity: 1
********
Invoice
********
Item:.........................bag of hammers
Unit Price:...................$12.99
Quantity:.....................1
Total Amount:.................$12.99
[Invoice for object created using constructor]
********
Invoice
********
Item:.........................Duct Tape
Unit Price:...................$2.99
Quantity:.....................10
Total Amount:.................$29.90

Recommended Answers

All 6 Replies

Instead of posting your homework assignment(and breaking forums rules) why don't you repost your code correctly and state what's not working and where its not working.

The last part of your posting

void print()
{
cout <<"Invoiced item is: " << getDescription << endl;

cout <<"Quantity ordered: "<< getQuantity << endl;

cout <<"Each unit's price is: "<< getPrice << endl;

cout <<"Total Amount: "<< (setPrice*setQuantity) << endl;
};



}

Should probably be

void print()
{
cout <<"Invoiced item is: " << getDescription << endl;

cout <<"Quantity ordered: "<< getQuantity << endl;

cout <<"Each unit's price is: "<< getPrice << endl;

cout <<"Total Amount: "<< (setPrice*setQuantity) << endl;
}



};

Note line 14.

sorry for breaking rules. thought someone could tell me what needs to be added or modified from what i already have, to show what i need. you can look at it and see whats not working. sorry for offending you.

I just tried compiling your program. I got four pages of errors/warnings.

From little obvious things like

void hammers(string bagofhammers);//Note the semi-colon. It shouldn't be there.
{
setDescription = bag of hammers;
}
void hammers(int);//Note the semi-colon. It shouldn't be there.
{
setQuantity = 1;
}
void hammers (int);//Note the semi-colon. It shouldn't be there.
{
setPrice = 12.99;
}

might not be much, but thanks man.

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.