Spring 2024 - CS304P - 2
Spring 2024 - CS304P - 2
02 Total Marks: 20
Semester: Spring 2024
Due Date: 24 June, 24
CS304P- Object Oriented Programming - Practical
Objective
To give you an idea of the practical implementation of the following concepts of Object-Oriented Programming
(OOP):
Class: Involves declaration of the class, its member functions, and objects.
Templates: Class templates and function templates.
Uploading instructions:
• Your assignment should be in .CPP format (Any other formats like scan images, PDF, zip, doc, rar and bmp
etc. will not be accepted).
• Save your assignment with your ID (e.g. bc000000000.CPP).
• No assignment will be accepted through email.
It should be clear that your assignment will not get any credit if:
Lectures Covered:
Problem Statement:
Suppose you are working as a junior programmer in an organization. The organization uses different data compression
algorithms before sending a message to reduce the communication bandwidth and transmission time. You are asked
to implement a simple compression algorithm known as Run-Length Encoding (RLE). In RLE, consecutive
occurrences of the same character/number are replaced by a single occurrence of the character/number followed by
the count of its occurrences.
Example Of RLE:
Consider the string: "A A A A B B B C C D A A "
Encoding Process:
• the runs of consecutive characters:
Identify the runs of consecutive characters:
o A A A A (four 'A's)
o B B B (three 'B's)
o C C (two 'C's)
o D (one 'D')
o A A (two 'A's)
• Encode each run as the character followed by the count of repetitions:
o A A A A becomes A4
o B B B becomes B3
o C C becomes C2
o D becomes D1
o A A becomes A2
• Combine these encoded segments into a single string:
o "A4B3C2D1A2"
Final Encoded Output:
"A4B3C2D1A2"
Question Statement:
Write Dev C++ code for the above scenario. The program can compress any type of data: integer, float, characters,
and symbols.
Consider the following points while writing the code:
• Write a single template class to encode integer, character, float, and symbol data.
• The input should be of one data type only. For example, in the case of integer type input, the input string
should be all integers e.g. 2 2 2 3 3 3 3. In the case of character type input, the input string should be all
characters. a a a a b b b b.
• In the main() function, initialize four arrays; one for each data type(int, char, float, symbol).
• Encode array data and display the actual and encoded message as shown in the screenshot of the output of all
types of data.
Note: The C++ program should contain only a template class with an encode function and a main() function only.
Sample Output:
Best of luck!
NOTE: Do not put any query on MDB about this assignment, if you have any query then email at [email protected].
Furthermore, if any student is found cheating by any other student or from online forums then he/she will be awarded
ZERO right away and strict disciplinary action will be taken against the student.