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

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

Container adapters
Container adaptersContainer adapters
Container adapters
mohamed sikander
 
please code in c#- please note that im a complete beginner- northwind.docx
please code in c#- please note that im a complete beginner-  northwind.docxplease code in c#- please note that im a complete beginner-  northwind.docx
please code in c#- please note that im a complete beginner- northwind.docx
AustinaGRPaigey
 
C++ Programming Homework Help
C++ Programming Homework HelpC++ Programming Homework Help
C++ Programming Homework Help
C++ Homework Help
 
Below is my code- I have an error that I still have difficulty figurin.pdf
Below is my code- I have an error that I still have difficulty figurin.pdfBelow is my code- I have an error that I still have difficulty figurin.pdf
Below is my code- I have an error that I still have difficulty figurin.pdf
armanuelraj
 
You are to write a program that computes customers bill for hisher.docx
 You are to write a program that computes customers bill for hisher.docx You are to write a program that computes customers bill for hisher.docx
You are to write a program that computes customers bill for hisher.docx
ajoy21
 
I have the first program completed (not how request, but it works) a.pdf
I have the first program completed (not how request, but it works) a.pdfI have the first program completed (not how request, but it works) a.pdf
I have the first program completed (not how request, but it works) a.pdf
footworld1
 
Chapter2pp
Chapter2ppChapter2pp
Chapter2ppJ. C.
 
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docxIn Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
bradburgess22840
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
Mohammed Khan
 
19-Lec - Multidimensional Arrays.ppt
19-Lec - Multidimensional Arrays.ppt19-Lec - Multidimensional Arrays.ppt
19-Lec - Multidimensional Arrays.ppt
AqeelAbbas94
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical file
Pranav Ghildiyal
 
Cheat Sheet for Stata v15.00 PDF Complete
Cheat Sheet for Stata v15.00 PDF CompleteCheat Sheet for Stata v15.00 PDF Complete
Cheat Sheet for Stata v15.00 PDF Complete
TsamaraLuthfia1
 
PorfolioReport
PorfolioReportPorfolioReport
PorfolioReportAlbert Chu
 
Arrays
ArraysArrays
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++
Neeru Mittal
 
So I already have most of the code and now I have to1. create an .pdf
So I already have most of the code and now I have to1. create an .pdfSo I already have most of the code and now I have to1. create an .pdf
So I already have most of the code and now I have to1. create an .pdf
arjuncollection
 
Basic iOS Training with SWIFT - Part 2
Basic iOS Training with SWIFT - Part 2Basic iOS Training with SWIFT - Part 2
Basic iOS Training with SWIFT - Part 2
Manoj Ellappan
 
WD programs descriptions.docx
WD programs descriptions.docxWD programs descriptions.docx
WD programs descriptions.docx
anjani pavan kumar
 
C important questions
C important questionsC important questions
C important questions
JYOTI RANJAN PAL
 
Lecture 2
Lecture 2Lecture 2

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

Container adapters
Container adaptersContainer adapters
Container adapters
 
please code in c#- please note that im a complete beginner- northwind.docx
please code in c#- please note that im a complete beginner-  northwind.docxplease code in c#- please note that im a complete beginner-  northwind.docx
please code in c#- please note that im a complete beginner- northwind.docx
 
C++ Programming Homework Help
C++ Programming Homework HelpC++ Programming Homework Help
C++ Programming Homework Help
 
Below is my code- I have an error that I still have difficulty figurin.pdf
Below is my code- I have an error that I still have difficulty figurin.pdfBelow is my code- I have an error that I still have difficulty figurin.pdf
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
 You are to write a program that computes customers bill for hisher.docx You are to write a program that computes customers bill for hisher.docx
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
I have the first program completed (not how request, but it works) a.pdfI have the first program completed (not how request, but it works) a.pdf
I have the first program completed (not how request, but it works) a.pdf
 
Chapter2pp
Chapter2ppChapter2pp
Chapter2pp
 
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docxIn Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
 
19-Lec - Multidimensional Arrays.ppt
19-Lec - Multidimensional Arrays.ppt19-Lec - Multidimensional Arrays.ppt
19-Lec - Multidimensional Arrays.ppt
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical file
 
Cheat Sheet for Stata v15.00 PDF Complete
Cheat Sheet for Stata v15.00 PDF CompleteCheat Sheet for Stata v15.00 PDF Complete
Cheat Sheet for Stata v15.00 PDF Complete
 
PorfolioReport
PorfolioReportPorfolioReport
PorfolioReport
 
Arrays
ArraysArrays
Arrays
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++
 
So I already have most of the code and now I have to1. create an .pdf
So I already have most of the code and now I have to1. create an .pdfSo I already have most of the code and now I have to1. create an .pdf
So I already have most of the code and now I have to1. create an .pdf
 
Basic iOS Training with SWIFT - Part 2
Basic iOS Training with SWIFT - Part 2Basic iOS Training with SWIFT - Part 2
Basic iOS Training with SWIFT - Part 2
 
WD programs descriptions.docx
WD programs descriptions.docxWD programs descriptions.docx
WD programs descriptions.docx
 
C important questions
C important questionsC important questions
C important questions
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 

More from info189835

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

More from info189835 (20)

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

Recently uploaded

The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 

Recently uploaded (20)

The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 

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;