SlideShare a Scribd company logo
C++ help finish my code
Phase 1 - input phase. Main reads the file and populates one Grocery element in the array for
each input
record. This is a standard .txt file and is delimited by new line (n) characters at the end of every
input record.
This allows you to use getline. See the Canvas assignment and copy the file named a4data.txt to
your
machine. Do not change the name of the file it must be a4data.txt. Assume that the input will be
correct.
The input record format is:
6 characters - item UPC
20 characters - item description
6 characters - cost (999.99 format)
6 characters - selling price (999.99 format)
3 characters - inventory on hand
1 character - status (o on order; d discontinued; s on shelf)
Use correct read loop logic as discussed in class.
There is no constructor. The Grocery array is statically allocated, so if there was a constructor, it
would be
executed when the array was first defined, once per element.
The maximum number of grocery items is 100, and youll need a counter to keep track of how
many there
actually are. Define that counter as a static variable in the Grocery class, and use it throughout
your code as
needed.
At the end of phase 1, main has built a set of Grocery objects.
Next, main should display all the Grocery objects to ensure that the array has been built
correctly. Examine
the input data and determine if your code is processing all the records, and each record correctly.
Display
them after you have processed the input file; do not list each object as its created within the read
loop. Use
some appropriate column formatting so that you can make sense of the output, and so that you
can verify
that the objects have all been created and populated correctly. At this point, there is no price
history data,
that will be added in the next phase. Your display should look something like this:
=====================================================================
=
UPC Description Cost Price Inventory Status
=====================================================================
=
123456 Peas, canned, 12 oz 1.23 1.89 100 s
234567 Tomatoes, sundried 2.25 3.75 25 s
345676 Pineapple, whole 2.99 4.25 0 o
Phase 2 Transaction processing phase. Main asks the console user for transactions. Use getline;
do
not use some other form of input. There are four different types of transactions. Assume the
transaction data
is valid (no error checking needed). There are four types of transactions:
D
Display a list of all Grocery items, one item at a time, something like this:
=====================================================================
=
UPC Description Cost Price Inventory Status
=====================================================================
=
123456 Peas, canned, 12 oz 1.23 1.89 100 s
Price history: 2021-03-17 1.11
2021-04-17 1.45
2022-06-14 1.89
234567 Tomatoes, sundried 2.25 3.75 25 s
Price history: 2021-03-17 1.98
2021-04-17 2.25
345676 Pineapple, whole 2.99 4.25 0 o
Price history: there is no price history for this item
. . .
H upc date price
Add a price history to the grocery item with UPC code upc. The upc, date, and price fields are
fixed in size and
separated by blanks. Perform a linear search for the item. If its found, add the history and
display a success
message. If the UPC isnt found, display a not found message. You may assume that you will
never add
more than 25 history items per grocery item.
C upc1 upc2
Compares the number of price history elements for the two items specified by upc1 and upc2. If
the number
of elements is equal, display a message saying they are equal. Otherwise, display a message
saying they are
not equal. Use an operator== overload to implement the comparison. If either upc is not found,
display an
error message.
X
Clean up and exit.
Source code file structure
Separate your code into five source files:
main.cpp main
Grocery.hpp class definition
Grocery.cpp class definition for any member functions
Phistory.hpp class definition
Phistory.cpp class definition for any member functions
My code so far:
main:
//====================================================================
========
// Name :cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//====================================================================
========
#include "Grocery.hpp"
#include "Phistory.hpp"
#include
#include
#include
#include
using namespace std;
int main()
{
Grocery groceries[100];
int num_groceries = 0;
// Read input file and populate the Grocery array
ifstream infile;
infile.open("a4data.txt");
if (!infile)
{
cout << "Error: could not open filen";
return 0;
}
string line;
while (getline(infile, line))
{
int upc;
string description;
float cost;
float sellingPrice;
int inventory;
char status;
int priceHistory[25];
int numPriceHistories;
// Read each field from the line
string sub;
int start = 0;
int length = 6;
sub = line.substr(start, length);
upc = stoi(sub);
start += length + 1;
length = 20;
sub = line.substr(start, length);
description = sub;
start += length + 1;
length = 6;
sub = line.substr(start, length);
cost = stof(sub);
start += length + 1;
length = 6;
sub = line.substr(start, length);
sellingPrice = stof(sub);
start += length + 1;
length = 3;
sub = line.substr(start, length);
inventory = stoi(sub);
start += length + 1;
length = 1;
sub = line.substr(start, length);
status = sub[0];
// Populate the array with the Grocery object
Grocery grocery = Grocery(upc, description, cost, sellingPrice, inventory, status,
priceHistory[25],numPriceHistories);
groceries[num_groceries] = grocery;
num_groceries += 1;
}
infile.close();
return 0;
}
Grocery.hpp
#ifndef GROCERY_HPP
#define GROCERY_HPP
#include "Phistory.hpp"
#include
#include
using namespace std;
class Grocery
{
private:
int upc;
string description;
float cost;
float selling_price;
int inventory;
char status;
//PriceHistory price_history[25];
int num_used_history;
static int num_groceries;
public:
// Constructor
Grocery(int upc, string description, float cost, float selling_price, int inventory, char status );
// Accessors and mutators
int getUPC();
string getDescription();
float getCost();
float getSellingPrice();
int getInventory();
char getStatus();
PriceHistory getPriceHistory(int index);
int getNumUsedHistory();
static int getNumGroceries();
void setUPC(int upc);
void setDescription(string description);
void setCost(float cost);
void setSellingPrice(float selling_price);
void setInventory(int inventory);
void setStatus(char status);
// Other
void addHistory(PriceHistory history);
friend bool operator==(Grocery &g1, Grocery &g2);
};
#endif
Grocery.cpp
#include "Grocery.hpp"
#include
#include
// Constructor
Grocery::Grocery(int upc, string description, float cost, float selling_price, int inventory, char
status)
{
this->upc = upc;
this->description = description;
this->cost = cost;
this->selling_price = selling_price;
this->inventory = inventory;
this->status = status;
this->num_used_history = 0;
Grocery::num_groceries += 1;
}
// and mutators
int Grocery::getUPC()
{
return upc;
}
string Grocery::getDescription()
{
return description;
}
float Grocery::getCost()
{
return cost;
}
float Grocery::getSellingPrice()
{
return selling_price;
}
int Grocery::getInventory()
{
return inventory;
}
char Grocery::getStatus()
{
return status;
}
PriceHistory Grocery::getPriceHistory(int index)
{
return price_history[index];
}
int Grocery::getNumUsedHistory()
{
return num_used_history;
}
int Grocery::getNumGroceries()
{
return num_groceries;
}
void Grocery::setUPC(int upc)
{
this->upc = upc;
}
void Grocery::setDescription(string description)
{
this->description = description;
}
void Grocery::setCost(float cost)
{
this->cost = cost;
}
void Grocery::setSellingPrice(float selling_price)
{
this->selling_price = selling_price;
}
void Grocery::setInventory(int inventory)
{
this->inventory = inventory;
}
void Grocery::setStatus(char status)
{
this->status = status;
}
void Grocery::displayCH() const
{
cout << "Price history: ";
if (numUsed == 0)
cout << "there is no price history for this item." << endl;
else
{
for (int i = 0; i < numUsed; i++)
cout << priceHistory[i].date << " " << priceHistory[i].historicalPrice << endl;
}
}
Phistory.hpp
#pragma once
#include
#include
using namespace std;
class PriceHistory {
private:
string date;
float price;
public:
// Constructor
PriceHistory(string d, float p) {
date = d;
price = p;
}
// Getter functions
string getDate();
float getPrice();
};
Phistory.cpp
#pragma once
#include "Phistory.hpp"
string PriceHistory::getDate() {
return date;
}
float PriceHistory::getPrice() {
return price;
}
the errors I get:
../src/Grocery.cpp:8:10: error: constructor for 'Grocery' must explicitly initialize the member
'price_history' which does not have a default constructor
Grocery::Grocery(int upc, string description, float cost, float selling_price, int inventory, char
status)
^
../src/Grocery.hpp:19:15: note: member is declared here
PriceHistory price_history[25];
^
../src/Grocery.cpp:98:6: error: use of undeclared identifier 'numUsed'
if (numUsed == 0)
^
../src/Grocery.cpp:102:23: error: use of undeclared identifier 'numUsed'
for (int i = 0; i < numUsed; i++)
^
../src/Grocery.cpp:103:12: error: use of undeclared identifier 'priceHistory'; did you mean
'price_history'?
cout << priceHistory[i].date << " " << priceHistory[i].historicalPrice << endl;
^~~~~~~~~~~~
price_history
../src/Grocery.hpp:19:15: note: 'price_history' declared here
PriceHistory price_history[25];
^
../src/Grocery.cpp:103:28: error: 'date' is a private member of 'PriceHistory'
cout << priceHistory[i].date << " " << priceHistory[i].historicalPrice << endl;
^
../src/Phistory.hpp:11:12: note: declared private here
string date;
^
../src/Grocery.cpp:103:43: error: use of undeclared identifier 'priceHistory'; did you mean
'price_history'?
cout << priceHistory[i].date << " " << priceHistory[i].historicalPrice << endl;
^~~~~~~~~~~~
price_history
../src/Grocery.hpp:19:15: note: 'price_history' declared here
PriceHistory price_history[25];
^
../src/Grocery.cpp:103:59: error: no member named 'historicalPrice' in 'PriceHistory'
cout << priceHistory[i].date << " " << priceHistory[i].historicalPrice << endl;

More Related Content

PDF
C++ help finish my code Topics class definitions, arrays of objec.pdf
PDF
12.9 Program Online shopping cart (continued) (C++)This program e.pdf
PDF
Please the following is the currency class of perious one- class Curre.pdf
DOCX
Please solve the following problem using C++- Thank you Instructions-.docx
DOCX
hello- please dont just copy from other answers- the following is the.docx
PPT
PDF
I really need help with this Assignment Please in C programming not .pdf
DOCX
ObjectivesMore practice with recursion.Practice writing some tem.docx
C++ help finish my code Topics class definitions, arrays of objec.pdf
12.9 Program Online shopping cart (continued) (C++)This program e.pdf
Please the following is the currency class of perious one- class Curre.pdf
Please solve the following problem using C++- Thank you Instructions-.docx
hello- please dont just copy from other answers- the following is the.docx
I really need help with this Assignment Please in C programming not .pdf
ObjectivesMore practice with recursion.Practice writing some tem.docx

Similar to C++ help finish my code Phase 1 - input phase. Main reads the fi.pdf (20)

PDF
Container adapters
DOCX
please code in c#- please note that im a complete beginner- northwind.docx
DOCX
Sample-Program-file-with-output-and-index.docx
PPTX
C++ Programming Homework Help
PDF
Below is my code- I have an error that I still have difficulty figurin.pdf
DOCX
You are to write a program that computes customers bill for hisher.docx
PDF
I have the first program completed (not how request, but it works) a.pdf
PPT
Chapter2pp
DOCX
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
PPTX
Lecture 9
PPT
19-Lec - Multidimensional Arrays.ppt
DOC
CBSE Class XII Comp sc practical file
PDF
Cheat Sheet for Stata v15.00 PDF Complete
DOCX
PorfolioReport
PPT
PPTX
Library functions in c++
PDF
So I already have most of the code and now I have to1. create an .pdf
PPTX
Basic iOS Training with SWIFT - Part 2
DOCX
WD programs descriptions.docx
DOC
C important questions
Container adapters
please code in c#- please note that im a complete beginner- northwind.docx
Sample-Program-file-with-output-and-index.docx
C++ Programming Homework Help
Below is my code- I have an error that I still have difficulty figurin.pdf
You are to write a program that computes customers bill for hisher.docx
I have the first program completed (not how request, but it works) a.pdf
Chapter2pp
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
Lecture 9
19-Lec - Multidimensional Arrays.ppt
CBSE Class XII Comp sc practical file
Cheat Sheet for Stata v15.00 PDF Complete
PorfolioReport
Library functions in c++
So I already have most of the code and now I have to1. create an .pdf
Basic iOS Training with SWIFT - Part 2
WD programs descriptions.docx
C important questions
Ad

