I. Write the complete definition of the following members only. Note that these definitions are placed outside of the class' declaration. 1. Default construtor to initialize the length to -1 2. Non-default construtor to initialize the length member. 3. Destructor to print the message "From the destructor" 4. getLength(), the accessor function for the member variable length.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter11: Inheritance And Composition
Section: Chapter Questions
Problem 22SA
icon
Related questions
Question
Consider the following class' declaration.
class Packet {
float length;
public:
Рacket();
Packet(float);
~Packet();
float getlength();
};
I. Write the complete definition of the following members only. Note that these definitions are
placed outside of the class' declaration.
1. Default construtor to initialize the length to -1
2. Non-default construtor to initialize the length member.
3. Destructor to print the message "From the destructor"
4. getlength(), the accessor function for the member variable length.
II. Write a main() which performs the following:
1. Create an instance of type Packet using the default constructor.
2. Create an instance of type Packet using the non-default constructor. Pass a proper value to the
non-default constructor.
3. Print the value of length from using both instances.
Transcribed Image Text:Consider the following class' declaration. class Packet { float length; public: Рacket(); Packet(float); ~Packet(); float getlength(); }; I. Write the complete definition of the following members only. Note that these definitions are placed outside of the class' declaration. 1. Default construtor to initialize the length to -1 2. Non-default construtor to initialize the length member. 3. Destructor to print the message "From the destructor" 4. getlength(), the accessor function for the member variable length. II. Write a main() which performs the following: 1. Create an instance of type Packet using the default constructor. 2. Create an instance of type Packet using the non-default constructor. Pass a proper value to the non-default constructor. 3. Print the value of length from using both instances.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning