Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am getting error C2679 on priceList.cpp where i have items[size++] = new Price

ID: 3890607 • Letter: I

Question

I am getting error C2679 on priceList.cpp where i have items[size++] = new PriceListItem(itemName, code, price, taxable);

this is my priceList.h


#pragma once
#include
#include
#include "PriceListItem.h"
using namespace std;
class PriceList
{
public:
void createPriceListFromDatafile(string filename); // Load information from a text file with the given filename (Completed)
void addEntry(string itemName, string code, double price, bool taxable); // add to the price list information about a new item. A max of 1,000,000 entries can be added
bool isValid(string code) const; // return true only if the code is valid
PriceListItem getItem(string code) const; // return price, item name, taxable? as an PriceListItem object; throw exception if code is not found


private:
PriceListItem *items;
int size;


};
=============================================================

this is my priceList.cpp

#include
#include
#include
#include
#include "PriceList.h"
#include "PriceListItem.h"
using namespace std;


// Load information from a text file with the given filename.
void PriceList::createPriceListFromDatafile(string filename)
{
ifstream myfile(filename);
if (myfile.is_open()) {
  cout << "Successfully opened file " << filename << endl;
  string name;
  string code;
  double price;
  bool taxable;
  while (myfile >> name >> code >> price >> taxable) {
   // cout << code << " " << taxable << endl;
   addEntry(name, code, price, taxable);
  }
  myfile.close();
}
else
  throw invalid_argument("Could not open file " + filename);
}
// return true only if the code is valid
bool PriceList::isValid(string code) const
{
for (int i = 0; i {
  if (items[i].getCode() == code)
   return true;
}
return false;
}

// return price, item name, taxable? as an ItemPrice object; throw exception if code is not found
PriceListItem PriceList::getItem(string code) const {

for (int i = 0; i {
  if (items[i].getCode() == code)
   return items[i];
}
throw invalid_argument("Invalid code: " + code);
}

// add to the price list information about a new item
void PriceList::addEntry(string itemName, string code, double price, bool taxable) {

if (size < 1000000)
  items[size++] = new PriceListItem(itemName, code, price, taxable);
throw invalid_argument("Max of 1000000 items reached");


}

=============================================================

this is in the main

#include <iostream>

#include <fstream>

#include <string>

#include <stdexcept>

#include "PriceList.h"

#include "GroceryBill.h"
#include "priceListItem.h"

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

// DO NOT EDIT THIS FILE (except for your own testing)

// CODE WILL BE GRADED USING A MAIN FUNCTION SIMILAR TO THIS

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

using namespace std;

template <typename T>

bool testAnswer(const string &nameOfTest, const T &received, const T &expected) {

if (received == expected) {

  cout << "PASSED " << nameOfTest << ": expected and received " << received << endl;

  return true;

}

cout << "FAILED " << nameOfTest << ": expected " << expected << " but received " << received << endl;

return false;

}

template <typename T>

bool testAnswerEpsilon(const string &nameOfTest, const T &received, const T &expected) {

const double epsilon = 0.0001;

if ((received - expected < epsilon) && (expected - received < epsilon)) {

  cout << "PASSED " << nameOfTest << ": expected and received " << received << endl;

  return true;

}

cout << "FAILED " << nameOfTest << ": expected " << expected << " but received " << received << endl;

return false;

}

int main() {

{


  //test only the PriceList class

  PriceList priceList;

  priceList.addEntry("Apples", "1000", 1.99, false);

  priceList.addEntry("Bananas", "2000", 0.99, false);

  testAnswer("PriceList isValid1", priceList.isValid("1000"), true);

  testAnswer("PriceList isValid2", priceList.isValid("19"), false);

   // test copy constructor

   PriceList priceList2 = priceList;

   testAnswer("PriceList copy constructor test1", priceList2.isValid("1000"), true);

   priceList.addEntry("Milk", "3000", 3.49, false);

   priceList2.addEntry("Eggs", "4000", 4.99, false);

   testAnswer("PriceList copy constructor test2", priceList.isValid("4000"), false);

   // test assignment operator

   PriceList priceList3;

   priceList3 = priceList;

   testAnswer("PriceList assignment test1", priceList3.isValid("1000"), true);

   priceList.addEntry("Orange_juice_1gal", "4500", 6.49, false);

   priceList3.addEntry("Diapers_30ct", "5000", 19.99, false);

   testAnswer("PriceList assignment test2", priceList.isValid("5000"), false);

  
  
   {

    // test capacity of the PriceList class

    PriceList priceList;

    for (int i = 1; i<100000; i++)

     priceList.addEntry(string("Apples_") + to_string(i), to_string(i), 1.99, false);

    testAnswer("PriceList big data1", priceList.isValid("20000"), true);

    testAnswer("PriceList big data2", priceList.isValid("100000"), false);

   }

=============================================================================

this is my priceListItem.h

#ifndef PRICELISTITEM_H
#define PRICELISTITEM_H
#include <string>
using namespace std;
class PriceListItem
{
private:
string code;
double price;
string itemName;
bool taxable;
//Pointer to next Item, As the items are maintained as Linked List
//PriceListItem *nextItem = NULL;
public:
//Constructor with all details
PriceListItem();
PriceListItem(const string &itemName, const string &code, double price, bool taxable);
//Public methods to access its properties
string getCode();
double getPrice();
string getItemName();
bool isTaxable();

};


#endif // PRICELISTITEM_H

Objective You are given partial implementations of three classes. Briselist is a class to hold information of all items in the grocery store. There could be up to 1,000,000 items. The information of each item is its price barcode, item name, and whether it is taxable; these are kept together in Class RriceLigtItem. The items in PriceList are loaded all together from a text filel, or inserted one at a time. The complete grocery bill is computed in Class GrecervBill. To do so, it is given (a const pointer to) a previously created eieat to get the prices, and the tax rate percentage for taxable items when constructed. It is then given barcodes of items and their quantity. The barcodes can be given one at a time, or they can be collected together in a text file. You are to complete the implementations of these classes, adding public/private member variables and functions as needed. You should not use any of the C++ Standard Library containers (such as std::array, std::vector, std::list) for this project. Your code is tested in the provided main.cpp. Initially, the given code does not even compile. As you complete the code, it will pass the tests in the main

Explanation / Answer

In priceList.cpp, the member variables are not initialized.

Have a constructor to do this job

PriceList::PriceList()
{
size = 0;
items = new PriceListItem[1000000];
}