0% found this document useful (0 votes)
60 views2 pages

OOP Practice Question

This homework assignment involves revising concepts related to arrays and functions in C++ and introduces the concept of separating interface and implementation; it contains 5 tasks involving writing functions to swap integers, find string lengths, copy strings, separate even and odd numbers from a file into dynamic arrays, and creating interface and implementation files to test the functions through a menu.

Uploaded by

Hanzla Salfi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views2 pages

OOP Practice Question

This homework assignment involves revising concepts related to arrays and functions in C++ and introduces the concept of separating interface and implementation; it contains 5 tasks involving writing functions to swap integers, find string lengths, copy strings, separate even and odd numbers from a file into dynamic arrays, and creating interface and implementation files to test the functions through a menu.

Uploaded by

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

HW-1

Topic Revision Lab, separation of interface and implementation


The basic purpose of this lab is to revise some preliminary concepts of C++ that has been
covered in the course of Introduction to Computing and Programming Fundamentals. Its
Objective objective is to recall previously learned basic concepts like revision of arrays and
functions. It introduce the concept of separate interface and implementation.

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.

Task 5: (Most Important)

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:

Press 1 for swap


Press 2 for strLength
Press 3 for strCopy
Press 4 for EvenOddSeparation
Press 0 to exit

You might also like