Advertisement
bhok

3.1 Functions

Jun 24th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. // More Tutorials at BrandonHok.com
  2. #include <iostream>
  3.  
  4. // 3.1 Functions - Bite Size Calculations
  5.  
  6. // Before we begin, how about a warm-up question?
  7. // What is the difference between a class and a function?
  8.  
  9. // So, how are you today? It is raining outside while I'm typing this tutorial.
  10. // Do you happen to like to make ice on rainy warm days?
  11.  
  12. // Section 1
  13. // Type the code below until the next section and answer the comments on a separate paper or within your compiler.
  14.  
  15. // What is the math formula for a cube?
  16. // Now take a look at how this function is made
  17. int cubeMaker(int number)
  18. {
  19.     return number * number * number;
  20. }
  21.  
  22. int main()
  23. {
  24.     // Can you explain what we did here?
  25.     std::cout << cubeMaker(5) << std::endl;
  26.     std::cout << cubeMaker(10) <<std::endl;
  27.     system("pause");
  28. }
  29.  
  30. // Review Questions
  31. // You are more than welcome to answer these on a separate piece of paper.
  32. // These questions are for your benefit and will help you retain the current lesson.
  33.  
  34. // So, what do you think makes up a function? What are the important pieces?
  35. // Can you recognize which part of the function is the return type, name, and parameter list?
  36. // [These three make up the function's signature]
  37.  
  38. // Why do you think we use functions for? What is the purpose of a function?
  39. // What problems can functions solve?
  40. // What makes a good function? What is a bad function?
  41.  
  42. // Try making your own function. How about square or other math equations?
  43. // How about having a function outputting words onto the screen? Experiment and have fun!
  44.  
  45. // Challenge Question
  46. // Can you make a class, object, and a function work altogether?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement