Question: Please do lab on linux terminal and use gedit as editor and zoom in for better vision CpSe 1111 Lab 9 Functions Overview This week,


CpSe 1111 Lab 9 Functions Overview This week, you will gain some experience with functions by creating two functions one for the binary-to-decimal conversion (btod) and one for the decimal-to-binary conversion (dob). Background Information Functions In class, you have leamed that functions are logical groupings of code, a series of steps, that are given a name. Functions are especially useful when these series of steps will need to be done over and over again. Print and scanf are functions that we have already been using. They exist in the library because they are common routines that are used all the time; this way, we don't have to re-write the code for printing to the screen or receiving inputs. These functions hide the complexity of performing 10 operations and provide a simple abstraction for us to use. In addition to using pee-defined functions, we can also write our own. Functions that we write ourselves exist as part of the program and are used the same way, by calling it by its name that we've given it and using it the way we have defined it You have learned in class that writing your own functions toquites 3 things a function declaration (prototype the function implementation (the code for the function, and the function call A function prototype declares the function - it tells the compiler that the function exists it tells the compiler what the return type will be the name of the function, and the types of parameters that the function will be taking in double total contint quantity, diable unit cost); // prototype The prototype ahuwe could also have been written this way: double total cost fint, double); // prototype The names of the parameters are not required in the prototype, but the types are in blue above). In fact, the compiler ignores the names of the parameters in prototypes. Including the names of the parameters is more for readability or convenience to the programmer The name of the function is total_cont You can see that the return type is double which means that that function will return something that is of type double In other words, where that function is implemented further down in the file, it will have a return statement When calling a function that returns something, usually a variable of the same type will be set equal to the function call, so it will be used to hold the return value. If the return value from a function that retums something is not stored in a variable or printed out in a printft) statement, then it is just ignored. For example, if the above function is being called from within main(). the code may look something like: // ... inside of main function double costoItems, costPerItem: int numberOf Items Il other code to get number of items and costPeriten from user costofItems - total_cost (numberofitens, contperitem); // function call Notice that the arguments sent to the function from main() have different names than the parameters. You should do that it's bad practice to use the same names. You will see examples in class of sely that is bad practice. Some functions don't return anything. The retum type of a function that does not return anything will be vold, and there will not be a return statement in the function implementation. An example is shown below. #include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