More from info189835 (20)

PDF
Can someone help with the implementation of these generic ArrayList .pdf
PDF
can someone help with the implementation of these generic DoublyLink.pdf
PDF
can someone help with the implementation of these generic LinkedList.pdf
PDF
Can someone explain me the steps pleaseTake the provided files.pdf
PDF
can someone briefly answer these questions please1) how socia.pdf
PDF
Can anyone help me to understand why Consider a two way ANOVA model.pdf
PDF
can anyone help Prokaryotes are highly successful biological organi.pdf
PDF
Cambios en los Activos y Pasivos Operativos Actuales�M�todo Indirect.pdf
PDF
California condors (Gymnogyps californianus) are listed on the IUCN .pdf
PDF
California continues to face a water shortage. The quantity of water.pdf
PDF
Calculate the various ratios based on the following informationCa.pdf
PDF
calculate the return on assets calculate the return on equity ca.pdf
PDF
Calculate the frequency of alleles A and B for the two populations s.pdf
PDF
Calculate the Earnings Per Share (EPS) and Dividends Per Share (DPS).pdf
PDF
Calculate the of total (portfolio weight) for eachStock A pr.pdf
PDF
Calculate R2. (Round your answer to 4 decimal places.)Moviegoer Sp.pdf
PDF
Cada vez es m�s dif�cil mantenerse al d�a con los problemas tecnol�g.pdf
PDF
Cada una de las siguientes cuentas se reporta como pasivo a largo pl.pdf
PDF
C coding into MIPS coding (Make sure this code works on Qtmips) Ho.pdf
PDF
C++ help !!!!Sally wants to write a program to help with her kee.pdf
Can someone help with the implementation of these generic ArrayList .pdf
can someone help with the implementation of these generic DoublyLink.pdf
can someone help with the implementation of these generic LinkedList.pdf
Can someone explain me the steps pleaseTake the provided files.pdf
can someone briefly answer these questions please1) how socia.pdf
Can anyone help me to understand why Consider a two way ANOVA model.pdf
can anyone help Prokaryotes are highly successful biological organi.pdf
Cambios en los Activos y Pasivos Operativos Actuales�M�todo Indirect.pdf
California condors (Gymnogyps californianus) are listed on the IUCN .pdf
California continues to face a water shortage. The quantity of water.pdf
Calculate the various ratios based on the following informationCa.pdf
calculate the return on assets calculate the return on equity ca.pdf
Calculate the frequency of alleles A and B for the two populations s.pdf
Calculate the Earnings Per Share (EPS) and Dividends Per Share (DPS).pdf
Calculate the of total (portfolio weight) for eachStock A pr.pdf
Calculate R2. (Round your answer to 4 decimal places.)Moviegoer Sp.pdf
Cada vez es m�s dif�cil mantenerse al d�a con los problemas tecnol�g.pdf
Cada una de las siguientes cuentas se reporta como pasivo a largo pl.pdf
C coding into MIPS coding (Make sure this code works on Qtmips) Ho.pdf
C++ help !!!!Sally wants to write a program to help with her kee.pdf
Ad

Recently uploaded (20)

PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Sports Quiz easy sports quiz sports quiz
PDF
Insiders guide to clinical Medicine.pdf
PDF
Basic Mud Logging Guide for educational purpose
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
01-Introduction-to-Information-Management.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Renaissance Architecture: A Journey from Faith to Humanism
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Module 4: Burden of Disease Tutorial Slides S2 2025
Sports Quiz easy sports quiz sports quiz
Insiders guide to clinical Medicine.pdf
Basic Mud Logging Guide for educational purpose
STATICS OF THE RIGID BODIES Hibbelers.pdf
Microbial diseases, their pathogenesis and prophylaxis
01-Introduction-to-Information-Management.pdf
TR - Agricultural Crops Production NC III.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
GDM (1) (1).pptx small presentation for students
Supply Chain Operations Speaking Notes -ICLT Program
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
VCE English Exam - Section C Student Revision Booklet

C++ help finish my code Phase 1 - input phase. Main reads the fi.pdf

  • 1. C++ help finish my code Phase 1 - input phase. Main reads the file and populates one Grocery element in the array for each input record. This is a standard .txt file and is delimited by new line (n) characters at the end of every input record. This allows you to use getline. See the Canvas assignment and copy the file named a4data.txt to your machine. Do not change the name of the file it must be a4data.txt. Assume that the input will be correct. The input record format is: 6 characters - item UPC 20 characters - item description 6 characters - cost (999.99 format) 6 characters - selling price (999.99 format) 3 characters - inventory on hand 1 character - status (o on order; d discontinued; s on shelf) Use correct read loop logic as discussed in class. There is no constructor. The Grocery array is statically allocated, so if there was a constructor, it would be executed when the array was first defined, once per element. The maximum number of grocery items is 100, and youll need a counter to keep track of how many there actually are. Define that counter as a static variable in the Grocery class, and use it throughout your code as needed. At the end of phase 1, main has built a set of Grocery objects. Next, main should display all the Grocery objects to ensure that the array has been built correctly. Examine the input data and determine if your code is processing all the records, and each record correctly. Display them after you have processed the input file; do not list each object as its created within the read loop. Use some appropriate column formatting so that you can make sense of the output, and so that you can verify
  • 2. that the objects have all been created and populated correctly. At this point, there is no price history data, that will be added in the next phase. Your display should look something like this: ===================================================================== = UPC Description Cost Price Inventory Status ===================================================================== = 123456 Peas, canned, 12 oz 1.23 1.89 100 s 234567 Tomatoes, sundried 2.25 3.75 25 s 345676 Pineapple, whole 2.99 4.25 0 o Phase 2 Transaction processing phase. Main asks the console user for transactions. Use getline; do not use some other form of input. There are four different types of transactions. Assume the transaction data is valid (no error checking needed). There are four types of transactions: D Display a list of all Grocery items, one item at a time, something like this: ===================================================================== = UPC Description Cost Price Inventory Status ===================================================================== = 123456 Peas, canned, 12 oz 1.23 1.89 100 s Price history: 2021-03-17 1.11 2021-04-17 1.45 2022-06-14 1.89 234567 Tomatoes, sundried 2.25 3.75 25 s Price history: 2021-03-17 1.98 2021-04-17 2.25 345676 Pineapple, whole 2.99 4.25 0 o Price history: there is no price history for this item . . . H upc date price Add a price history to the grocery item with UPC code upc. The upc, date, and price fields are fixed in size and
  • 3. separated by blanks. Perform a linear search for the item. If its found, add the history and display a success message. If the UPC isnt found, display a not found message. You may assume that you will never add more than 25 history items per grocery item. C upc1 upc2 Compares the number of price history elements for the two items specified by upc1 and upc2. If the number of elements is equal, display a message saying they are equal. Otherwise, display a message saying they are not equal. Use an operator== overload to implement the comparison. If either upc is not found, display an error message. X Clean up and exit. Source code file structure Separate your code into five source files: main.cpp main Grocery.hpp class definition Grocery.cpp class definition for any member functions Phistory.hpp class definition Phistory.cpp class definition for any member functions My code so far: main: //==================================================================== ======== // Name :cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //==================================================================== ======== #include "Grocery.hpp" #include "Phistory.hpp" #include
  • 4. #include #include #include using namespace std; int main() { Grocery groceries[100]; int num_groceries = 0; // Read input file and populate the Grocery array ifstream infile; infile.open("a4data.txt"); if (!infile) { cout << "Error: could not open filen"; return 0; } string line; while (getline(infile, line)) { int upc; string description; float cost; float sellingPrice; int inventory; char status; int priceHistory[25]; int numPriceHistories; // Read each field from the line string sub; int start = 0; int length = 6; sub = line.substr(start, length); upc = stoi(sub); start += length + 1; length = 20; sub = line.substr(start, length);
  • 5. description = sub; start += length + 1; length = 6; sub = line.substr(start, length); cost = stof(sub); start += length + 1; length = 6; sub = line.substr(start, length); sellingPrice = stof(sub); start += length + 1; length = 3; sub = line.substr(start, length); inventory = stoi(sub); start += length + 1; length = 1; sub = line.substr(start, length); status = sub[0]; // Populate the array with the Grocery object Grocery grocery = Grocery(upc, description, cost, sellingPrice, inventory, status, priceHistory[25],numPriceHistories); groceries[num_groceries] = grocery; num_groceries += 1; } infile.close(); return 0; } Grocery.hpp #ifndef GROCERY_HPP #define GROCERY_HPP #include "Phistory.hpp" #include #include using namespace std; class Grocery {
  • 6. private: int upc; string description; float cost; float selling_price; int inventory; char status; //PriceHistory price_history[25]; int num_used_history; static int num_groceries; public: // Constructor Grocery(int upc, string description, float cost, float selling_price, int inventory, char status ); // Accessors and mutators int getUPC(); string getDescription(); float getCost(); float getSellingPrice(); int getInventory(); char getStatus(); PriceHistory getPriceHistory(int index); int getNumUsedHistory(); static int getNumGroceries(); void setUPC(int upc); void setDescription(string description); void setCost(float cost); void setSellingPrice(float selling_price); void setInventory(int inventory); void setStatus(char status); // Other void addHistory(PriceHistory history); friend bool operator==(Grocery &g1, Grocery &g2); }; #endif Grocery.cpp #include "Grocery.hpp"
  • 7. #include #include // Constructor Grocery::Grocery(int upc, string description, float cost, float selling_price, int inventory, char status) { this->upc = upc; this->description = description; this->cost = cost; this->selling_price = selling_price; this->inventory = inventory; this->status = status; this->num_used_history = 0; Grocery::num_groceries += 1; } // and mutators int Grocery::getUPC() { return upc; } string Grocery::getDescription() { return description; } float Grocery::getCost() { return cost; } float Grocery::getSellingPrice() { return selling_price; } int Grocery::getInventory() { return inventory; }
  • 8. char Grocery::getStatus() { return status; } PriceHistory Grocery::getPriceHistory(int index) { return price_history[index]; } int Grocery::getNumUsedHistory() { return num_used_history; } int Grocery::getNumGroceries() { return num_groceries; } void Grocery::setUPC(int upc) { this->upc = upc; } void Grocery::setDescription(string description) { this->description = description; } void Grocery::setCost(float cost) { this->cost = cost; } void Grocery::setSellingPrice(float selling_price) { this->selling_price = selling_price; } void Grocery::setInventory(int inventory) { this->inventory = inventory; }
  • 9. void Grocery::setStatus(char status) { this->status = status; } void Grocery::displayCH() const { cout << "Price history: "; if (numUsed == 0) cout << "there is no price history for this item." << endl; else { for (int i = 0; i < numUsed; i++) cout << priceHistory[i].date << " " << priceHistory[i].historicalPrice << endl; } } Phistory.hpp #pragma once #include #include using namespace std; class PriceHistory { private: string date; float price; public: // Constructor PriceHistory(string d, float p) { date = d; price = p; } // Getter functions string getDate(); float getPrice(); }; Phistory.cpp #pragma once
  • 10. #include "Phistory.hpp" string PriceHistory::getDate() { return date; } float PriceHistory::getPrice() { return price; } the errors I get: ../src/Grocery.cpp:8:10: error: constructor for 'Grocery' must explicitly initialize the member 'price_history' which does not have a default constructor Grocery::Grocery(int upc, string description, float cost, float selling_price, int inventory, char status) ^ ../src/Grocery.hpp:19:15: note: member is declared here PriceHistory price_history[25]; ^ ../src/Grocery.cpp:98:6: error: use of undeclared identifier 'numUsed' if (numUsed == 0) ^ ../src/Grocery.cpp:102:23: error: use of undeclared identifier 'numUsed' for (int i = 0; i < numUsed; i++) ^ ../src/Grocery.cpp:103:12: error: use of undeclared identifier 'priceHistory'; did you mean 'price_history'? cout << priceHistory[i].date << " " << priceHistory[i].historicalPrice << endl; ^~~~~~~~~~~~ price_history ../src/Grocery.hpp:19:15: note: 'price_history' declared here PriceHistory price_history[25]; ^ ../src/Grocery.cpp:103:28: error: 'date' is a private member of 'PriceHistory' cout << priceHistory[i].date << " " << priceHistory[i].historicalPrice << endl; ^
  • 11. ../src/Phistory.hpp:11:12: note: declared private here string date; ^ ../src/Grocery.cpp:103:43: error: use of undeclared identifier 'priceHistory'; did you mean 'price_history'? cout << priceHistory[i].date << " " << priceHistory[i].historicalPrice << endl; ^~~~~~~~~~~~ price_history ../src/Grocery.hpp:19:15: note: 'price_history' declared here PriceHistory price_history[25]; ^ ../src/Grocery.cpp:103:59: error: no member named 'historicalPrice' in 'PriceHistory' cout << priceHistory[i].date << " " << priceHistory[i].historicalPrice << endl;