Skip to end of metadata
Go to start of metadata

These are all extensions for this project:

1) The first extension that I completed was to complete part 1 in C++.  I explored control flow:



The if statement, while loop, do while loop, for loop, for in loop, and switch statement are all the same as in C. There is also a goto statement that allows the programmer to goto a line of code marked by a label:, which is also available in C, but I have never used it before.  It is not recommended that it is used very often because it can be easy to make mistakes. 

2) The second extension that I completed as to complete the second task of the project.  I explored how functions are used as data types in C++.



 A function can be passed to another function in C++ using the form std::function<return_type(arg_types)> func_name.  The function can then be called in the function using func_name(args).  A function can be assigned to a new identifier using auto new_name = old_name.  The auto type deduces the type of the variable from the context.  new_name can not be reassigned to another type of variable.  Interestingly, the original name can be, but then it is no longer able to call the function. I learned that cout<< can be used to print to the terminal, which is much easier than using printf. 

3) The third extension I completed was to complete the third task of the project, to write a quicksort algorithm in C++.


This is a very similar algorithm to those that I used in the last two languages.  I struggled, however with how to make it generic.  I learned in the last part that I can pass functions into other functions.  I also learned how templates can be used to pass generic types into C++ functions.  But then I learned that these templates cannot be used to pass generic functions into other functions.  There is not enough information for the compiler to recognize when the function is called.  Therefore, I made this algorithm so it can sort arrays of integers in any way possible, but not so that it can take any type possible. 

4) The fourth extension that I completed for this language was to write a program that shows the concept of overloading in C++. 


This shows overloading in multiple ways.  First, using generic types in the first function allows it to be used on multiple types.  Second, there are two functions called var.  This is allowed by the compiler because their signatures are different since they have different argument types/numbers.  And finally, the + operation is given another use in that it can create a Person object by taking two other person objects and adding their names.  Thus, functions with different names can have different uses. 

  • No labels