Question
I'm having errors with my cpp files. I was implementing everything in the hpp files but that seems incorrect to do. This is the lab
I'm having errors with my cpp files. I was implementing everything in the hpp files but that seems incorrect to do. This is the lab work that I was asked to do:
C++ Creating Classes (Invoice Class): Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four data membersa part number (type string), a part description (type string), a quantity of the item being purchased (type int) and a price per item (type int). Your class should have a constructor that initializes the four data members. Provide a set and a get function for each data member. In addition, provide a member function named getInvoiceAmount that calculates the invoice amount (i.e., multiplies the quantity by the price per item), then returns the amount as an int value. If the quantity is not positive, it should be set to 0. If the price per item is not positive, it should be set to 0. Write a test program that demonstrates class Invoices capabilities. Use classes, functions, objects, and exceptions to create an invoicing system.
Demonstrate understanding of three things: 1) Classes and functions 2) Objects 3) Exceptions.
G lab2ExceptionHandeling.cpp Invoice.cpp Invoice.hpp Negative.cpp Negative.hpp 3 2e Negative.hppl 7 8 #ifndef NEGATIVE. HPP . 9 #define NEGATIVE-HPP- 10 #include iostream> 11 #include ioma nip 12 using namespace std; 13 14 class Negative public exception 15 private: 16 public: 17 Negative(){ 18 19 virtual const char* what() const throw(){ 20 return "Quantity cannot be a negative number, setting quantity to e"; 21 22 myex; 23 24 #endif /* NEGATIVE. HPP-*/ 25 26 Run d lab2ExceptionHandeling.cpp C Invoice.cpp h invoice.npp Lc Negative.cpp n Negative.npp e Invoice.cppl 7 8 #include "Invoice.hpp" 310 Invoice:: Invoice(string partNumber string description,int quantity double price) this->partNumber-partNumber; this->description-description; this->price-price; setQuantity (quantity); 12 13 14 215 16 17 18 // TODO Auto-generated constructor stub 19 Invoice:: Invoice() /I TODO Auto-generated destructor stub 220 21 23 24 c Negative.cpp in Negative.npp lab2ExceptionHandeling.cpp C Invoice.cpp 2/Name invoice.npp : lab2txceptionHandeling. cpp 9 #include iostream 10 using namespace std; 11 #include "Invoice.hpp" 12 #include "Negative . hpp" 13 14 int main) 15 string partNumber; 16 string description; 17 int quantity; 18 double price; 19 20 cout>partNumber; 23 cout>description; 25 26 cout>quantity; 28 29 cout>price; 31 32 Invoice i(partNumber,description,quantity,price); 34 coutStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started