Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following class keeps track of how many items are on a restaurants menu, and the number of calories of each menu item. The calories

The following class keeps track of how many items are on a restaurants menu, and the number of calories of each menu item. The calories of the menu items are positive values of type unsigned int and are stored as a dynamically allocated array. The first data member is a pointer that will point to the first element of the array. This array will be of an arbitrary size. The default size of the array shall be 25, but may be specified by the user at the time of construction. The second data member represents the size of the array, i.e. the number of menu items, and is stored as size_t.

class MenuCalories { private: unsigned int* calories; size_t num; public: // constructors (default, one arg, and copy) MenuCalories(); MenuCalories( unsigned int numberOfMenuItems); MenuCalories( const MenuCalories& original); // destructor ~MenuCalories(); // Member function int calorieAtIndex( int index ); };

i) If this is in the Class Specification (header) file MenuCalories.hpp, write the function definitions that would be in the Class Implementation (source) file MenuCalories.cpp.

ii) Why must the parameter of the copy constructor be of type constant reference?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

1. Define mass and mediated communication

Answered: 1 week ago