226k views
2 votes
Write a C++ code snippet to assign a pointer mytiger with a new tiger object. Call mytiger's read() to read the object's fields. Then, call mytiger's print() to output the values of the fields. Finally, delete mytiger.

Example:
If the input is 6 467, then the output is:

1 Answer

7 votes

Final answer:

To assign a pointer mytiger with a new tiger object in C++, call mytiger's read() to read the object's fields, call mytiger's print() to output the values of the fields, and finally delete mytiger.

Step-by-step explanation:

To assign a pointer mytiger with a new tiger object in C++, we can use the new keyword and dynamically allocate memory for the object. We then call the read() function of the mytiger object to read its fields. Finally, we call the print() function of the mytiger object to output the values of its fields. Afterward, we delete the mytiger object using the delete keyword to free the allocated memory.



Tiger* mytiger = new Tiger();
mytiger->read();
mytiger->print();
delete mytiger;11
User Ndarriulat
by
8.0k points