Question
Please help with this assignment. Thanks.
1. Write a C++ program containing a class Invoice and a driver program called invoiceDriver.cpp. The class Invoice is used in

1. Create an object of type invoice using the constructor, provide the required initialization values 2. Print the values of
0 0
Add a comment Improve this question Transcribed image text
Answer #1

I have written three programs.

Invoice.h has only declarations of data members and functions.

invoice.cpp has the definitions of these functions.

InvoiceDriver.cpp is the test program.

Invoice.h:

#include <iostream>
#include <string>


using namespace std;

class Invoice
{
public:
       Invoice(string p_number, string p_description, int quantity, int price) ;
       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();
      
       int getInvoiceAmount() ;

private:
       string partNumber;
           string partDescription;
           int quantity;
           int pricePerItem;
};
      

invoice.cpp

#include <iostream>
#include <string>
#include "Invoice.h"

using namespace std;
Invoice::Invoice ( string p_number, string p_desc, int quant, int price )
{
   setPartNumber (p_number);
   setPartDescription (p_desc);
   setQuantity (quant);
   setPricePerItem (price);
}

void Invoice::setPartNumber (string number)
{
   partNumber = number;
}

string Invoice::getPartNumber ()
{
   return partNumber;
}

void Invoice::setPartDescription (string desc)
{
   partDescription = desc;
}

string Invoice::getPartDescription()
{
   return partDescription;
}

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

int Invoice::getQuantity()
{
   return quantity;
}

void Invoice::setPricePerItem(int price)
{
   if (price >= 0) pricePerItem = price;
   else pricePerItem = 0;
}

int Invoice::getPricePerItem()
{
   return pricePerItem;
}

int Invoice::getInvoiceAmount()
{
  
   return quantity * pricePerItem;
}

InvoiceDriver.cpp

#include <string.h>
#include <iostream>
#include "Invoice.h"

using namespace std;

int main()
{
   Invoice invoiceObj1("P1111","item1",4,200);
   Invoice   invoiceObj2("P2222","item2",-2,50);
  
   // test getquantity and getprice functions
   int q1 = invoiceObj1.getQuantity();
   int p1 = invoiceObj1.getPricePerItem();
  
   int q2 = invoiceObj2.getQuantity();
   int p2 = invoiceObj2.getPricePerItem();
  
  
   cout << "Price per item1 = " << p1 << "\t Price per item2 = " << p2 << endl;
   cout << "Quantity1 = " << q1 << "\t Quantity2 = " << q2 << endl;
  
  
   // test getInvoiceAmount function
   cout << " Total Amount = " << invoiceObj1.getInvoiceAmount() << endl;
   cout << " Total Amount = " << invoiceObj2.getInvoiceAmount() << endl;
  
   // test set functions
  
   invoiceObj1.setPartNumber("S0001");
   invoiceObj1.setPartDescription("set item1");
   invoiceObj1.setPricePerItem(100);
   invoiceObj1.setQuantity(5);
  
   cout << "Part number = " << invoiceObj1.getPartNumber() << endl;
   cout << "Part description is " << invoiceObj1.getPartDescription() <<endl;
   cout << "Price per item = " << invoiceObj1.getPricePerItem() << endl;
   cout << "Quantity = " << invoiceObj1.getQuantity() << endl;
   cout << " Total Amount = " << invoiceObj1.getInvoiceAmount() << endl;
  
}

OUTPUT:

Price per item1 = 200    Price per item2 = 50
Quantity1 = 4    Quantity2 = 0
 Total Amount = 800
 Total Amount = 0
Part number = S0001
Part description is set item1
Price per item = 100
Quantity = 5
 Total Amount = 500

Hope this helps. Please Upvote .
  
  

Add a comment
Know the answer?
Add Answer to:
Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1a. Create a class named Inventory - Separate declaration from implementation (i.e. Header and CPP files)...

    1a. Create a class named Inventory - Separate declaration from implementation (i.e. Header and CPP files) 1b. Add the following private member variables - a int variable named itemNumber - an int variable named quantity - a double variable named cost - a double variable named totalCost. Total cost is defined as quantity X cost. - updateTotalCost() which takes no arguments and sets the values of the variable totalCost. 1c. Add the following public functions: - Accessor and Mutators for...

  • In C++, Step 1: Implement the Student Class and write a simple main() driver program to...

    In C++, Step 1: Implement the Student Class and write a simple main() driver program to instantiate several objects of this class, populate each object, and display the information for each object. The defintion of the student class should be written in an individual header (i.e. student.h) file and the implementation of the methods of the student class should be written in a corresponding source (i.e. student.cpp) file. Student class - The name of the class should be Student. -...

  • Write a program in C++ that simulates a soft drink machine. The program will need several...

    Write a program in C++ that simulates a soft drink machine. The program will need several classes: DrinkItem, DrinkMachine and Receipt. For each of the classes you must create the constructors and member functions required below. You can, optionally, add additional private member functions that can be used for doing implementation work within the class. DrinkItem class The DrinkItem class will contains the following private data members: name: Drink name (type of drink – read in from a file). Type...

  • C++ Retailltem.h, Retailltem.cpp, Store.h, Store.cpp, and Driver.cpp. Description: Write a set of programs that holds data...

    C++ Retailltem.h, Retailltem.cpp, Store.h, Store.cpp, and Driver.cpp. Description: Write a set of programs that holds data about items in a retail store. Your submission should include 5 files, Retailltem.b, Retailltem.cpp, Store, Store.cpp, and Driver.cpp 1. Retailltem class: The class should have three member variables • description (a string, represent the item's name. A name contains space) quantity (an int, represent how many current available) price (a double, item's price) Member Functions Constructor with default argument get Description getQuantity getPrice setDescription...

  • C++ Programing In this exercise, you will design a class memberType. The class has the following...

    C++ Programing In this exercise, you will design a class memberType. The class has the following data members: memberName. A string that holds the name of a person memberID. A string that holds the member identification number numBooks. An int that holds the number of books bought purchaseAmt. A double that holds the amount spent on books In addition, the class should have the following constructor and other member functions. Constructor. The constructor should accept the person’s name and member...

  • Write a program Ct+ that processes a user's monthly budget. Note that this program can easily...

    Write a program Ct+ that processes a user's monthly budget. Note that this program can easily be enhanced to process any number of budget items he program should contain several Classes A parent class named SpentItemType. The parent class should contain several member variables and member functions Just need classes below Above, we will restrict the program to process a maximum of 10 budget items for each group For each Budget items, there should be a class created that contains...

  • JAVA Use the class, Invoice, provided to create an array of Invoice objects. Class Invoice includes...

    JAVA Use the class, Invoice, provided to create an array of Invoice objects. Class Invoice includes four instance variables; partNumber (type String), partDescription (type String), quantity of the item being purchased (type int0, and pricePerItem (type double). Perform the following queries on the array of Invoice objects and display the results: Use streams to sort the Invoice objects by partDescription, then display the results. Use streams to sort the Invoice objects by pricePerItem, then display the results. Use streams to...

  • I need help with my homework please. I should write this program in C++ language and...

    I need help with my homework please. I should write this program in C++ language and use Inventory.h file (header file), Inventory.cpp file (implementation file), and main.cpp file (main program). This is the program: Demonstrate the class in a driver program. Input validation, don’t accept negative values for item number, quantity, or cost. 6. Inventory Class Design an Inventory class that can hold information and calculate data for items ma retail store's inventory. The class should have the following private...

  • - Classes Write a C++ program that creates a class called Date that includes three pieces...

    - Classes Write a C++ program that creates a class called Date that includes three pieces of information as data members, namely:  month (type int)  day (type int)  year (type int). Program requirements: - Provide set and a get member functions for each data member. - For the set member functions assume that the values provided for the year and day are correct, but in the setMonth member function ensure that the month value is in the...

  • Write a C++ program Write a class named Employee that has the following member variables: name...

    Write a C++ program Write a class named Employee that has the following member variables: name A string that holds the employee name idNumber An int to hold employee id number department A string to hold the name of the department position A string to hold the job position The class will have three constructors: 1. A constructor that accepts all the internal data such as: Employee susan("Susan Meyers", 47899, "Accounting", "Vice President"); 2. A constructor that accepts some of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT