Question

C++ Itty Bitty Airfreight (IBA) Lab 3.1 Create your objects in the stack (not on the...

C++ Itty Bitty Airfreight (IBA)

Lab 3.1

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 object on the stack with the following information:

uld – Container

abbreviation - AYK

uldid – AYK68943IB

aircraft - 737

weight – 1654 Kilograms

destination – PDX

Output the contents of your object.

-------------------------------------------------------------------------------------------------------------------------------------

Lab 3.2

Utilizing Lab 3.1 code, add a copy constructor.

Create an object on the stack using the following data:

uld – Container

abbreviation - ABB

uldid – ABB31545IB

aircraft - 737

weight – 1156

destination – BUR

Copy the first object using a copy constructor. Output the contents of both objects.

Homework Answers

Answer #1

Code:-

/// Lab 3.1 ///

#include<iostream>
#include<string>
using namespace std;
class Item
{
public:
string uld;
string abbreviation;
string uldid;
int aircraft;
double weight;
string destination;
void print()
{
cout<<"uld - "<<uld<<endl;
cout<<"abbreviation - "<<abbreviation<<endl;
cout<<"uldid - "<<uldid<<endl;
cout<<"aircraft - "<<aircraft<<endl;
cout<<"weight - "<<weight<<" Kilograms"<<endl;
cout<<"destination - "<<destination<<endl;
}
friend void kilotopound(Item );
};

void kilotopound(Item I)
{
cout<<"Weight in pounds is: "<<I.weight*2.2<<" Pounds "<<endl;
}
int main()
{
Item I;
I.uld="Container";
I.uldid="AYK68943IB";
I.abbreviation="AYK";
I.aircraft=737;
I.weight=1654;
I.destination="PDX";
I.print();
kilotopound(I);
return 0;
}

Code Screenshot:-

Output:-

/// Lab 3.2 ///

#include<iostream>
#include<string>
using namespace std;
class Item
{
public:
string uld;
string abbreviation;
string uldid;
int aircraft;
double weight;
string destination;
Item()
{
  
}
Item(Item & i)
{
uld = i.uld;
abbreviation= i.abbreviation;
uldid=i.uldid;
aircraft=i.aircraft;
weight=i.weight;
destination=i.destination;
}
void print()
{
cout<<"uld - "<<uld<<endl;
cout<<"abbreviation - "<<abbreviation<<endl;
cout<<"uldid - "<<uldid<<endl;
cout<<"aircraft - "<<aircraft<<endl;
cout<<"weight - "<<weight<<" Kilograms"<<endl;
cout<<"destination - "<<destination<<endl;
}
friend void kilotopound(Item );
};
void kilotopound(Item I)
{
cout<<"Weight in pounds is: "<<I.weight*2.2<<" Pounds "<<endl;
}
int main()
{
Item I;
I.uld="Container";
I.uldid="ABB315451B";
I.abbreviation="ABB";
I.aircraft=737;
I.weight=1156;
I.destination="BUR";
Item I2(I);
I.print();
kilotopound(I);
cout<<"Second Object\n";
I2.print();
kilotopound(I2);
return 0;
}

Code Screenshots:-

Output:-

Please UPVOTE thank you...!!!

Know the answer?
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
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT