I can figure out what is the problem with this code : here is the program and th
ID: 3623516 • Letter: I
Question
I can figure out what is the problem with this code : here is the program and the error...the error is : inlab7b.cc:23: error: printStore() was not declared in this scope
//File: storeClassb.h
//
//This is the specification file for a store class.
//Each store contains data members that contain
//information about chairs and tables sold by the store
//as well as the name of the store.
#include <string>
using namespace std;
//prevent multiple inclusions
#ifndef STORE_CLASS_H
#define STORE_CLASS_H
class StoreClass
{
public:
//Read the data for a store from a file. The name of the
//file is passed as an argument to this method
void readFile (string filename);
//print information about the store
void printStore();
//You should define 3 printStore overloaded functions:
//One printStore requires a string as a parameter.
//One printStore requires an integer as a parameter.
//One printStore requires both an integer and a string
//as a parameter.
void printStore(string s);
void printStore(int a);
void printStore(string s,int a);
private:
//define a struct for a Chair type
struct Chair
{
string designer; //chair designer's name
bool cushion; //does it have a cushion
string material; //type of material used in the chair
string color; //color of the chair
int qty; //quantity of this chair
};
//define a struct for a Table type
struct Table
{
string designer; //table designer's name
bool glass; //does the chair have glass
string material; //type of material used in the table
string color; //table's color
int qty; //quantity of this table
};
//data members in the store
Chair chairArray[100]; //the store contains many chairs
Table tableArray[100]; //and many tables
int totalTables; //number of tables
int totalChairs; //number of chairs
string storeName; //name of the store
};
#endif
/////////////////////////////////////////////////////////////////
//File: storeClassb.cc
//
//This is the implementation file for a store class.
//Each store contains data members that contain
//information about chairs and tables sold by the store
//as well as the name of the store.
#include "storeClassb.h"
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
//This method receives the name of the file containig
//store data. It reads all data about the store.
//The data file contains the name of the store followed
//by information about chairs and tables. If a chair's
//information appears in the file, it is preceeded by
//the string "Chair". If a table's information appears
//in the file, it is preceeded by the string "Table".
void StoreClass::readFile(string filename)
{
string input; //input a string from the file
ifstream myFile; //input file stream
totalChairs = 0; //set the chair counter to 0
totalTables = 0; //set the table counter to 0
//open the data file & check to make sure it opened
myFile.open(filename.c_str());
if (!myFile)
{
cerr << "Data file failed to open! ";
exit (0);
}
//read the store's name
myFile >> input;
//check for an empty file
if(input!="")
{
//set the store's name
storeName = input;
//read in chairs & tables until end-of-file
//read the type of the next item
myFile >> input;
while(myFile)
{
//the next item is a chair
if(input == "Chair")
{
//create a Chair object and fill it with data
Chair chair1;
myFile >> chair1.designer;
myFile >> chair1.color;
myFile >> chair1.material;
//read a string to indicate whether the chair
//has a cushion or not
myFile >> input;
if(input == "true")
{
chair1.cushion = true;
}
else
chair1.cushion = false;
myFile >> chair1.qty;
//place the chair into the array of chairs
chairArray[totalChairs] = chair1;
totalChairs +=1;
}
//the next item is a table
else if(input == "Table")
{
//create a Table object and fill it with data
Table table1;
myFile >> table1.designer;
myFile >> table1.color;
myFile >> table1.material;
//read a string to indicate whether the table
//has glass or not
myFile >> input;
if(input == "true")
{
table1.glass = true;
}
else
table1.glass = false;
myFile >> table1.qty;
//place the chair into the array of tables
tableArray[totalTables] = table1;
totalTables+=1;
}
//read the type of the next item
myFile >> input;
}
}
}
//This method prints all information about all tables
//and chairs in the store.
void StoreClass::printStore()
{
//print all information about Chairs sold by
//the store
if (totalChairs > 0)
cout << "Inventory of Chairs" << endl;
else
cout << "No chairs in Inventory" << endl;
for(int i = 0; i < totalChairs; i++)
{
cout << chairArray[i].designer <<" ";
cout << chairArray[i].color << " ";
cout << chairArray[i].material << " ";
if(chairArray[i].cushion == true)
cout << "Cushioned " <<endl;
else
cout << "Not Cushioned " << endl;
cout << "Qty in Stock: " << chairArray[i].qty << endl;
}
//print all information about Tables sold by
//the store
if (totalTables > 0)
cout << " Inventory of Tables" << endl;
else
cout << " No tables in Inventory" << endl;
for(int i = 0; i < totalTables; i++)
{
cout << tableArray[i].designer <<" ";
cout << tableArray[i].color << " ";
cout << tableArray[i].material << " ";
if(tableArray[i].glass == true)
cout << "Glass Top " <<endl;
else
cout << "No Glass Top " << endl;
cout << "Qty in Stock: " << tableArray[i].qty << endl;
}
}
//This method receives the type of product that the user
//wishes information about. All products of that type
//are printed.
void StoreClass::printStore(string type)
{
//if the type was "Chair", then print all inventory
//pertaining to chairs
if(type == "Chair")
{
if (totalChairs > 0)
cout << "Inventory of Chairs" << endl;
else
cout << "No chairs in Inventory" << endl;
for(int i = 0; i < totalChairs; i++)
{
cout << chairArray[i].designer <<" ";
cout << chairArray[i].color << " ";
cout << chairArray[i].material << " ";
if(chairArray[i].cushion == true)
cout << "Cushioned " <<endl;
else
cout << "Not Cushioned " << endl;
cout << "Qty in Stock: " << chairArray[i].qty << endl;
}
}
else if (type == "Table")
{
if (totalTables > 0)
cout << " Inventory of Tables" << endl;
else
cout << " No tables in Inventory" << endl;
for(int i = 0; i< totalTables; i++)
{
cout << tableArray[i].designer <<" ";
cout << tableArray[i].color << " ";
cout << tableArray[i].material << " ";
if(tableArray[i].glass == true)
cout << "Glass Top " <<endl;
else
cout << "No Glass Top " << endl;
cout << "Qty in Stock: " << tableArray[i].qty << endl;
}
}
}
//This method receives the type of product that the user
//wishes information about. It also receives an integer
//quantity and prints all items of the given type that
//need to be reordered. An item needs to be reordered
//if the store contains a quantity of that item less than
//the quantity received.
void StoreClass::printStore(string type,int qty)
{
//int count = 0;
string temp = "";
//if the type desired is a Chair
if(type == "Chair")
{
cout << "Chairs to be Re-Ordered: " << endl;
for(int i =0; i < totalChairs; i++)
{
//if a chair needs to be reordered print it
if(chairArray[i].qty < qty)
{
cout << chairArray[i].designer <<" ";
cout << chairArray[i].color << " ";
cout << chairArray[i].material << " ";
if(chairArray[i].cushion == true)
cout << "Cushioned " <<endl;
else
cout << "Not Cushioned " << endl;
cout << "Qty in Stock: " << chairArray[i].qty << endl;
}
}
}
//if the type desired is a table
else if(type == "Table")
{
cout << "Tables to be Re-Ordered" << endl;
temp = tableArray[0].designer;
for(int i =0;i<totalTables;i++)
{
//if a table needs to be reordered print it
if(tableArray[i].qty < qty)
{
cout << tableArray[i].designer <<" ";
cout << tableArray[i].color << " ";
cout << tableArray[i].material << " ";
if(tableArray[i].glass == true)
cout << "Glass Top " <<endl;
else
cout << "No Glass Top " << endl;
cout << "Qty in Stock: " << tableArray[i].qty << endl;
}
}
}
}
//This method receives an integer quantity and prints
//all items that need to be reordered. An item needs to be
//reordered if the store contains a quantity of that item
//less than the quantity received.
void StoreClass::printStore(int qty)
{
//print all chairs that need to be reordered
cout << "Chairs to be Re-Ordered" << endl;
for(int i =0;i<totalChairs;i++)
{
if(chairArray[i].qty < qty)
{
cout << chairArray[i].designer <<" ";
cout << chairArray[i].color << " ";
cout << chairArray[i].material << " ";
if(chairArray[i].cushion == true)
cout << "Cushioned " <<endl;
else
cout << "Not Cushioned " << endl;
cout << "Qty in Stock: " << chairArray[i].qty << endl;
}
}
//print all tables that need to be reordered
cout << " Tables to be Re-Ordered" << endl;
for(int i =0;i<totalTables;i++)
{
if(tableArray[i].qty < qty)
{
cout << tableArray[i].designer <<" ";
cout << tableArray[i].color << " ";
cout << tableArray[i].material << " ";
if(tableArray[i].glass == true)
cout << "Glass Top " <<endl;
else
cout << "No Glass Top " << endl;
cout << "Qty in Stock: " << tableArray[i].qty << endl;
}
}
}
//////////////////////////////////////////////////////////////
//File: inlab7b.cc
//
//This is a simple test program to test the
//store class.
#include "storeClassb.h"
#include <iostream>
using namespace std;
int main()
{
//create an instance of the store class
StoreClass store1;
//read in informaton about the store
store1.readFile ("ex3_data.0");
//print all information about "tables" sold by
//the store. Place the activation below
printStore();
//print all information about "chairs" with a
//quantity < 7. Place the activation below
cout << endl << endl;
printStore(n);
//print all products sold by the store with a
//quantity < 19. Place the activation below
cout << endl << endl;
printStore(s,a);
return 0;
}
Explanation / Answer
please rate - thanks
without the data file I wasn't able to test it, but here are the corrections (see the red at the bottom)
I think you'll understand the problem when you see the solution
//File: storeClassb.h
//
//This is the specification file for a store class.
//Each store contains data members that contain
//information about chairs and tables sold by the store
//as well as the name of the store.
#include <string>
using namespace std;
//prevent multiple inclusions
#ifndef STORE_CLASS_H
#define STORE_CLASS_H
class StoreClass
{
public:
//Read the data for a store from a file. The name of the
//file is passed as an argument to this method
void readFile (string filename);
//print information about the store
void printStore();
//You should define 3 printStore overloaded functions:
//One printStore requires a string as a parameter.
//One printStore requires an integer as a parameter.
//One printStore requires both an integer and a string
//as a parameter.
void printStore(string s);
void printStore(int a);
void printStore(string s,int a);
private:
//define a struct for a Chair type
struct Chair
{
string designer; //chair designer's name
bool cushion; //does it have a cushion
string material; //type of material used in the chair
string color; //color of the chair
int qty; //quantity of this chair
};
//define a struct for a Table type
struct Table
{
string designer; //table designer's name
bool glass; //does the chair have glass
string material; //type of material used in the table
string color; //table's color
int qty; //quantity of this table
};
//data members in the store
Chair chairArray[100]; //the store contains many chairs
Table tableArray[100]; //and many tables
int totalTables; //number of tables
int totalChairs; //number of chairs
string storeName; //name of the store
};
#endif
/////////////////////////////////////////////////////////////////
//File: storeClassb.cc
//
//This is the implementation file for a store class.
//Each store contains data members that contain
//information about chairs and tables sold by the store
//as well as the name of the store.
#include "storeClassb.h"
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
//This method receives the name of the file containig
//store data. It reads all data about the store.
//The data file contains the name of the store followed
//by information about chairs and tables. If a chair's
//information appears in the file, it is preceeded by
//the string "Chair". If a table's information appears
//in the file, it is preceeded by the string "Table".
void StoreClass::readFile(string filename)
{
string input; //input a string from the file
ifstream myFile; //input file stream
totalChairs = 0; //set the chair counter to 0
totalTables = 0; //set the table counter to 0
//open the data file & check to make sure it opened
myFile.open(filename.c_str());
if (!myFile)
{
cerr << "Data file failed to open! ";
exit (0);
}
//read the store's name
myFile >> input;
//check for an empty file
if(input!="")
{
//set the store's name
storeName = input;
//read in chairs & tables until end-of-file
//read the type of the next item
myFile >> input;
while(myFile)
{
//the next item is a chair
if(input == "Chair")
{
//create a Chair object and fill it with data
Chair chair1;
myFile >> chair1.designer;
myFile >> chair1.color;
myFile >> chair1.material;
//read a string to indicate whether the chair
//has a cushion or not
myFile >> input;
if(input == "true")
{
chair1.cushion = true;
}
else
chair1.cushion = false;
myFile >> chair1.qty;
//place the chair into the array of chairs
chairArray[totalChairs] = chair1;
totalChairs +=1;
}
//the next item is a table
else if(input == "Table")
{
//create a Table object and fill it with data
Table table1;
myFile >> table1.designer;
myFile >> table1.color;
myFile >> table1.material;
//read a string to indicate whether the table
//has glass or not
myFile >> input;
if(input == "true")
{
table1.glass = true;
}
else
table1.glass = false;
myFile >> table1.qty;
//place the chair into the array of tables
tableArray[totalTables] = table1;
totalTables+=1;
}
//read the type of the next item
myFile >> input;
}
}
}
//This method prints all information about all tables
//and chairs in the store.
void StoreClass::printStore()
{
//print all information about Chairs sold by
//the store
if (totalChairs > 0)
cout << "Inventory of Chairs" << endl;
else
cout << "No chairs in Inventory" << endl;
for(int i = 0; i < totalChairs; i++)
{
cout << chairArray[i].designer <<" ";
cout << chairArray[i].color << " ";
cout << chairArray[i].material << " ";
if(chairArray[i].cushion == true)
cout << "Cushioned " <<endl;
else
cout << "Not Cushioned " << endl;
cout << "Qty in Stock: " << chairArray[i].qty << endl;
}
//print all information about Tables sold by
//the store
if (totalTables > 0)
cout << " Inventory of Tables" << endl;
else
cout << " No tables in Inventory" << endl;
for(int i = 0; i < totalTables; i++)
{
cout << tableArray[i].designer <<" ";
cout << tableArray[i].color << " ";
cout << tableArray[i].material << " ";
if(tableArray[i].glass == true)
cout << "Glass Top " <<endl;
else
cout << "No Glass Top " << endl;
cout << "Qty in Stock: " << tableArray[i].qty << endl;
}
}
//This method receives the type of product that the user
//wishes information about. All products of that type
//are printed.
void StoreClass::printStore(string type)
{
//if the type was "Chair", then print all inventory
//pertaining to chairs
if(type == "Chair")
{
if (totalChairs > 0)
cout << "Inventory of Chairs" << endl;
else
cout << "No chairs in Inventory" << endl;
for(int i = 0; i < totalChairs; i++)
{
cout << chairArray[i].designer <<" ";
cout << chairArray[i].color << " ";
cout << chairArray[i].material << " ";
if(chairArray[i].cushion == true)
cout << "Cushioned " <<endl;
else
cout << "Not Cushioned " << endl;
cout << "Qty in Stock: " << chairArray[i].qty << endl;
}
}
else if (type == "Table")
{
if (totalTables > 0)
cout << " Inventory of Tables" << endl;
else
cout << " No tables in Inventory" << endl;
for(int i = 0; i< totalTables; i++)
{
cout << tableArray[i].designer <<" ";
cout << tableArray[i].color << " ";
cout << tableArray[i].material << " ";
if(tableArray[i].glass == true)
cout << "Glass Top " <<endl;
else
cout << "No Glass Top " << endl;
cout << "Qty in Stock: " << tableArray[i].qty << endl;
}
}
}
//This method receives the type of product that the user
//wishes information about. It also receives an integer
//quantity and prints all items of the given type that
//need to be reordered. An item needs to be reordered
//if the store contains a quantity of that item less than
//the quantity received.
void StoreClass::printStore(string type,int qty)
{
//int count = 0;
string temp = "";
//if the type desired is a Chair
if(type == "Chair")
{
cout << "Chairs to be Re-Ordered: " << endl;
for(int i =0; i < totalChairs; i++)
{
//if a chair needs to be reordered print it
if(chairArray[i].qty < qty)
{
cout << chairArray[i].designer <<" ";
cout << chairArray[i].color << " ";
cout << chairArray[i].material << " ";
if(chairArray[i].cushion == true)
cout << "Cushioned " <<endl;
else
cout << "Not Cushioned " << endl;
cout << "Qty in Stock: " << chairArray[i].qty << endl;
}
}
}
//if the type desired is a table
else if(type == "Table")
{
cout << "Tables to be Re-Ordered" << endl;
temp = tableArray[0].designer;
for(int i =0;i<totalTables;i++)
{
//if a table needs to be reordered print it
if(tableArray[i].qty < qty)
{
cout << tableArray[i].designer <<" ";
cout << tableArray[i].color << " ";
cout << tableArray[i].material << " ";
if(tableArray[i].glass == true)
cout << "Glass Top " <<endl;
else
cout << "No Glass Top " << endl;
cout << "Qty in Stock: " << tableArray[i].qty << endl;
}
}
}
}
//This method receives an integer quantity and prints
//all items that need to be reordered. An item needs to be
//reordered if the store contains a quantity of that item
//less than the quantity received.
void StoreClass::printStore(int qty)
{
//print all chairs that need to be reordered
cout << "Chairs to be Re-Ordered" << endl;
for(int i =0;i<totalChairs;i++)
{
if(chairArray[i].qty < qty)
{
cout << chairArray[i].designer <<" ";
cout << chairArray[i].color << " ";
cout << chairArray[i].material << " ";
if(chairArray[i].cushion == true)
cout << "Cushioned " <<endl;
else
cout << "Not Cushioned " << endl;
cout << "Qty in Stock: " << chairArray[i].qty << endl;
}
}
//print all tables that need to be reordered
cout << " Tables to be Re-Ordered" << endl;
for(int i =0;i<totalTables;i++)
{
if(tableArray[i].qty < qty)
{
cout << tableArray[i].designer <<" ";
cout << tableArray[i].color << " ";
cout << tableArray[i].material << " ";
if(tableArray[i].glass == true)
cout << "Glass Top " <<endl;
else
cout << "No Glass Top " << endl;
cout << "Qty in Stock: " << tableArray[i].qty << endl;
}
}
}
//////////////////////////////////////////////////////////////
//File: inlab7b.cc
//
//This is a simple test program to test the
//store class.
#include <iostream>
using namespace std;
int main()
{
//create an instance of the store class
StoreClass store1;
//read in informaton about the store
store1.readFile ("ex3_data.0");
//print all information about "tables" sold by
//the store. Place the activation below
store1.printStore();
//print all information about "chairs" with a
//quantity < 7. Place the activation below
cout << endl << endl;
int n=7;
store1.printStore(n);
//print all products sold by the store with a
//quantity < 19. Place the activation below
cout << endl << endl;
int a=19;
string s="tables";
store1.printStore(s,a);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.