SlideShare a Scribd company logo
1 of 13
Download to read offline
Why won't my code build and run? and what is the correct code so it builds successfully?
getting errors in the Product.cpp file error:(Expected unqualified-id)
all code below and files
Main.cpp
#include <iostream>
#include <time.h>
#include "InventorySystem.hpp"
#include <iostream>
#include "Product.hpp"
#include <time.h>
#include <stdlib.h>
using namespace std;
int main() {
srand(time( NULL ));
Inventory_System *h1 = nullptr ;
h1 = new Inventory_System("Radioshack", 117);
h1->BuildInventory();
h1->ShowInventory();
h1->ShowDefectInventory();
h1->Terminate();
delete h1;
return 0;
};
InventorySystem.cpp
#include "InventorySystem.hpp"
#include "InventoryItem.hpp"
#include "Product.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
Inventory_System::Inventory_System() {
}
Inventory_System::Inventory_System(std::string name, int id) :
store_name(name),
store_id(id) {
}
Inventory_System::~Inventory_System() {
for ( int i = 0; i < item_count; i++) {
delete ptr_inv_item[i];
}
}
int Inventory_System::GetStoreId(){
return store_id;
}
int Inventory_System::GetItemCount(){
return item_count;
}
std::string Inventory_System::GetStoreName(){
return store_name;
}
void Inventory_System::BuildInventory() {
std::ifstream file("products_test.txt", std::ios::in);
std::string name, quantity, price, condition;
Inventory_Item *item;
if (!file) {
std::cerr << "Error: Failed to open filen";
exit(-1);
}
else {
while (!file.eof()) {
item = new Product();
Product *product = static_cast <Product*> (item);
std::getline(file, name, ';');
product->SetItemName(name);
std::getline(file, quantity, ';');
product->SetItemQuantity(stoi(quantity));
std::getline(file, price, ';');
product->SetProductPrice(stold(price));
std::getline(file, condition, 'n');
switch (condition[0]) {
case 'D':
product->SetProductCondition(PC_DEFECTIVE);
break ;
case 'N':
product->SetProductCondition(PC_NEW);
break ;
case 'R':
product->SetProductCondition(PC_REFURBISHED);
break ;
case 'U':
product->SetProductCondition(PC_USED);
break ;
default :
product->SetProductCondition(PC_NEW);
break ;
}
product->SetProductId(rand() % 10000);
ptr_inv_item[item_count] = product;
item_count++;
}
}
}
void Inventory_System::ShowInventory() {
for ( int i = 0; i < item_count; i++) {
Product *temp = static_cast <Product*> (ptr_inv_item[i]);
temp->Display();
}
}
void Inventory_System::ShowDefectInventory() {
for ( int i = 0; i < item_count; i++) {
Product *temp = static_cast <Product*> (ptr_inv_item[i]);
if (temp->GetProductCondition() == PC_DEFECTIVE) {
temp->Display();
}
}
}
void Inventory_System::Terminate() {
std::ofstream file;
std::stringstream ss;
file.open("example.txt");
for ( int i = 0; i < item_count; i++) {
Product *temp = static_cast <Product*> (ptr_inv_item[i]);
file << temp->GetItemName() << ";"
<< temp->GetItemQuantity() << ";"
<< temp->GetProductPrice() << ";";
switch (temp->GetProductCondition()) {
case PC_DEFECTIVE:
file << "Dn";
break ;
case PC_NEW:
file << "Nn";
break ;
case PC_REFURBISHED:
file << "Rn";
break ;
case PC_USED:
file << "Un";
break ;
default :
file << "Dn";
break ;
}
}
}
InventorySystem.h
#ifndef InventorySystem_hpp
#define InventorySystem_hpp
#include "InventoryItem.hpp"
#include "Product.hpp"
#include <stdio.h>
#include <string>
class Inventory_System {
public :
Inventory_System();
Inventory_System(std::string, int );
~Inventory_System();
int GetStoreId();
int GetItemCount();
std::string GetStoreName();
void BuildInventory();
void ShowInventory();
void ShowDefectInventory();
void Terminate();
private :
std::string store_name;
int store_id, item_count = 0;
Inventory_Item **ptr_inv_item = new Inventory_Item*[512];
};
#endif /* InventorySystem_hpp */
InventoryItem.cpp
#include "InventoryItem.hpp"
#include <iostream>
Inventory_Item::Inventory_Item(){
}
Inventory_Item::Inventory_Item(std::string name, int quantity) :
item_name(name),
item_quantity(quantity) {
}
Inventory_Item::~Inventory_Item() {
std::cout << "Inventory Item " << item_name << " with " << item_quantity << " item(s)
destroyed.n";
}
std::string Inventory_Item::GetItemName() const {
return item_name;
}
int Inventory_Item::GetItemQuantity() const {
return item_quantity;
}
void Inventory_Item::SetItemName(std::string name) {
item_name = name;
}
void Inventory_Item::SetItemQuantity( int quantity) {
item_quantity = quantity;
}
void Inventory_Item::Display() const {
std::cout << item_name << " (" << item_quantity << ") ";
}
InventoryItem.h
#ifndef InventoryItem_hpp
#define InventoryItem_hpp
#include <stdio.h>
#include <string>
class Inventory_Item {
public :
Inventory_Item();
Inventory_Item(std::string name, int quantity);
~Inventory_Item();
std::string GetItemName() const ;
int GetItemQuantity() const ;
void SetItemName(std::string);
void SetItemQuantity( int );
virtual void Display() const ;
protected :
std::string item_name;
int item_quantity;
private :
};
#endif /* InventoryItem_hpp */
Product.cpp
#include "Product.hpp"
#include <iostream>
#include <iomanip>
Product::Product() :
Inventory_Item(),
product_id(0),
product_price(0.0) {
}
Inventory_Item(),
product_id(0),
product_price(0.0){
}
Product::Product(std::string name, int quantity) :
Inventory_Item(name, quantity),
product_id(rand()% 1000),
product_price(100.0 * ((rand() + 1) / double (RAND_MAX + 2))){
}
Product::~Product() {
std::cout << "Product " << product_id << " priced $" << product_price << " has been
destroyed.";
}
int Product::GetProductId() const {
return product_id;
}
double Product::GetProductPrice() const {
return product_price;
}
T_Condition Product::GetProductCondition() const {
return condition_;
}
void Product::SetProductId( int id){
product_id = id;
}
void Product::SetProductPrice( double price) {
product_price = price;
}
void Product::SetProductCondition(T_Condition condition) {
condition_ = condition;
}
void Product::Display() const {
Inventory_Item::Display();
std::cout << product_id << " $" << std::setprecision(4) << product_price << 'n';
}
Product.h
#ifndef Product_hpp
#define Product_hpp
#include "InventoryItem.hpp"
#include <stdio.h>
#include "Product.hpp"
#include <string>
typedef enum { PC_NEW, PC_USED, PC_REFURBISHED, PC_DEFECTIVE } T_Condition;
class Product : public Inventory_Item {
public :
Product();
Product(std::string, int );
~Product();
int GetProductId() const ;
double GetProductPrice() const ;
T_Condition GetProductCondition() const ;
void SetProductId( int );
void SetProductPrice( double );
void SetProductCondition(T_Condition);
virtual void Display() const ;
private :
T_Condition condition_;
int product_id;
double product_price;
};
#endif /* Product_hpp */
Why won't my code build and run- and what is the correct code so it bu.pdf

More Related Content

Similar to Why won't my code build and run- and what is the correct code so it bu.pdf

Writing native bindings to node.js in C++
Writing native bindings to node.js in C++Writing native bindings to node.js in C++
Writing native bindings to node.js in C++nsm.nikhil
 
Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Juan Pablo
 
How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js ModuleFred Chien
 
Threads and Callbacks for Embedded Python
Threads and Callbacks for Embedded PythonThreads and Callbacks for Embedded Python
Threads and Callbacks for Embedded PythonYi-Lung Tsai
 
CPP Programming Homework Help
CPP Programming Homework HelpCPP Programming Homework Help
CPP Programming Homework HelpC++ Homework Help
 
#include stdio.h#include stdlib.h#include string.hstruct.pdf
#include stdio.h#include stdlib.h#include string.hstruct.pdf#include stdio.h#include stdlib.h#include string.hstruct.pdf
#include stdio.h#include stdlib.h#include string.hstruct.pdfanubhavnigam2608
 
Introduction to Spring Boot.pdf
Introduction to Spring Boot.pdfIntroduction to Spring Boot.pdf
Introduction to Spring Boot.pdfShaiAlmog1
 
maincpp include ListItemh include ltstringgt in.pdf
maincpp include ListItemh include ltstringgt in.pdfmaincpp include ListItemh include ltstringgt in.pdf
maincpp include ListItemh include ltstringgt in.pdfabiwarmaa
 
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdfC++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdfaassecuritysystem
 
Static code analysis: what? how? why?
Static code analysis: what? how? why?Static code analysis: what? how? why?
Static code analysis: what? how? why?Andrey Karpov
 
#include customer.h#include heap.h#include iostream.docx
#include customer.h#include heap.h#include iostream.docx#include customer.h#include heap.h#include iostream.docx
#include customer.h#include heap.h#include iostream.docxAASTHA76
 
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.docxbradburgess22840
 
This is the main file include itemh include itemList.pdf
This is the main file include itemh include itemList.pdfThis is the main file include itemh include itemList.pdf
This is the main file include itemh include itemList.pdfinfo334223
 
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxfilesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxssuser454af01
 

Similar to Why won't my code build and run- and what is the correct code so it bu.pdf (20)

Writing native bindings to node.js in C++
Writing native bindings to node.js in C++Writing native bindings to node.js in C++
Writing native bindings to node.js in C++
 
Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#
 
How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js Module
 
Threads and Callbacks for Embedded Python
Threads and Callbacks for Embedded PythonThreads and Callbacks for Embedded Python
Threads and Callbacks for Embedded Python
 
Android ndk
Android ndkAndroid ndk
Android ndk
 
CPP Programming Homework Help
CPP Programming Homework HelpCPP Programming Homework Help
CPP Programming Homework Help
 
Lecture2.ppt
Lecture2.pptLecture2.ppt
Lecture2.ppt
 
OpenCMIS Part 1
OpenCMIS Part 1OpenCMIS Part 1
OpenCMIS Part 1
 
#include stdio.h#include stdlib.h#include string.hstruct.pdf
#include stdio.h#include stdlib.h#include string.hstruct.pdf#include stdio.h#include stdlib.h#include string.hstruct.pdf
#include stdio.h#include stdlib.h#include string.hstruct.pdf
 
Introduction to Spring Boot.pdf
Introduction to Spring Boot.pdfIntroduction to Spring Boot.pdf
Introduction to Spring Boot.pdf
 
maincpp include ListItemh include ltstringgt in.pdf
maincpp include ListItemh include ltstringgt in.pdfmaincpp include ListItemh include ltstringgt in.pdf
maincpp include ListItemh include ltstringgt in.pdf
 
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdfC++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
 
Static code analysis: what? how? why?
Static code analysis: what? how? why?Static code analysis: what? how? why?
Static code analysis: what? how? why?
 
#include customer.h#include heap.h#include iostream.docx
#include customer.h#include heap.h#include iostream.docx#include customer.h#include heap.h#include iostream.docx
#include customer.h#include heap.h#include iostream.docx
 
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
 
This is the main file include itemh include itemList.pdf
This is the main file include itemh include itemList.pdfThis is the main file include itemh include itemList.pdf
This is the main file include itemh include itemList.pdf
 
C++ file
C++ fileC++ file
C++ file
 
C++ file
C++ fileC++ file
C++ file
 
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxfilesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
 
V8
V8V8
V8
 

More from umeshagarwal39

Write a c++ program that will input TWO characters then print if it is.pdf
Write a c++ program that will input TWO characters then print if it is.pdfWrite a c++ program that will input TWO characters then print if it is.pdf
Write a c++ program that will input TWO characters then print if it is.pdfumeshagarwal39
 
Wredk 10-5 Ps- Rob- Fes- me ton- Would youi like to haye a cotfer Thre.pdf
Wredk 10-5 Ps- Rob- Fes- me ton- Would youi like to haye a cotfer Thre.pdfWredk 10-5 Ps- Rob- Fes- me ton- Would youi like to haye a cotfer Thre.pdf
Wredk 10-5 Ps- Rob- Fes- me ton- Would youi like to haye a cotfer Thre.pdfumeshagarwal39
 
Write 200-250 words Q-1 Identify specific examples of different stake.pdf
Write 200-250 words  Q-1 Identify specific examples of different stake.pdfWrite 200-250 words  Q-1 Identify specific examples of different stake.pdf
Write 200-250 words Q-1 Identify specific examples of different stake.pdfumeshagarwal39
 
Working with the Concepts 5- Cable subscriptions decline- The number o.pdf
Working with the Concepts 5- Cable subscriptions decline- The number o.pdfWorking with the Concepts 5- Cable subscriptions decline- The number o.pdf
Working with the Concepts 5- Cable subscriptions decline- The number o.pdfumeshagarwal39
 
Within the organizational structure of Philips- the national organizat.pdf
Within the organizational structure of Philips- the national organizat.pdfWithin the organizational structure of Philips- the national organizat.pdf
Within the organizational structure of Philips- the national organizat.pdfumeshagarwal39
 
With appropriate referencing and elaborate explanation- write a minimu.pdf
With appropriate referencing and elaborate explanation- write a minimu.pdfWith appropriate referencing and elaborate explanation- write a minimu.pdf
With appropriate referencing and elaborate explanation- write a minimu.pdfumeshagarwal39
 
Winger corporation was organized in March- It is authorized to issue 5.pdf
Winger corporation was organized in March- It is authorized to issue 5.pdfWinger corporation was organized in March- It is authorized to issue 5.pdf
Winger corporation was organized in March- It is authorized to issue 5.pdfumeshagarwal39
 
William Ouchi's Theory Z recognized Multiple Choice the combined benef.pdf
William Ouchi's Theory Z recognized Multiple Choice the combined benef.pdfWilliam Ouchi's Theory Z recognized Multiple Choice the combined benef.pdf
William Ouchi's Theory Z recognized Multiple Choice the combined benef.pdfumeshagarwal39
 
Wildhorse Company has a balancet in its Accouats Receivable control ac.pdf
Wildhorse Company has a balancet in its Accouats Receivable control ac.pdfWildhorse Company has a balancet in its Accouats Receivable control ac.pdf
Wildhorse Company has a balancet in its Accouats Receivable control ac.pdfumeshagarwal39
 
Wildhorse Company has a balance in its Accounts Recevvable control acc.pdf
Wildhorse Company has a balance in its Accounts Recevvable control acc.pdfWildhorse Company has a balance in its Accounts Recevvable control acc.pdf
Wildhorse Company has a balance in its Accounts Recevvable control acc.pdfumeshagarwal39
 
why does this code keep generating this error- even though the URL is.pdf
why does this code keep generating this error- even though the URL is.pdfwhy does this code keep generating this error- even though the URL is.pdf
why does this code keep generating this error- even though the URL is.pdfumeshagarwal39
 
Why do you think the SEC (should or should not) to go after celebritie.pdf
Why do you think the SEC (should or should not) to go after celebritie.pdfWhy do you think the SEC (should or should not) to go after celebritie.pdf
Why do you think the SEC (should or should not) to go after celebritie.pdfumeshagarwal39
 
Who would be at increased risk for vitamin B12 deficiency without fort.pdf
Who would be at increased risk for vitamin B12 deficiency without fort.pdfWho would be at increased risk for vitamin B12 deficiency without fort.pdf
Who would be at increased risk for vitamin B12 deficiency without fort.pdfumeshagarwal39
 
Why are funny channels -funny- (different from other channels)- Becaus.pdf
Why are funny channels -funny- (different from other channels)- Becaus.pdfWhy are funny channels -funny- (different from other channels)- Becaus.pdf
Why are funny channels -funny- (different from other channels)- Becaus.pdfumeshagarwal39
 
Why do we try to remove air bubbles in the electroblot set up- Protein.pdf
Why do we try to remove air bubbles in the electroblot set up- Protein.pdfWhy do we try to remove air bubbles in the electroblot set up- Protein.pdf
Why do we try to remove air bubbles in the electroblot set up- Protein.pdfumeshagarwal39
 
Why do we need Confusion matrix-What is recall- accuracy- precision an.pdf
Why do we need Confusion matrix-What is recall- accuracy- precision an.pdfWhy do we need Confusion matrix-What is recall- accuracy- precision an.pdf
Why do we need Confusion matrix-What is recall- accuracy- precision an.pdfumeshagarwal39
 
Which of these is the best example of mechanical digestion- Group of a.pdf
Which of these is the best example of mechanical digestion- Group of a.pdfWhich of these is the best example of mechanical digestion- Group of a.pdf
Which of these is the best example of mechanical digestion- Group of a.pdfumeshagarwal39
 
Whispering Winds Corp- reported these income statement data for a 2-ye.pdf
Whispering Winds Corp- reported these income statement data for a 2-ye.pdfWhispering Winds Corp- reported these income statement data for a 2-ye.pdf
Whispering Winds Corp- reported these income statement data for a 2-ye.pdfumeshagarwal39
 
While in her hepatocyte- you notice that a molecule of carbon dioxide.pdf
While in her hepatocyte- you notice that a molecule of carbon dioxide.pdfWhile in her hepatocyte- you notice that a molecule of carbon dioxide.pdf
While in her hepatocyte- you notice that a molecule of carbon dioxide.pdfumeshagarwal39
 
Which was not a reason it took 100 years for the Copernican Revolution.pdf
Which was not a reason it took 100 years for the Copernican Revolution.pdfWhich was not a reason it took 100 years for the Copernican Revolution.pdf
Which was not a reason it took 100 years for the Copernican Revolution.pdfumeshagarwal39
 

More from umeshagarwal39 (20)

Write a c++ program that will input TWO characters then print if it is.pdf
Write a c++ program that will input TWO characters then print if it is.pdfWrite a c++ program that will input TWO characters then print if it is.pdf
Write a c++ program that will input TWO characters then print if it is.pdf
 
Wredk 10-5 Ps- Rob- Fes- me ton- Would youi like to haye a cotfer Thre.pdf
Wredk 10-5 Ps- Rob- Fes- me ton- Would youi like to haye a cotfer Thre.pdfWredk 10-5 Ps- Rob- Fes- me ton- Would youi like to haye a cotfer Thre.pdf
Wredk 10-5 Ps- Rob- Fes- me ton- Would youi like to haye a cotfer Thre.pdf
 
Write 200-250 words Q-1 Identify specific examples of different stake.pdf
Write 200-250 words  Q-1 Identify specific examples of different stake.pdfWrite 200-250 words  Q-1 Identify specific examples of different stake.pdf
Write 200-250 words Q-1 Identify specific examples of different stake.pdf
 
Working with the Concepts 5- Cable subscriptions decline- The number o.pdf
Working with the Concepts 5- Cable subscriptions decline- The number o.pdfWorking with the Concepts 5- Cable subscriptions decline- The number o.pdf
Working with the Concepts 5- Cable subscriptions decline- The number o.pdf
 
Within the organizational structure of Philips- the national organizat.pdf
Within the organizational structure of Philips- the national organizat.pdfWithin the organizational structure of Philips- the national organizat.pdf
Within the organizational structure of Philips- the national organizat.pdf
 
With appropriate referencing and elaborate explanation- write a minimu.pdf
With appropriate referencing and elaborate explanation- write a minimu.pdfWith appropriate referencing and elaborate explanation- write a minimu.pdf
With appropriate referencing and elaborate explanation- write a minimu.pdf
 
Winger corporation was organized in March- It is authorized to issue 5.pdf
Winger corporation was organized in March- It is authorized to issue 5.pdfWinger corporation was organized in March- It is authorized to issue 5.pdf
Winger corporation was organized in March- It is authorized to issue 5.pdf
 
William Ouchi's Theory Z recognized Multiple Choice the combined benef.pdf
William Ouchi's Theory Z recognized Multiple Choice the combined benef.pdfWilliam Ouchi's Theory Z recognized Multiple Choice the combined benef.pdf
William Ouchi's Theory Z recognized Multiple Choice the combined benef.pdf
 
Wildhorse Company has a balancet in its Accouats Receivable control ac.pdf
Wildhorse Company has a balancet in its Accouats Receivable control ac.pdfWildhorse Company has a balancet in its Accouats Receivable control ac.pdf
Wildhorse Company has a balancet in its Accouats Receivable control ac.pdf
 
Wildhorse Company has a balance in its Accounts Recevvable control acc.pdf
Wildhorse Company has a balance in its Accounts Recevvable control acc.pdfWildhorse Company has a balance in its Accounts Recevvable control acc.pdf
Wildhorse Company has a balance in its Accounts Recevvable control acc.pdf
 
why does this code keep generating this error- even though the URL is.pdf
why does this code keep generating this error- even though the URL is.pdfwhy does this code keep generating this error- even though the URL is.pdf
why does this code keep generating this error- even though the URL is.pdf
 
Why do you think the SEC (should or should not) to go after celebritie.pdf
Why do you think the SEC (should or should not) to go after celebritie.pdfWhy do you think the SEC (should or should not) to go after celebritie.pdf
Why do you think the SEC (should or should not) to go after celebritie.pdf
 
Who would be at increased risk for vitamin B12 deficiency without fort.pdf
Who would be at increased risk for vitamin B12 deficiency without fort.pdfWho would be at increased risk for vitamin B12 deficiency without fort.pdf
Who would be at increased risk for vitamin B12 deficiency without fort.pdf
 
Why are funny channels -funny- (different from other channels)- Becaus.pdf
Why are funny channels -funny- (different from other channels)- Becaus.pdfWhy are funny channels -funny- (different from other channels)- Becaus.pdf
Why are funny channels -funny- (different from other channels)- Becaus.pdf
 
Why do we try to remove air bubbles in the electroblot set up- Protein.pdf
Why do we try to remove air bubbles in the electroblot set up- Protein.pdfWhy do we try to remove air bubbles in the electroblot set up- Protein.pdf
Why do we try to remove air bubbles in the electroblot set up- Protein.pdf
 
Why do we need Confusion matrix-What is recall- accuracy- precision an.pdf
Why do we need Confusion matrix-What is recall- accuracy- precision an.pdfWhy do we need Confusion matrix-What is recall- accuracy- precision an.pdf
Why do we need Confusion matrix-What is recall- accuracy- precision an.pdf
 
Which of these is the best example of mechanical digestion- Group of a.pdf
Which of these is the best example of mechanical digestion- Group of a.pdfWhich of these is the best example of mechanical digestion- Group of a.pdf
Which of these is the best example of mechanical digestion- Group of a.pdf
 
Whispering Winds Corp- reported these income statement data for a 2-ye.pdf
Whispering Winds Corp- reported these income statement data for a 2-ye.pdfWhispering Winds Corp- reported these income statement data for a 2-ye.pdf
Whispering Winds Corp- reported these income statement data for a 2-ye.pdf
 
While in her hepatocyte- you notice that a molecule of carbon dioxide.pdf
While in her hepatocyte- you notice that a molecule of carbon dioxide.pdfWhile in her hepatocyte- you notice that a molecule of carbon dioxide.pdf
While in her hepatocyte- you notice that a molecule of carbon dioxide.pdf
 
Which was not a reason it took 100 years for the Copernican Revolution.pdf
Which was not a reason it took 100 years for the Copernican Revolution.pdfWhich was not a reason it took 100 years for the Copernican Revolution.pdf
Which was not a reason it took 100 years for the Copernican Revolution.pdf
 

Recently uploaded

Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 

Recently uploaded (20)

Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 

Why won't my code build and run- and what is the correct code so it bu.pdf

  • 1. Why won't my code build and run? and what is the correct code so it builds successfully? getting errors in the Product.cpp file error:(Expected unqualified-id) all code below and files Main.cpp #include <iostream> #include <time.h> #include "InventorySystem.hpp" #include <iostream> #include "Product.hpp" #include <time.h> #include <stdlib.h> using namespace std; int main() { srand(time( NULL )); Inventory_System *h1 = nullptr ; h1 = new Inventory_System("Radioshack", 117); h1->BuildInventory(); h1->ShowInventory(); h1->ShowDefectInventory(); h1->Terminate(); delete h1; return 0; };
  • 2. InventorySystem.cpp #include "InventorySystem.hpp" #include "InventoryItem.hpp" #include "Product.hpp" #include <iostream> #include <fstream> #include <sstream> Inventory_System::Inventory_System() { } Inventory_System::Inventory_System(std::string name, int id) : store_name(name), store_id(id) { } Inventory_System::~Inventory_System() { for ( int i = 0; i < item_count; i++) { delete ptr_inv_item[i]; } } int Inventory_System::GetStoreId(){ return store_id; } int Inventory_System::GetItemCount(){ return item_count;
  • 3. } std::string Inventory_System::GetStoreName(){ return store_name; } void Inventory_System::BuildInventory() { std::ifstream file("products_test.txt", std::ios::in); std::string name, quantity, price, condition; Inventory_Item *item; if (!file) { std::cerr << "Error: Failed to open filen"; exit(-1); } else { while (!file.eof()) { item = new Product(); Product *product = static_cast <Product*> (item); std::getline(file, name, ';'); product->SetItemName(name); std::getline(file, quantity, ';'); product->SetItemQuantity(stoi(quantity)); std::getline(file, price, ';'); product->SetProductPrice(stold(price)); std::getline(file, condition, 'n');
  • 4. switch (condition[0]) { case 'D': product->SetProductCondition(PC_DEFECTIVE); break ; case 'N': product->SetProductCondition(PC_NEW); break ; case 'R': product->SetProductCondition(PC_REFURBISHED); break ; case 'U': product->SetProductCondition(PC_USED); break ; default : product->SetProductCondition(PC_NEW); break ; } product->SetProductId(rand() % 10000); ptr_inv_item[item_count] = product; item_count++; } } }
  • 5. void Inventory_System::ShowInventory() { for ( int i = 0; i < item_count; i++) { Product *temp = static_cast <Product*> (ptr_inv_item[i]); temp->Display(); } } void Inventory_System::ShowDefectInventory() { for ( int i = 0; i < item_count; i++) { Product *temp = static_cast <Product*> (ptr_inv_item[i]); if (temp->GetProductCondition() == PC_DEFECTIVE) { temp->Display(); } } } void Inventory_System::Terminate() { std::ofstream file; std::stringstream ss; file.open("example.txt"); for ( int i = 0; i < item_count; i++) { Product *temp = static_cast <Product*> (ptr_inv_item[i]); file << temp->GetItemName() << ";" << temp->GetItemQuantity() << ";" << temp->GetProductPrice() << ";";
  • 6. switch (temp->GetProductCondition()) { case PC_DEFECTIVE: file << "Dn"; break ; case PC_NEW: file << "Nn"; break ; case PC_REFURBISHED: file << "Rn"; break ; case PC_USED: file << "Un"; break ; default : file << "Dn"; break ; } } } InventorySystem.h #ifndef InventorySystem_hpp #define InventorySystem_hpp #include "InventoryItem.hpp"
  • 7. #include "Product.hpp" #include <stdio.h> #include <string> class Inventory_System { public : Inventory_System(); Inventory_System(std::string, int ); ~Inventory_System(); int GetStoreId(); int GetItemCount(); std::string GetStoreName(); void BuildInventory(); void ShowInventory(); void ShowDefectInventory(); void Terminate(); private : std::string store_name; int store_id, item_count = 0; Inventory_Item **ptr_inv_item = new Inventory_Item*[512]; }; #endif /* InventorySystem_hpp */ InventoryItem.cpp #include "InventoryItem.hpp"
  • 8. #include <iostream> Inventory_Item::Inventory_Item(){ } Inventory_Item::Inventory_Item(std::string name, int quantity) : item_name(name), item_quantity(quantity) { } Inventory_Item::~Inventory_Item() { std::cout << "Inventory Item " << item_name << " with " << item_quantity << " item(s) destroyed.n"; } std::string Inventory_Item::GetItemName() const { return item_name; } int Inventory_Item::GetItemQuantity() const { return item_quantity; } void Inventory_Item::SetItemName(std::string name) { item_name = name; } void Inventory_Item::SetItemQuantity( int quantity) { item_quantity = quantity; } void Inventory_Item::Display() const {
  • 9. std::cout << item_name << " (" << item_quantity << ") "; } InventoryItem.h #ifndef InventoryItem_hpp #define InventoryItem_hpp #include <stdio.h> #include <string> class Inventory_Item { public : Inventory_Item(); Inventory_Item(std::string name, int quantity); ~Inventory_Item(); std::string GetItemName() const ; int GetItemQuantity() const ; void SetItemName(std::string); void SetItemQuantity( int ); virtual void Display() const ; protected : std::string item_name; int item_quantity; private : }; #endif /* InventoryItem_hpp */
  • 10. Product.cpp #include "Product.hpp" #include <iostream> #include <iomanip> Product::Product() : Inventory_Item(), product_id(0), product_price(0.0) { } Inventory_Item(), product_id(0), product_price(0.0){ } Product::Product(std::string name, int quantity) : Inventory_Item(name, quantity), product_id(rand()% 1000), product_price(100.0 * ((rand() + 1) / double (RAND_MAX + 2))){ } Product::~Product() { std::cout << "Product " << product_id << " priced $" << product_price << " has been destroyed."; } int Product::GetProductId() const { return product_id;
  • 11. } double Product::GetProductPrice() const { return product_price; } T_Condition Product::GetProductCondition() const { return condition_; } void Product::SetProductId( int id){ product_id = id; } void Product::SetProductPrice( double price) { product_price = price; } void Product::SetProductCondition(T_Condition condition) { condition_ = condition; } void Product::Display() const { Inventory_Item::Display(); std::cout << product_id << " $" << std::setprecision(4) << product_price << 'n'; } Product.h #ifndef Product_hpp #define Product_hpp
  • 12. #include "InventoryItem.hpp" #include <stdio.h> #include "Product.hpp" #include <string> typedef enum { PC_NEW, PC_USED, PC_REFURBISHED, PC_DEFECTIVE } T_Condition; class Product : public Inventory_Item { public : Product(); Product(std::string, int ); ~Product(); int GetProductId() const ; double GetProductPrice() const ; T_Condition GetProductCondition() const ; void SetProductId( int ); void SetProductPrice( double ); void SetProductCondition(T_Condition); virtual void Display() const ; private : T_Condition condition_; int product_id; double product_price; }; #endif /* Product_hpp */