#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

class CashRegister {
public:
   void clear();
   void add_item(double price);
   int get_count() const;
   double get_total() const;
private:
   vector<double> prices; // Store prices in a vector
};

void CashRegister::clear() {
   prices.clear();
}

void CashRegister::add_item(double price) {
   prices.push_back(price); // Add the price to the vector
}

int CashRegister::get_count() const {
   return prices.size(); // Return the size of the vector
}

double CashRegister::get_total() const {
   return accumulate(prices.begin(), prices.end(), 0.0); // Accumulate the prices in the vector
}

int main() {
   CashRegister reg1;
   reg1.clear();
   reg1.add_item(5);
   cout << reg1.get_count() << endl;
   cout << "Expected: 1" << endl;
   reg1.add_item(7);
   cout << reg1.get_count() << endl;
   cout << "Expected: 2" << endl;
   double amount_due = reg1.get_total();
   cout << amount_due << endl;
   cout << "Expected: 12" << endl;
   return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: