110 likes | 263 Views
COS220 Concepts of PLs AUBG, COS dept. Exercise 5a Fundamentals of Subprograms Reference: lecture 5. Exercise Topics:. Build and test a set of functions that illustrate the evolution of the subprogram concept: parameter passing mechanisms overloaded functions default arguments functions
E N D
COS220 Concepts of PLs AUBG, COS dept Exercise 5a Fundamentals of Subprograms Reference: lecture 5 assoc. prof. Stoyan Bonev
Exercise Topics: • Build and test a set of functions that illustrate the evolution of the subprogram concept: • parameter passing mechanisms • overloaded functions • default arguments functions • inline functions assoc. prof. Stoyan Bonev
Task 1 Build and test a function named swap() that exchanges the values stored in its originals (actual arguments) using • parameter passing mechanism by value • parameter passing mechanism by address • parameter passing mechanism by reference • global data. assoc. prof. Stoyan Bonev
Task 2 Build and test an overloaded function named prchar1() that displays a concrete character certain number of times on the same line in four versions: void prchar1(); void prchar1(char); void prchar1(int); void prchar1(char, int); assoc. prof. Stoyan Bonev
Task 3 Build and test a default arguments function named prchar2() that displays a concrete character certain number of times on the same line. The default values that the function provides are character ‘*’, number of times 45. assoc. prof. Stoyan Bonev
Task 4 Build and test an inline function named lbstoklg() that converts pounds to kilograms (1 pound = 0.453592 kg). assoc. prof. Stoyan Bonev
Task 5 Write a function ZeroSmaller() that is passed two int arguments by reference and then sets the smaller of the arguments to 0. Write a main() function as a driver program to exercise the function. assoc. prof. Stoyan Bonev
Task 6 Build and test a macro that calculates the area of a rectangle AREA(x, y) and a function named length(x, y) that calculates the perimeter of a rectangle. assoc. prof. Stoyan Bonev
Task 7 Build and test a program that reads its command line arguments. assoc. prof. Stoyan Bonev
Task 7 Build and test a program that reads its command line arguments. int main(int argc, char *argv[], char **envp) { int i; for ( i=0; i <argc; i++) cout << "\n"<< argv[i]; i=0; while (envp[i] != NULL) {cout << "\n\n\n" << envp[i]; i++; } assoc. prof. Stoyan Bonev
Thank You For Your attention assoc. prof. Stoyan Bonev