1 / 11

COS220 Concepts of PLs AUBG, COS dept

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

said
Download Presentation

COS220 Concepts of PLs AUBG, COS dept

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COS220 Concepts of PLs AUBG, COS dept Exercise 5a Fundamentals of Subprograms Reference: lecture 5 assoc. prof. Stoyan Bonev

  2. 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 • inline functions assoc. prof. Stoyan Bonev

  3. 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

  4. 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

  5. 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

  6. Task 4 Build and test an inline function named lbstoklg() that converts pounds to kilograms (1 pound = 0.453592 kg). assoc. prof. Stoyan Bonev

  7. 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

  8. 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

  9. Task 7 Build and test a program that reads its command line arguments. assoc. prof. Stoyan Bonev

  10. 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

  11. Thank You For Your attention assoc. prof. Stoyan Bonev

More Related