OOP Practice Question
OOP Practice Question
Instructions:
Indent your code.
Comment your code.
Use meaningful variable names.
Plan your code carefully on a piece of paper before you implement it.
Name of the program should be same as the task name. i.e. the first program should be
Task_1.cpp
void main() is not allowed. Use int main()
You are not allowed to use system("pause")
You are not allowed to use any built-in functions
Task 1:
Write a non-returning function Swap which takes two integers as parameters by reference to swaps
those integers.
Task 2:
Write a returning function strLength which takes only one char* as parameter and returns the length
of the array. Its prototype should be:
int strLength(char* src);
Task 3:
Write a non-returning function strCopy which takes only two char* as parameters, one is destination
and other is source. Your task is to copy all the data of the source into destination.
Hint: You can use strLength function of task 2 to calculate the length of the source. Prototype of the
function should be:
void strCopy(char* &dest, char* src);
Task 4:
Create a file data.txt with integers as given below. Write a function that reads integers one by one and
separates even and odd numbers into two dynamic arrays, say evenArray, oddArray. Regrow both the
arrays. Stop reading the numbers when -1 is found in the file. Find maximum number from both the
arrays and write them in file output.txt as:
Data.txt 1 5 6 2 3 4 5 8 2 0 1 3 9 5 6 -1 5 6 8 3 5 6 4 8
Note: Do not read all the numbers in an array. Create dynamic arrays and regrow.
Create a separate interface (.h file) and implementation (.cpp file) for the functions above. And then make
a file tester.cpp having your driver programme (main() function) where you will test all the above
functions . Your task is to create a menu driven main where user should select the function that needs to
be tested from the above functions.
For example: