Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. Product and Attributes
- - Create a class Product with two member attributes called name and price. Their
- types should be std::string and double. Create an object called beverage in
- main function. Set name and price to "coffee" and 1.5. Print name and price.
- - Learn: class and object creation, public, access and usage of member
- attributes,
- 2. Product and Default Constructor
- - Continue from exercise 1.
- - Add a default constructor into class Product. Initialize name and price to
- "null" and 0. Add print into constructor that tells the name of a Product
- object and that we are in a constructor. Add a destructor. Add a print into
- destructor that tells the name of the Product object and that we are in a
- destructor. Create new object called sandwich after printing details of
- coffee object. Print name and price of the sandwich as for the coffee.
- - Learn: default constructor and destructor
- 3. Product and Parameterized Constructor
- - Continue from exercise 2.
- - Add parameterized constructor accepting two parameters: name and price as
- std::string and double. Add a print into the parameterized constructor
- about calling it and print the name of the Product object too. Change
- instantiation of the coffee object to use the new parameterized constructor.
- Don't remove setting name and price for coffee yet.
- Compiler should warn about shadowed members. Fix issue by renaming member
- attributes to mName and mPrice. Alternatively m_name or name_ naming scheme
- can be used as well.
- - Learn: parameterized constructor
- +
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement