I'm trying to create a copy constructor to copy my string, int and double variables after taking it in from the user. I want to display the copy constructor as well as display it using the shipment.output. I think I have created the copy constructor but I'm still confused on how to call the copy constructor and how to actually display it's content after copying the variables. Looking on my textbook and various youtube videos I'm still confused on how to call a copy constructor and display it. I think the copy constructor I already have is already copying the variables but I am not sure.
I am also getting and error when building the code on code blocks. "Error: No matching function for call to 'cargo::cargo()' ". Not entirely sure what's causing that either.
#include<iostream>
#include<string>
using namespace std;
class cargo{
public:
void setUnit(string unitName);
string getUnit() const;
void setAbbrev(string abbrevName);
string getAbbrev() const;
void setUnitID(string unitIDName);
string getUnitID() const;
void setAircraft(int aircraftname);
int getAircraft() const;
void setWeight(double weightName);
double getWeight() const;
void setDestinatoin(string destinationName);
string getDestination() const;
cargo(const cargo& other);
friend int weightConvert(int weightName);
void input();
void output();
void copy();
private:
string unit;
string abbrev;
string unitID;
int aircraft;
double weight;
string destination;
};
double weightConvert(double weightName){
weightName = weightName * 2.2046;
return weightName;
}
void cargo::setUnit(string unitName){
unit = unitName;
}
string cargo::getUnit() const{
return unit;
}
void cargo::setAbbrev(string abbrevName){
abbrev = abbrevName;
}
string cargo::getAbbrev() const{
return abbrev;
}
void cargo::setUnitID(string unitIDName){
unitID = unitIDName;
}
string cargo::getUnitID() const{
return unitID;
}
void cargo::setAircraft(int aircraftName){
aircraft = aircraftName;
}
int cargo::getAircraft() const{
return aircraft;
}
void cargo::setWeight(double weightName){
cout << "Is your weight in kilograms or pounds? k/p" << endl;
char x;
cin >> x;
if(x == 'k' || x == 'K'){
weight = weightConvert(weightName);
} else if(x == 'p' || x == 'P') {
weight = weightName;
}
}
double cargo::getWeight() const{
return weight;
}
void cargo::setDestinatoin(string destinationName){
destination = destinationName;
}
string cargo::getDestination() const{
return destination;
}
void cargo::input(){
string tempString;
int tempInt;
cout << "Is it a pallet or container" << endl;
getline(cin, tempString);
setUnit(tempString);
cout << "What is the load abbreviatoin?" << endl;
getline(cin, tempString);
setAbbrev(tempString);
cout << "What is the unitID?" << endl;
getline(cin, tempString);
setUnitID(tempString);
cout << "What is the aircraft type?" << endl;
cin >> tempInt;
setAircraft(tempInt);
cout << "Enter the weight of your unit." << endl;
double tempDouble;
cin >> tempDouble;
setWeight(tempDouble);
cout << "What is the destination for the unit?" << endl;
cin.ignore();
getline(cin, tempString);
setDestinatoin(tempString);
}
void cargo::output(){
cout << "Unit load type: " << getUnit() << endl;
cout << "Unit load abbreviation: " << getAbbrev() << endl;
cout << "Unit ID: " << getUnitID() << endl;
cout << "Aircraft type: " << getAircraft() << endl;
cout << "Weight: " << getWeight() << endl;
cout << "Destination: " << getDestination() << endl;
}
cargo::cargo(const cargo& other){
unit = other.getUnit();
abbrev = other.getAbbrev();
unitID = other.getUnitID();
weight = other.getWeight();
destination = other.getDestination();
}
int main(){
cargo shipment;
shipment.input();
shipment.output();
return 0;
}