Starting from:
$30

$24

Lab 9 Solution

Introduction:




Last week we started an investigation of functions and their uses in programming. Functions though, are much broader than what we were able to cover in a single lab. This week we will focus of refining our understanding of functions.




Lab 7 mentioned that functions do not need to have a unique name, only a unique “signature” which is a combination of the functions name and its parameters. So for instance ​void foo (int a) ​and ​void foo (char c) ​are recognized by the compiler as different functions. Utilizing this feature is called “overloading” and it allows us to write several versions of the same function in order to make it more useful and general-purpose.




Another refinement we can apply to our understanding of functions is to further analyze how values are passed into functions as parameters. Specifically we need to understand when a function is able to alter a variable which has been passed to it. Additionally we need to understand the “life span” of variables in a computing environment and where within a program a variable might or might not be visible.




The purpose of today’s lab is to introduce you to function overloading and variable scope.




Directions:







1- ​Download the starter file yourName_lab9.cpp Launch Code::Blocks and rename the file with the appropriate name.




2-​Include the standard header for this lab:




//Your Name




//CS1428




//Lab 9




3- ​You are building the back end for an app called DogDiet. This app will help dog owners make nutritional decisions for their dog. To do this you will need to fill in the helper function defined in the starter file. A main function has been written for you to test your functions. Do not make any changes to the main function.




4- ​Add comments to your helper functions. You should explain what is being done and how the functions connect to each other.

4- ​After filling in the overloaded functions build and run your code. Correct any errors. Your output should look something like this:




















































































































































5- ​Submit your .cpp file to TRACS. You can leave when you’re donne.

More products