11.14. Coding Practice¶
Write the Cake
structure, which has instance variables name, weight and member function has_icing function that returns a bool. Use the Cake
object initialised below to invoke the has_icing function.
Below is one way to implement the program. We declare the Cake
struct and list the instance
variables in order.
The Cake
structure has instance variables name, weight and member function has_icing. Write the has_icing function which returns true when the weight is greater than 10.
Below is one way to implement the program.
Create the Music
structure, with member variables num_sold and year, and member functions sold
and is_new
. The sold
function should print twice the num_sold while the is_new
function should return true if the year is greater than 2012.
Below is one way to implement the program.
Create the Music
structure, with member variables num_sold and year, and member function latest
. The latest
function operates on two Music
objects, and returns true if the current object’s year is greater than the other’s.
Below is one way to implement the program.
Write the function printInfo
, which prints the music album’s information in the format
“This is a artist
, year
album with/without featured artists.” If artist
has the value “n/a”, printInfo
prints out “Unknown artist
! Your album is from year
.”
Below is one way to implement the program.
The Music
structure has instance variables name, weight and member function has_icing. Write the has_icing function which returns true when the weight is greater than 10.
Below is one way to implement the program.
Write the Pants
structure, which has instance variables size and material. Also write a constructor for Pants
that would be called when p1 is declred. The constructor sets the size to L and material to cotton.
Below is one way to implement the program. We declare the Pants
struct and list the instance
variables in order. In addition, we write a default constructor.
Implement 2 constructors for the struct Book
, which has the instance variables name and publish_year. One should be a default constructor that sets name to N/A and publish_year to 0. The other constructor should take arguments
Below is one way to implement the program.
Implement the struct Book
as would appear in the Book.h header file and the following necessary statement in main.cpp in order for thr program to run
Below is one way to implement the program.
Implement the struct Instrument
struct along with 2 constructors for the same (default and one that takes parameters). Instrument
has the instance variables name, year_made and function is_popular(). The default constructor sets name to guitar and year_made to 2000.
Below is one way to implement the program.