In-Class Practice

Modular Design



Consider the following application file:


 /* Application Module
  * app.c
  */

 #include "library.h"

 int main(void) {
     int i;

     printf("Running version %s.\n", VERSION); 
     for (i = 0; i < 5; i++) {
         printf("n = %02d f(n) = %4d\n", i + 1, f(i + 1)); 
     }

     return 0;
 }

The library.h header file specifies the version used and declares the function f()


 /* Library Module - Header
  * library.h
  */

 #define  VERSION "1.0"
 int f(int i);

The library.c implementation file define the function f()


 /* Library Module - Implementation
  * library.c
  * version 1.0
  */

 int f(int i) {
     return i * i * i;
 }

Show the output produced by the pre-processor (complete the missing parts of the statements below)



 int main(void) {

     printf("Running version %s.\n",                    ); 
     for (i = 0; i < 5; i++) {
         printf(                                                        ); 

     return 0;
 }

Show the output produced by the executable here







 

Now change the library.h header file to version 2.0:


 /* Library Module - Header
  * library.h
  */

 #define  VERSION "2.0"
 int f(int i);

The library.c implementation file define the function f()


 /* Library Module - Implementation
  * library.c
  * version 2.0
  */

 int f(int i) {
     return 2 * i * i;
 }

Show the output produced by the pre-processor (complete the missing parts of the statements below)



 int main(void) {

     printf("Running version %s.\n",                    ); 
     for (i = 0; i < 5; i++) {
         printf(                                                        ); 

     return 0;
 }

Show the output produced by the executable here







 

Note that the change in the version of the library module did not require any change to the application module.


   Printer Friendly Version of this Page print this page     Top  Go Back to the Top of this Page



  Designed by Chris Szalwinski   Copying From This Site