0% found this document useful (0 votes)
50 views1 page

Course C Programming Language Topic: Preprocessor

1. Create three files (function.h, function.cpp, prog.cpp) for a C programming project on the preprocessor topic. 2. In function.cpp, write functions to operate on arrays of integers, reals, and symbols including filling, outputting, finding min/max, sorting, and editing values. 3. In function.h, declare function prototypes and check for a data type constant. Generalize function names based on the constant. 4. In prog.cpp, call functions through generalized names, define a constant for the data type, and specify the main function.

Uploaded by

Andrei Cojocaru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views1 page

Course C Programming Language Topic: Preprocessor

1. Create three files (function.h, function.cpp, prog.cpp) for a C programming project on the preprocessor topic. 2. In function.cpp, write functions to operate on arrays of integers, reals, and symbols including filling, outputting, finding min/max, sorting, and editing values. 3. In function.h, declare function prototypes and check for a data type constant. Generalize function names based on the constant. 4. In prog.cpp, call functions through generalized names, define a constant for the data type, and specify the main function.

Uploaded by

Andrei Cojocaru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Course «C Programming Language»

Topic: Preprocessor
Homework
Exercise 1.
Create a project, in which:
1. Create three files: (function.h, function.cpp, prog.cpp).
2. In a file function.cpp you should write the following functions to operate with an
array of data:
a) function to fill the array with random values;
b) function to output values of the array to the console;
c) function to search for minimum element;
d) function to search for maximum element;
e) sorting function;
f) function to edit value of the array.
These functions must be written to operate with an array of integers, real and
symbolic values. (For each type you should write separate function).
3. In a file function.h you should:
a) describe prototypes of all functions;
b) check whether constant, which indicates a type of data, is defined (#ifdef
INTEGER);
c) create generalizing function names, which will get a function of the
appropriate type, depending on the constant specified in prog.cpp file. (#
Define show ShowInt);
4. In the file prog.cpp you should:
a) in main function call all functions through generalized names of
function.h file ( show For ( ) );
b) define a constant that indicates what type of data will be used. For
example, INTEGER - whole data, CHAR - character data, DOUBLE -
real data (# define INTEGER).

Exercise 2.
Write the following macros using #define directive:
find the smaller of two numbers;
find the larger of two numbers;
raise a number to the second power;
raise a number to a power;
check whether a given number is even;
check whether a given number is odd.

You might also like