Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // More Tutorials at BrandonHok.com
- #include <iostream>
- // 3.1 Functions - Bite Size Calculations
- // Before we begin, how about a warm-up question?
- // What is the difference between a class and a function?
- // So, how are you today? It is raining outside while I'm typing this tutorial.
- // Do you happen to like to make ice on rainy warm days?
- // Section 1
- // Type the code below until the next section and answer the comments on a separate paper or within your compiler.
- // What is the math formula for a cube?
- // Now take a look at how this function is made
- int cubeMaker(int number)
- {
- return number * number * number;
- }
- int main()
- {
- // Can you explain what we did here?
- std::cout << cubeMaker(5) << std::endl;
- std::cout << cubeMaker(10) <<std::endl;
- system("pause");
- }
- // Review Questions
- // You are more than welcome to answer these on a separate piece of paper.
- // These questions are for your benefit and will help you retain the current lesson.
- // So, what do you think makes up a function? What are the important pieces?
- // Can you recognize which part of the function is the return type, name, and parameter list?
- // [These three make up the function's signature]
- // Why do you think we use functions for? What is the purpose of a function?
- // What problems can functions solve?
- // What makes a good function? What is a bad function?
- // Try making your own function. How about square or other math equations?
- // How about having a function outputting words onto the screen? Experiment and have fun!
- // Challenge Question
- // Can you make a class, object, and a function work altogether?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement