Question

Please help fix my code C++, I get 2 errors when running. The code should be...

Please help fix my code C++, I get 2 errors when running. The code should be able to open this file:

labdata.txt

Pallet PAG PAG45982IB 737 4978 OAK
Container AYF AYF23409AA 737 2209 LAS
Container AAA AAA89023DL 737 5932 DFW

Here is my code:


#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <cstdlib>
#include <iomanip>

using namespace std;

const int MAXLOAD737 = 46000;
const int MAXLOAD767 = 116000;

class Cargo
{

protected:
string uldtype;
string abbreviation;
string uldid;
int aircraft;
double weight;
string destination;
  
public:

Cargo();

Cargo(const string &uldtype, const string &abbreviation, const string &uldid, const int &aircraft, const double &weight, const string &destination);
  
Cargo(const Cargo &unit);
  
~Cargo();
  
void setuldtype(string);
void setabbreviation(string);
void setuldid(string);
void setaircraft(int);
void setweight(double);
void setdestination(string);
  
string getuldtype() const;
string getabbreviation() const;
string getuldid() const;
int getaircraft() const;
double getweight() const;
string getdestination() const;
  
virtual bool maxweight(int)
{
return 0;
}
  
void output(Cargo &plunit);
};


class Boeing737 : public Cargo
{
private:

public:
Boeing737()
{}
Boeing737(const Cargo &unit) : Cargo(unit)
{}
Boeing737(const string &uldtype, const string &abbreviation, const string &uldid, const int &aircraft, const double &weight, const string &destination);
  
void output(Boeing737 &plunit)
{}
  
~Boeing737()
{}
  
bool maxweight(int total) const;
};


class Boeing767 :: public Cargo
{

private:

public:
Boeing767() :: Cargo()
{}
  
Boeing767(const Cargo &unit) : Cargo(unit)
{}
  
Boeing767(const string &uldtype, const string &abbreviation, const string, const string &uldid, const int &aircraft, const double &weight, const string &destination);

~Boeing767()
{}

bool maxweight(int total);
};

void load737(const string tttt, const string abrv, const string id, const int craft, const double wt,
const string dest);

void load767(const string tttt, const string abrv, const string id, const int craft,
const double wt, const string dest);

void input();

void vecprint(vector <Boeing737> &vec737, vector <Boeing767> &vec767);

int main()
{
input();
return 0;
}

Cargo::Cargo()
{
uldtype = "XXX";
abbreviation = " ";
uldid = "xxxxxIB";
aircraft = 700;
weight = 0.0;
destination = "NONE";
}

Cargo::Cargo(const string &uld, const string &abrv, const string &id,
const int &craft, const double &wt, const string &dest)
{
uldtype = uld;
abbreviation = abrv;
uldid = id;
aircraft = craft;
weight = wt;
destination = dest;
}   

Cargo::Cargo(const Cargo &unit1)
{
uldtype = unit1.uldtype;
abbreviation = unit1.abbreviation;
uldid = unit1.uldid;
aircraft = unit1.weight;
weight = unit1.weight;
destination = unit1.destination;
}

Cargo::~Cargo()
{
cout << "Cargo destructor called\n\n";
}

void Cargo::setuldtype(string type)
{
uldtype = type;
}

void Cargo::setabbreviation(string abrv)
{
abbreviation = abrv;
}

void Cargo::setuldid(string id)
{
uldid = id;
}

void Cargo::setaircraft(int air)
{
aircraft = air;
}

void Cargo::setweight(double wt)
{
weight = wt;
}

void Cargo::setdestination(string dest)
{
destination = dest;
}

string Cargo::getuldtype() const
{
return uldtype;
}

string Cargo::getabbreviation() const
{
return abbreviation;
}

string Cargo::getuldid() const
{
return uldid;
}

int Cargo::getaircraft() const
{
return aircraft;
}

double Cargo::getweight() const
{
return weight;
}

string Cargo::getdestination() const
{
return destination;
}

Boeing737::Boeing737(const string &uld, const string &abrv, const string &id, const int &craft, const double &wt, const string &dest)
{
uldtype = uld;
abbreviation = abrv;
uldid = id;
aircraft = craft;
weight = wt;
destination = dest;
}
bool Boeing737::maxweight(int total) const
{
return total < MAXLOAD737;
}

Boeing767::Boeing767(const string &uld, const string &abrv, const string &id, const int &craft, const double &wt, const string &dest)
{
uldtype = uld;
abbreviation == abrv;
uldid = id;
aircraft = craft;
weight = wt;
destination = dest;
}
bool Boeing767::maxweight(int total)
{
return total < MAXLOAD767;
}

void load737(vector<Boeing737> &vec737, const string tttt, const string abrv, const string id, const int craft, const double wt, const string dest,
int &total737wt)
{
total737wt = total737wt + wt;
Boeing737 plane(tttt, abrv, id, craft, wt, dest);
if (plane.maxweight(total737wt))
{
vec737.push_back(plane);
}
else
{
total737wt = total737wt - wt;
cout << "noncomply\n";
}
}
  
void load767(vector <Boeing767> &vec767, const string tttt, const string abrv, const string id, const int craft, const double wt, const string dest,
int &total767wt)
  
{
Boeing767 plane (tttt, abrv, id, craft, wt, dest);
if (plane.maxweight(total767wt))
{
vec767.push_back(plane);
}
else
{
total767wt = total767wt - wt;
cout << "noncomply\n";
}
}
  
void Cargo::output(Cargo &plunit)
{
cout << fixed << showpoint << setprecision(2);
cout << setw(19) << "Unit load type: " << uldtype << endl;
cout << setw(19) << "Unit abbreviation: " << abbreviation << endl;
cout << setw(19) << "Unit identifier: " << uldid << endl;
cout << setw(19) << "Aircraft type: " << aircraft << endl;
cout << setw(19) << "Unit weight: " << weight << " pounds" << endl;
cout << setw(19) << "Destination code: " << destination << endl;
}
void input()
{
string type;
string abrv;
string id;
int air;
double wt;
string dest;
int total737wt = 0;
int total767wt = 0;
vector<Boeing737> vecptr737;
vector<Boeing767> vecptr767;
ifstream inputFile;
  
if(!inputFile)
{
std::cerr <<"Error opening the file"<<endl;
exit(99);
}
while (inputFile >> type)
{
inputFile >> abrv;
inputFile >> id;
inputFile >> air;
inputFile >> wt;
inputFile >> dest;
if (air==737)
{
load737(vecptr737, type, abrv, id, air, wt, dest, total737wt);
}
else if (air == 767)
{
load767(vecptr767,type, abrv, id, air, wt, dest, total767wt);
}
else
cout << "Unknown aircraft type\n";
}
inputFile.close();
  
for(int i = 0; i < vecptr737.size(); i++)
{
cout << "737 unit #" << i + 1 << endl;
cout << fixed << showpoint << setprecision(2);
cout << setw(19) << "Unit load type: " << vecptr737[i].getuldtype() << endl;
cout << setw(19) << "Unit abbreviation: " << vecptr737[i].getabbreviation() << endl;
cout << setw(19) << "Unit identifier: " << vecptr737[i].getuldid() << endl;
cout << setw(19) << "Aircraft type: " << vecptr737[i].getaircraft() << endl;
cout << setw(19) << "Unit weight: " << vecptr737[i].getweight() << " pounds" << endl;
cout << setw(19) << "Destination code: " << vecptr737[i].getdestination()<< endl;
}
  
for(int i = 0; i < vecptr767.size(); i++)
{
cout << "767 unit #" << i + 1 << endl;
cout << fixed << showpoint << setprecision(2);
cout << setw(19) << "Unit load type: " << vecptr767[i].getuldtype() << endl;
cout << setw(19) << "Unit abbreviation: " << vecptr767[i].getabbreviation() << endl;
cout << setw(19) << "Unit identifier: " << vecptr767[i].getuldid() << endl;
cout << setw(19) << "Aircraft type: " << vecptr767[i].getaircraft() << endl;
cout << setw(19) << "Unit weight: " << vecptr767[i].getweight() << " pounds" << endl;
cout << setw(19) << "Destination code: " << vecptr767[i].getdestination()<< endl;
}
}
  
  

0 0
Add a comment Improve this question Transcribed image text
Answer #1
  • In the line class Boeing737 :: public Cargo single : must be used to inherit cargo , not ::
  • in the line Boeing767() :: Cargo() use single : instead of ::
  • In the line Boeing767(const string &uldtype, const string &abbreviation, const string, const string &uldid, const int &aircraft, const double &weight, const string &destination); The underlined part is redundant, it is not present in the definition of this constructor, so remove it.
  • In the input() function, file in not being opened , so change the ifstream inputFile; to ifstream inputFile("labdata.txt");

Modified program:

#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <cstdlib>
#include <iomanip>

using namespace std;

const int MAXLOAD737 = 46000;
const int MAXLOAD767 = 116000;

class Cargo
{

protected:
string uldtype;
string abbreviation;
string uldid;
int aircraft;
double weight;
string destination;
  
public:

Cargo();

Cargo(const string &uldtype, const string &abbreviation, const string &uldid, const int &aircraft, const double &weight, const string &destination);
  
Cargo(const Cargo &unit);
  
~Cargo();
  
void setuldtype(string);
void setabbreviation(string);
void setuldid(string);
void setaircraft(int);
void setweight(double);
void setdestination(string);
  
string getuldtype() const;
string getabbreviation() const;
string getuldid() const;
int getaircraft() const;
double getweight() const;
string getdestination() const;
  
virtual bool maxweight(int)
{
return 0;
}
  
void output(Cargo &plunit);
};


class Boeing737 : public Cargo
{
private:

public:
Boeing737() : Cargo()
{}
Boeing737(const Cargo &unit) : Cargo(unit)
{}
Boeing737(const string &uldtype, const string &abbreviation, const string &uldid, const int &aircraft, const double &weight, const string &destination);
  
void output(Boeing737 &plunit)
{}
  
~Boeing737()
{}
  
bool maxweight(int total) const;
};


class Boeing767 : public Cargo
{

private:

public:
Boeing767() : Cargo()
{}
  
Boeing767(const Cargo &unit) : Cargo(unit)
{}
  
Boeing767(const string &uldtype, const string &abbreviation, const string &uldid, const int &aircraft, const double &weight, const string &destination);

~Boeing767()
{}

bool maxweight(int total);
};

void load737(const string tttt, const string abrv, const string id, const int craft, const double wt,
const string dest);

void load767(const string tttt, const string abrv, const string id, const int craft,
const double wt, const string dest);

void input();

void vecprint(vector <Boeing737> &vec737, vector <Boeing767> &vec767);

int main()
{
input();
return 0;
}

Cargo::Cargo()
{
uldtype = "XXX";
abbreviation = " ";
uldid = "xxxxxIB";
aircraft = 700;
weight = 0.0;
destination = "NONE";
}

Cargo::Cargo(const string &uld, const string &abrv, const string &id,
const int &craft, const double &wt, const string &dest)
{
uldtype = uld;
abbreviation = abrv;
uldid = id;
aircraft = craft;
weight = wt;
destination = dest;
}   

Cargo::Cargo(const Cargo &unit1)
{
uldtype = unit1.uldtype;
abbreviation = unit1.abbreviation;
uldid = unit1.uldid;
aircraft = unit1.weight;
weight = unit1.weight;
destination = unit1.destination;
}

Cargo::~Cargo()
{
cout << "Cargo destructor called\n\n";
}

void Cargo::setuldtype(string type)
{
uldtype = type;
}

void Cargo::setabbreviation(string abrv)
{
abbreviation = abrv;
}

void Cargo::setuldid(string id)
{
uldid = id;
}

void Cargo::setaircraft(int air)
{
aircraft = air;
}

void Cargo::setweight(double wt)
{
weight = wt;
}

void Cargo::setdestination(string dest)
{
destination = dest;
}

string Cargo::getuldtype() const
{
return uldtype;
}

string Cargo::getabbreviation() const
{
return abbreviation;
}

string Cargo::getuldid() const
{
return uldid;
}

int Cargo::getaircraft() const
{
return aircraft;
}

double Cargo::getweight() const
{
return weight;
}

string Cargo::getdestination() const
{
return destination;
}

Boeing737::Boeing737(const string &uld, const string &abrv, const string &id, const int &craft, const double &wt, const string &dest)
{
uldtype = uld;
abbreviation = abrv;
uldid = id;
aircraft = craft;
weight = wt;
destination = dest;
}
bool Boeing737::maxweight(int total) const
{
return total < MAXLOAD737;
}

Boeing767::Boeing767(const string &uld, const string &abrv, const string &id, const int &craft, const double &wt, const string &dest)
{
uldtype = uld;
abbreviation == abrv;
uldid = id;
aircraft = craft;
weight = wt;
destination = dest;
}
bool Boeing767::maxweight(int total)
{
return total < MAXLOAD767;
}

void load737(vector<Boeing737> &vec737, const string tttt, const string abrv, const string id, const int craft, const double wt, const string dest,
int &total737wt)
{
total737wt = total737wt + wt;
Boeing737 plane(tttt, abrv, id, craft, wt, dest);
if (plane.maxweight(total737wt))
{
vec737.push_back(plane);
}
else
{
total737wt = total737wt - wt;
cout << "noncomply\n";
}
}
  
void load767(vector <Boeing767> &vec767, const string tttt, const string abrv, const string id, const int craft, const double wt, const string dest,
int &total767wt)
  
{
Boeing767 plane (tttt, abrv, id, craft, wt, dest);
if (plane.maxweight(total767wt))
{
vec767.push_back(plane);
}
else
{
total767wt = total767wt - wt;
cout << "noncomply\n";
}
}
  
void Cargo::output(Cargo &plunit)
{
cout << fixed << showpoint << setprecision(2);
cout << setw(19) << "Unit load type: " << uldtype << endl;
cout << setw(19) << "Unit abbreviation: " << abbreviation << endl;
cout << setw(19) << "Unit identifier: " << uldid << endl;
cout << setw(19) << "Aircraft type: " << aircraft << endl;
cout << setw(19) << "Unit weight: " << weight << " pounds" << endl;
cout << setw(19) << "Destination code: " << destination << endl;
}
void input()
{
string type;
string abrv;
string id;
int air;
double wt;
string dest;
int total737wt = 0;
int total767wt = 0;
vector<Boeing737> vecptr737;
vector<Boeing767> vecptr767;
ifstream inputFile("labdata.txt");
  
if(!inputFile)
{
std::cerr <<"Error opening the file"<<endl;
exit(99);
}
while (inputFile >> type)
{
inputFile >> abrv;
inputFile >> id;
inputFile >> air;
cout<<air;
inputFile >> wt;
inputFile >> dest;
if (air==737)
{
load737(vecptr737, type, abrv, id, air, wt, dest, total737wt);
}
else if (air == 767)
{
load767(vecptr767,type, abrv, id, air, wt, dest, total767wt);
}
else
cout << "Unknown aircraft type\n";
}
inputFile.close();
for(int i = 0; i < vecptr737.size(); i++)
{
cout << "737 unit #" << i + 1 << endl;
cout << fixed << showpoint << setprecision(2);
cout << setw(19) << "Unit load type: " << vecptr737[i].getuldtype() << endl;
cout << setw(19) << "Unit abbreviation: " << vecptr737[i].getabbreviation() << endl;
cout << setw(19) << "Unit identifier: " << vecptr737[i].getuldid() << endl;
cout << setw(19) << "Aircraft type: " << vecptr737[i].getaircraft() << endl;
cout << setw(19) << "Unit weight: " << vecptr737[i].getweight() << " pounds" << endl;
cout << setw(19) << "Destination code: " << vecptr737[i].getdestination()<< endl;
}
  
for(int i = 0; i < vecptr767.size(); i++)
{
cout << "767 unit #" << i + 1 << endl;
cout << fixed << showpoint << setprecision(2);
cout << setw(19) << "Unit load type: " << vecptr767[i].getuldtype() << endl;
cout << setw(19) << "Unit abbreviation: " << vecptr767[i].getabbreviation() << endl;
cout << setw(19) << "Unit identifier: " << vecptr767[i].getuldid() << endl;
cout << setw(19) << "Aircraft type: " << vecptr767[i].getaircraft() << endl;
cout << setw(19) << "Unit weight: " << vecptr767[i].getweight() << " pounds" << endl;
cout << setw(19) << "Destination code: " << vecptr767[i].getdestination()<< endl;
}
}

output:
737Cargo destructor called 737Cargo destructor called Cargo destructor called 737Cargo destructor called Cargo destructor cal​​​​​​​

Add a comment
Know the answer?
Add Answer to:
Please help fix my code C++, I get 2 errors when running. The code should be...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Lab 5.1 C++ Utilizing the code from Lab 4.2, replace your Cargo class with a new...

    Lab 5.1 C++ Utilizing the code from Lab 4.2, replace your Cargo class with a new base class. This will be the base for two classes created through inheritance. The Cargo class will need to have virtual functions in order to have them redefined in the child classes. You will be able to use many parts of the new Cargo class in the child classes since they will have the same arguments/parameters and the same functionality. Child class one will...

  • Lab 4.1 Utilizing the code from Lab 3.2, add an overloaded operator == which will be...

    Lab 4.1 Utilizing the code from Lab 3.2, add an overloaded operator == which will be used to compare two objects to see if they are equal. For our purposes, two objects are equal if their abbreviation and uldid are the same. You’ll need to make your overloaded operator a friend of the Cargo class. Create a unit1 object and load it with this data: uld – Pallet abbreviation – PAG uldid – PAG32597IB aircraft - 737 weight – 3321...

  • Hi please help with c++ programming. This is my code. there's a syntax error. PLEASE FIX...

    Hi please help with c++ programming. This is my code. there's a syntax error. PLEASE FIX MY CODE instead of re-designing the program. Thanks /*    Description of problem: Introduction to Friends functions. Create objects in the stack (not on the heap) 3.1: Add a friend function, kilotopound, which will convert kilograms to pounds. 3.2: Add a copy constructor utilizing Lab 3.1 code. Copy the fist object using a copy constructor. Output the contents of both objects. */ #include <iostream>...

  • Please use my Lab 3.2 code for this assignment Lab 4.2 instruction Using the code from...

    Please use my Lab 3.2 code for this assignment Lab 4.2 instruction Using the code from lab 4.1, add the ability to read from a file. Modify the input function:       * Move the input function out of the Cargo class to just below the end of the Cargo class       * At the bottom of the input function, declare a Cargo object named         temp using the constructor that takes the six parameters.       * Use the Cargo output...

  • CIS 22B Lab 3 Itty Bitty Airfreight (IBA) Topics: Friend functions Copy constructor ----------------------------------------------------------------------------------------------------------------------------------------- Lab 3.1...

    CIS 22B Lab 3 Itty Bitty Airfreight (IBA) Topics: Friend functions Copy constructor ----------------------------------------------------------------------------------------------------------------------------------------- Lab 3.1 Utilizing Lab 2.2 code Create your objects in the stack (not on the heap). Add a friend function, kilotopound, which will convert kilograms to pounds. Change your weight mutator to ask whether weight is input in kilograms or pounds. If it is kilograms, call the friend function kilotopound to convert it to pounds and return pounds.There are 2.2 pounds in one kilogram. Create an...

  • I want to change this code and need help. I want the code to not use...

    I want to change this code and need help. I want the code to not use parallel arrays, but instead use one array of struct containing the data elements, String for first name, String for last name,Array of integers for five (5) test scores, Character for grade. If you have any idea help would be great. #include #include #include #include using namespace std; const int NUMBER_OF_ROWS = 10; //number of students const int NUMBER_OF_COLUMNS = 5; //number of scores void...

  • Hi there! I need to fix the errors that this code is giving me and also...

    Hi there! I need to fix the errors that this code is giving me and also I neet to make it look better. thank you! #include <iostream> #include <windows.h> #include <ctime> #include <cstdio> #include <fstream> // file stream #include <string> #include <cstring> using namespace std; const int N=10000; int *freq =new int [N]; int *duration=new int [N]; char const*filename="filename.txt"; int songLength(140); char MENU(); // SHOWS USER CHOICE void execute(const char command); void About(); void Save( int freq[],int duration[],int songLength); void...

  • Hi there. I tried to submit this before, but the copy/paste didn't copy my vectors correctly....

    Hi there. I tried to submit this before, but the copy/paste didn't copy my vectors correctly. Hello there. I am trying to implement the djikstras shortest path algorithm into my code in C++ with a vector of vectors. However, when I test I get an error "Exception thrown at 0x75FFC762 in graphMain.exe: Microsoft C++ exception: std::out_of_range at memory location 0x009CF26C" for line 115 in graph.cpp. Could you help me debug? I am so close! ----------------------------FILE NAME: pch.h--------------------------------------- // pch.cpp: source...

  • Can anyone help me with this one? I really appreciate it! Find and fix errors and...

    Can anyone help me with this one? I really appreciate it! Find and fix errors and Simplify the createGroups() function using only one loop instead of two #include using namespace std; const double NO_STU = 40; void createGroups(const string myClass[], int no_stu, string group1, string group2); void printList(const string [], int); int main() { int no_stu = 8; string myClass[NO_STU] = { "Linda", "Bob", "Mary", "Jo", "Tim", "Jamie", "Ann", "Tom" }; string group1[NO_STU % 2]; string group2[NO_STU % 2]; createGroups(no_stu,...

  • Hello, I have written a code that I now need to make changes so that arrays...

    Hello, I have written a code that I now need to make changes so that arrays are transferred to the functions as pointer variable. Below is my code I already have. #include<iostream> #include<string> #include<iomanip> using namespace std; //functions prototypes void getData(string id[], int correct[], int NUM_STUDENT); void calculate(int correct[], int incorrect[], int score[], int NUM_STUDENT); double average(int score[], int NUM_STUDENT); void Display(string id[], int correct[], int incorrect[], int score[], double average, int NUM_STUDENT); int findHigh(string id[], int score[], int NUM_STUDENT);...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT