Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. 1. Product and Attributes
  2. - Create a class Product with two member attributes called name and price. Their
  3. types should be std::string and double. Create an object called beverage in
  4. main function. Set name and price to "coffee" and 1.5. Print name and price.
  5. - Learn: class and object creation, public, access and usage of member
  6. attributes,
  7.  
  8.  
  9. 2. Product and Default Constructor
  10. - Continue from exercise 1.
  11. - Add a default constructor into class Product. Initialize name and price to
  12. "null" and 0. Add print into constructor that tells the name of a Product
  13. object and that we are in a constructor. Add a destructor. Add a print into
  14. destructor that tells the name of the Product object and that we are in a
  15. destructor. Create new object called sandwich after printing details of
  16. coffee object. Print name and price of the sandwich as for the coffee.
  17. - Learn: default constructor and destructor
  18.  
  19.  
  20. 3. Product and Parameterized Constructor
  21. - Continue from exercise 2.
  22. - Add parameterized constructor accepting two parameters: name and price as
  23. std::string and double. Add a print into the parameterized constructor
  24. about calling it and print the name of the Product object too. Change
  25. instantiation of the coffee object to use the new parameterized constructor.
  26. Don't remove setting name and price for coffee yet.
  27. Compiler should warn about shadowed members. Fix issue by renaming member
  28. attributes to mName and mPrice. Alternatively m_name or name_ naming scheme
  29. can be used as well.
  30. - Learn: parameterized constructor
  31. +
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement