The errors I am receiving before making the objects:
'getInFileS' was not declared in this scope| 'getInFileO' was not declared in this scope|
First line of each file has a number 100.
I thought I only needed to make objects to solve this issue such as:
Orders ord; Shipments ship;
ship.getInFileS(shipment, x, sFile); ord.getInFileO(order, x, oFile);
The errors I am receiving after making the objects:
undefined reference to Orders::Orders()'| undefined reference toShipments::Shipments()'| <-- line 172 undefined reference to `Shipments::Shipments()'| <-- line 192
I believe maybe I have made too many objects for Shipments and Orders. Am I using these default constructors right?
Thanks for everything!
Here is my code:
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <iomanip>
using namespace std;
struct Total{
int dollars;
int cents;
};
struct Date{
int day;
int month;
int year;
};
struct SizeOfBox{
int length;
int width;
int height;
};
struct Orders{
string nameOrd; /// Name of customer (small business)
string nameItem; /// Name of item needed
int numBox; /// Number of boxes
Total total; /// Total cost (dollar.cent)
Date ordDate; /// Date (month:day:year) order is placed
/// Member functions orders
bool compareDateHP(); /// Compare by date, if same, then by highest price
void displayInFileO(Orders order[], int x);
void getInFileO(Orders order[], int x, ifstream& inFile);
/// Default constructor for orders
Orders();
};
struct Shipments{
string food; /// Name of food item
Date expDate; /// Expiration date (month:day:year)
SizeOfBox sizeBox; /// Dimensions of the box (length:width:height) in inches
int weight; /// Weight of the box in pounds
char bStorageM; /// Best Storage Method (refrigerate “R”, freeze “F”, do not refrigerate “D”)
Date recDate; /// Date (month:day:year) received
Total price; /// Price (dollar.cent)
/// Member functions for shipments
bool compareEDate(); /// Compare by expiration date
void displayInFileS(Shipments shipment[], int x);
void getInFileS(Shipments shipment[], int x, ifstream& inFile);
/// Default constructor for Shipments
Shipments();
};
/// Using scope resolution operator, :: to access data types in the struct
void Orders::getInFileO(Orders order[], int x, ifstream& inFile){
char decimal;
for(int i = 0; i < x; i++){
inFile >> order[i].nameOrd;
inFile >> order[i].nameItem;
inFile >> order[i].numBox;
inFile >> order[i].total.dollars >> order[i].total.cents;
inFile >> order[i].ordDate.month >> decimal >> order[i].ordDate.day >> decimal >> order[i].ordDate.year;
}
inFile.close();
//printHeading("Orders", 60);
displayInFileO(order, x);
};
bool Orders::compareDateHP(){
return true;
};
void Orders::displayInFileO(Orders order[], int x){
cout << setw(10) << setfill(' ') << "Customer Name" << " | "
<< "Item Name" << " | "
<< "#Boxes" << " | "
<< "Cost" << " | "
<< "Order Date" << endl;
//printHorizontalLine(60,'-');
for(int i = 0; i < x; i++){
cout << left << setw(10) << order[i].nameOrd << " | "
<< left << setw(10) << order[i].nameItem << " | "
<< right << setw(2) << setfill('0') << order[i].numBox << " | "
<< left << setw(4) << setfill('0') << order[i].total.dollars << "." << order[i].total.cents<< " | "
<< right << setw(2) << setfill('0') << order[i].ordDate.month <<":" << setw(2) << setfill('0')
<< order[i].ordDate.day <<":" << setw(2) << setfill('0') << order[i].ordDate.year << " "
<< setfill(' ') << endl;
}
};
void Shipments::getInFileS(Shipments shipment[], int x, ifstream& inFile){
char decimal;
for(int i = 0; i < x; i++){
inFile >> shipment[i].food;
inFile >> shipment[i].expDate.month >> decimal >> shipment[i].expDate.day >> decimal >> shipment[i].expDate.year;
inFile >> shipment[i].sizeBox.length >> decimal >> shipment[i].sizeBox.width >> decimal >> shipment[i].sizeBox.height;
inFile >> shipment[i].weight;
inFile >> shipment[i].bStorageM;
inFile >> shipment[i].recDate.month >> decimal >> shipment[i].recDate.day >> decimal >> shipment[i].recDate.year;
inFile >> shipment[i].price.dollars >> decimal >> shipment[i].price.cents;
}
inFile.close();
//printHeading("Shipments", 80);
displayInFileS(shipment,x);
};
bool Shipments::compareEDate(){
return true;
};
void Shipments::displayInFileS(Shipments shipment[], int x){
cout << setw(10) << "Food Item" << " | "
<< "Exp Date " << " | "
<< "Box Size" << " | "
<< "Weight" << " | "
<< "Storage" << " | "
<< "Received date" << " | "
<< "Price" << endl;
//printHorizontalLine(80,'-');
for(int i = 0; i < x; i++){
cout << left << setw(9) << shipment[i].food << " | "
<< right <<setw(2) << setfill('0') << shipment[i].expDate.month <<":" << setw(2) << setfill('0')
<< shipment[i].expDate.day <<":" << setw(2) << setfill('0') << shipment[i].expDate.year << " | "
<< right <<setw(2) << setfill('0') << shipment[i].sizeBox.length <<":"<< setw(2) << setfill('0')
<< shipment[i].sizeBox.width << ":" << setw(2) << setfill('0') <<shipment[i].sizeBox.height << " | "
<< right <<setw(2) << shipment[i].weight << " | "
<< right <<shipment[i].bStorageM << " | "
<< right <<setw(2) << setfill('0') << shipment[i].recDate.month <<":" << setw(2) << setfill('0')
<< shipment[i].recDate.day <<":" << setw(2) << setfill('0') << shipment[i].recDate.year << " | "
<< right << fixed << setprecision(2) << setfill('0') << shipment[i].price.dollars << "." << shipment[i].price.cents<< " "
<< setfill(' ') << endl;
cout.unsetf(ios_base::fixed);
}
};
/// int main!
int main(){
int x = 0;
ifstream oFile;
ifstream sFile;
oFile.open("Orders.txt");
sFile.open("Shipments.txt");
if (!oFile)
{
cout << "The Orders input file does not exist. Program terminates!" << endl;
return 1;
}
if (!sFile)
{
cout << "The Shipments input file does not exist. Program terminates!" << endl;
return 1;
}
oFile >> x;
sFile >> x;
Shipments shipment[x];
Orders order[x];
gship.etInFileS(shipment, x, sFile);
getInFileO(order, x, oFile);
return 0;
}
Aucun commentaire:
Enregistrer un commentaire