Utilizing your Lab 2 code as a starting point, move both the input and output functions declarations
outside the class. They will no longer be able to directly access your private data (you’ll need to
use both mutators and accessors for private data access). 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.
Add a copy constructor.
Create an object on the stack with the following information (or appropriate data of your choice):
uld – Container
abbreviation - AYK
uldid – AYK68943IB
aircraft - 737
weight – 1654 Kilograms
destination – PDX
Copy the object using a copy constructor. Output the contents of both objects.
Assistant
User
show full implementation and declarsion of friend function.
Assistant
To implement the requested changes, you can follow these steps:
Move the input and output functions declarations outside the class. This means they will no longer be member functions of the class. You can declare them as global functions or define them in a separate namespace, for example.
In order to access the private data members of the class, you'll need to use accessor and mutator functions. Accessor functions are used to retrieve the values of private data members, and mutator functions are used to modify the values of private data members. Add appropriate accessor and mutator functions for each private data member.
Create the object on the stack with the given information or appropriate data of your choice. You can do this by declaring an object of the class type and using the appropriate constructor to initialize its data members.
Create a copy constructor for the class. The copy constructor creates a new object and initializes it with the values of an existing object of the same class. It can be implemented by taking a constant reference to an object as a parameter and initializing the data members of the new object with the corresponding data members of the existing object.
Don't forget to add the friend function kilotopound that converts kilograms to pounds and call it from the weight mutator function if the weight is input in kilograms.
In this implementation, the kilotopound function is defined outside the class as a global function. It takes a double parameter for the weight in kilograms and returns the corresponding weight in pounds. The function is declared as a friend function within the class Container. The setWeight function is updated to call kilotopound if the weight is input in kilograms.
This implementation also includes the complete code for the Container class, including the constructor and accessor functions, as well as the main function to demonstrate the usage of the class and the friend function.
Feel free to modify and adapt the code according to your specific needs!