Question

In C++ Write a header cashRegister.h and source cashRegister.cpp files for the a CashRegister class. The...

In C++

Write a header cashRegister.h and source cashRegister.cpp files for the a CashRegister class. The class a CashRegister class has the following data members: 1) an array of 100 Item objects. 2) Cash Register Name and 3) Count of Item objects purchased. 4) Item Cash Total 5) State Tax Rate. The Item is represented as a class in an item.h file. The Item class has the following data members: 1) Name of the item 2) Cost of the item. In addition, provide the following member function prototypes for the CashRegister class

  • CashRegister Default Constructor Function
  • CashRegister  Overloaded Constructor Function that takes the register name and state tax rate.
  • purchase(..) member function that takes an Item object and returns a boolean value (true: number of purchases does not exceed the limit, otherwise false). – Make sure not to exceed 100 items.
  • printTotal() a constant function that prints the cash total (include tax) of all the items purchased on the screen and returns nothing

#pragma once //item.h file

//Place code here for Item class

///////////////////////////////////////////////////

#pragma once //cashRegister.h file

//Place code here for CashRegister class

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*
* cashRegister.h
*
* Created on: 25-Jul-2020
* Author:
*/

#ifndef CASHREGISTER_H_
#define CASHREGISTER_H_
#include "item.h"
#include <iostream>
using namespace std;

class CashRegister {
   Item *item[100];
   string name;
   int count;
   double total;
   double taxRate;
public:
   /**
   * default constructor
   * set all attribute to 0
   */
   CashRegister();

   /**
   * overloaded constructor
   * @param name of cashregister to be set
   * @param rate
   */
   CashRegister(string name, double rate);

   /**
   * purchase an item and add it to array list
   * @param item to be purchase
   */
   bool purchase(Item &item);

   /**
   * print total amount including taxRate
   */
   void printTotal();
   virtual ~CashRegister();
};

#endif /* CASHREGISTER_H_ */

/*
* cashRegister.cpp
*
* Created on: 25-Jul-2020
* Author:
*/

#include "cashRegister.h"

CashRegister::CashRegister() {
   this->count = 0;   // set count to 0
   this->name = "";   // set register name to empty string
   this->total = 0;   // set total amount to 0
   this->taxRate = 0;    // set default tax rate to 0
}

CashRegister::CashRegister(std::string name, double rate){
   this->count = 0; // set count to 0
   this->name = name; // set name
   this->total = 0; // set total amount to 0
   this->taxRate = rate; // set rate to given rate
}

bool CashRegister::purchase(Item &item){
   if (this->count > 100){
       return false; // return false if item list is full
   }

   this->item[count] = &item; // add an item in list
   this->count+=1; // increase counter variable by one
   return true; // return true if successfully added
}

void CashRegister::printTotal(){
   // calculate to amount to be pay
   for (int i=0; i<this->count; i++){
       this->total += this->item[i]->getCost();
   }
   double taxAmt = this->total * this->taxRate / 100;
   this->total += taxAmt;
   cout<<"Total amount(including tax): "<<this->total<<endl;
}

CashRegister::~CashRegister() {}

/*
* item.h
*
* Created on: 25-Jul-2020
* Author:
*/

#ifndef ITEM_H_
#define ITEM_H_
#include <iostream>
using namespace std;

class Item {
   string name;
   double cost;
public:

   /**
   * default constructor
   */
   Item();

   /**
   * overloaded constructor
   * @param name of item
   * @param cost of item
   */
   Item(std::string name, double cost);

   /**
   * get name of item
   * @return name of item
   */
   string getName();

   /**
   * set name of item
   * @param name of item to be set
   */
   void setName(string name);

   /**
   * get cost of item
   * @return cost of item
   */
   double getCost();

   /**
   * set cost of item
   * @param cost of item
   */
   void setCost(double cost);
   virtual ~Item();
};

#endif /* ITEM_H_ */

/*
* item.cpp
*
* Created on: 25-Jul-2020
* Author:
*/

#include "item.h"

Item::Item() {
   this->cost = 0;
   this->name = "";
}

Item::Item(std::string name, double cost){
   this->cost = cost; // set cost of item
   this->name = name; // set name of item
}

double Item::getCost(){
   return this->cost; // return cost of item
}

void Item::setCost(double cost){
   this->cost = cost; // set cost of item
}

string Item::getName(){
   return this->name; // return name of item
}

void Item::setName(string name){
   this->name = name; // set name of item
}

Item::~Item() {}

/*
* main.cpp
*
* Created on: 23-Jul-2020
* Author:
*/

#include <iostream>
#include "cashRegister.h"

using namespace std;

int main(){
   CashRegister c("cRegister", 5.0); // create object of CashRegister class

   Item item1("Scale", 25);            // create item1
   Item item2("Tie", 10);                // create item2
   Item item3("Undergarments", 50);    // create item3
   Item item4("Cap", 70);                // create item4
   c.purchase(item1);                    // purchase item1
   c.purchase(item2);                    // purchase item2
   c.purchase(item3);                    // purchase item3
   c.purchase(item4);                    // purchase item4

   c.printTotal();        // print total amount of item
}


Output:

Total amount (including tax): 162.75

Add a comment
Know the answer?
Add Answer to:
In C++ Write a header cashRegister.h and source cashRegister.cpp files for the a CashRegister class. The...
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
  • Write a C++ class named CashRegister. The class should have private data members named Hundreds, Tens,...

    Write a C++ class named CashRegister. The class should have private data members named Hundreds, Tens, Fives, and Singles all of type integer. The class should have the following: 1. A member function named GetTotalCash to retrieve the total cash inside the cash register. 2. Overload the + operator to allow adding two objects of type CashRegister (note, add the hundreds to the hundreds, tens to tens and so on). 3. Overload the > operator to compare between two CashRegisters...

  • Complete the CashRegister class by implementing the methods and adding the correct attributes (characteristics) as discussed...

    Complete the CashRegister class by implementing the methods and adding the correct attributes (characteristics) as discussed in class. Once complete, test the class using the CashRegisterTester class. Make sure you have 3 total items in the cash register. I have two classes, the first is CashRegisterTester below: public class CashRegisterTester { public static void main(String[] args) { //Initialize all variables //Construct a CashRegister object CashRegister register1 = new CashRegister(); //Invole a non-static method of the object //since it is non-static,...

  • in java PART ONE ======================================= Below is the "RetailItem" class definition that we used in Chapter 6. Write a "CashRegister" class that leverages this "Ret...

    in java PART ONE ======================================= Below is the "RetailItem" class definition that we used in Chapter 6. Write a "CashRegister" class that leverages this "RetailItem" class which simulates the sale of a retail item. It should have a constructor that accepts a "RetailItem" object as an argument. The constructor should also accept an integer that represents the quantity of items being purchased. Your class should have these methods: getSubtotal: returns the subtotal of the sale, which is quantity times price....

  • 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...

  • Write the following program in Java using Eclipse. A cash register is used in retail stores...

    Write the following program in Java using Eclipse. A cash register is used in retail stores to help clerks enter a number of items and calculate their subtotal and total. It usually prints a receipt with all the items in some format. Design a Receipt class and Item class. In general, one receipt can contain multiple items. Here is what you should have in the Receipt class: numberOfItems: this variable will keep track of the number of items added to...

  • Write code in Java programming language. The ShoppingCart class will be composed with an array of...

    Write code in Java programming language. The ShoppingCart class will be composed with an array of Item objects. You do not need to implement the Item class for this question, only use it. Item has a getPrice() method that returns a float and a one-argument constructor that takes a float that specifies the price. The ShoppingCart class should have: Constructors: A no-argument and a single argument that takes an array of Items. Fields: • Items: an array of Item objects...

  • Part (A) Note: This class must be created in a separate cpp file Create a class...

    Part (A) Note: This class must be created in a separate cpp file Create a class Employee with the following attributes and operations: Attributes (Data members): i. An array to store the employee name. The length of this array is 256 bytes. ii. An array to store the company name. The length of this array is 256 bytes. iii. An array to store the department name. The length of this array is 256 bytes. iv. An unsigned integer to store...

  • Here is an example of how you separate your code into different files add the header...

    Here is an example of how you separate your code into different files add the header file and the .cpp file to the project. ------------------------------------------------------------------ //Header file -- saved as ex1.hpp #pragma once class ex1 { public: ...ex1(){} ...void print(); }; ------------------------------------------------------------------ //.cpp file -- saved as ex1.cpp #include "ex1.hpp" #include void ex1::print() { ...std::cout<<"Hello"< } ------------------------------------------------------------------ //main -- saved as main.cpp #include "ex1.hpp" int main(void) { ...ex1 e(); ...e.print(); ...return 0; } ------------------------------------------------------------------ Why do I have the #pragma...

  • 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...

  • 2- Write a program that has a Person class, a Student class, that is derived from...

    2- Write a program that has a Person class, a Student class, that is derived from Person, and a Faculty class, derived from Person as well, with the following specifications: The Person class has the following members: a. An integer private member variable named SSN. b. Two string protected member variables named firstName and lastName. C. An integer protected member variable named age. d. A constructor that takes SSN, first name, last name, and age as parameters. e. A constructor...

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