We have been working very hard since 2009 to facilitate in your learning Read More. We can't keep up without your support. Donate Now.


+ Link For Assignments, GDBs & Online Quizzes Solution


+ Link For Past Papers, Solved MCQs, Short Notes & More

Looking for Something at Site? Search Below

Object Oriented Programming (CS304)

Assignment # 03

Total marks = 20

                                                                                       Due Date =01/08/2016

Lectures Covered = All lectures up-to 33


Assignment Guidelines:


Instructions for the assignment preparation:


  • You are required to make a presentation file (.ppt or .pptx) for your assignment solution
  • Presentation will consist of maximum of 4 – 5 slides
  • First slide will contain student name and ID
  • Remaining slides will contain the solution of the assignment
  • You have to formally present your assignment with proper dress code and have to record the video of your presentation
  • You can use any video recording facility such as web cam, camera, mobile phone or etc. for recording of your presentation (See the tutorial “Tips for Recording Videos.mp4” available at download section of VULMS). Click http://lms1.vu.edu.pk/Courses/CS304/Downloads/Tips%20for%20Recordin... to download video file.
  • In first slide, you will speak your name and ID, and in remaining slides, you will be required to explain your solution given in your presentation file.
  • Your introduction and solution explanation should not take more than 4 to 5 minutes
  • After recording of your presentation, you have to convert your video in “.3gp” format using any video conversion tool to reduce the size of the video file. (See the tutorial “Video Compression.mp4” available at download section of VULMS). Click http://lms1.vu.edu.pk/Courses/CS304/Downloads/Soft%20Skill%20Assign... to download video file.
  • After converting the video in .3gp format, review your file to verify that audio and video are properly playing. 
  • Install VLC media player to view your compressed video before uploading on VU-LMS.You can download VLC from http://www.videolan.org/vlc/download-windows.html.
  • It is preferable to use English in your presentation in case of reluctance you can also use Urdu language.
  • Note that you will record your presentation standing in front of camera.


Weightage of Assignment:


  • This assignment has 5% weightage of your overall marks of this course.


Instructions for the assignment submission:


  • Save your assignment with your ID (e.g. bc020200786.rar)
  • Make sure that size of assignment file should not exceed 30 MB


For any query please contact: CS304@vu.edu.pk



Assignment Task

Note: You are given two topics. You have to select any one topic for your presentation. Instructions for solving the assignment are given at the top.


Topic-1:  Polymorphism

You need to explain polymorphism in detail. A working C++ code example will also be required if you select this topic to ensure that the audience gets the clear concept of this topic.


Topic-2: Generic Programming

In this topic you are required to explain that why and how overloaded functions can be changed to single function template. You need to explain this topic with the help of C++ code.

+ http://bit.ly/vucodes (Link for Assignments, GDBs & Online Quizzes Solution)

+ http://bit.ly/papersvu (Link for Past Papers, Solved MCQs, Short Notes & More)

+ Click Here to Search (Looking For something at vustudents.ning.com?)

+ Click Here To Join (Our facebook study Group)

Views: 4597


Replies to This Discussion

Please Discuss here about this assignment.Thanks
Our main purpose here discussion not just Solution
We are here with you hands in hands to facilitate your learning and do not appreciate the idea of copying or replicating solutions.

Dont waste your time here and there

just take this video with working example and understanding of polymorphisom and rememeber it is not so simple n short concept for which you will look for 4,5 min video and grab the concept. Those who has done their assignment # 2 and have understanding of that for those polymorphisom will be very easy. In this video first i Explained same thing without polymorphisom then told what and how to polymorphisom.


good job SK(MS-SE)  

Thank you so much for this...

i have done my assignment no 2 from your video's ..

it's so helpful ...

dear students please all of u must listen this video and solve your assignment by yourself...

Excellent ; highly appreciated .

the code i discussed in my video is located at this google drive


Also look into this video which was your assignment # 2, but I converted into polymorphic way to clear polymorphisom its case study.

agar ksi ko sirf is case study se samjh ajaey polymorphisom ki jo k 10 min ki video hy to salam hy mera usko ,

yeh case study apki assignment # 2 hy jisko  polymorphic way se solve kia hy

this statement is for those jo k video ki length he dekh k keh dety hain kon suny itna lamba lecture :(

polymorphisom is not small concept and based on Inheritance. 

hmmm bilkul ..

brother very good for us! 

brother can u help me in C++ code???


listen this video completely you can get clear concept.

i listen all but in code i face problem

yes sure ..

Generic Programming


Generic programming refers to programs containing generic abstractions (general

code that is same in logic for all data types like printArray function), then we

instantiate that generic program abstraction (function, class) for a particular data

type, such abstractions can work with many different types of data.



As you can imagine major benefits of this approach are,

a. Reusability: Code can work for all data types

b. Writability: Code takes lesser time to write

c.    Maintainability: Code is easy to maintain as changes are needed to be made

in a single function or class instead of many functions or classes.



In C++ generic programming is done using templates.


Templates are of two kinds,


a. Function Templates (in case we want to write general function like


b. Class Templates (in case we want to write general class like Array class)


Compiler generates different type-specific copies from a single template

This concept is similar to concept of making prototype in the form of class for all

objects of same kind.

Function Templates


A function template can be parameterized to operate on different types of data types.




We write template keyword above any function make any function as template

function, they can be declared in any one of the following ways,


template/b> class T >

void funName( T x );


// OR


template/b> typename T >

void funName( T x );


// OR


template/b> class T, class U,  >

void funName( T x, U y,  );


Note here T is typename of class name and we use this T instead of data type/s for

which we want our function to work as template.


For Example – Function Templates

Following function template prints an array having almost any type of elements

(note the use of T instead of int or float or char in implementation of function):


template/b> typename T >

void printArray( T* array, int size )


for ( int i = 0; i /b> size; i++ )

cout  array[ i ]  “, ”; // Here data type of array is T



Similarly we can also write same function as,


template/b> class T >

void printArray( T* array, int size )


for ( int i = 0; i /b> size; i++ )

cout  array[ i ]  “, ”; // Here data type of array is T



There is no difference in two implementations.


Template function will be instantiated for a particular data type according to passed

argument as shown below,


int main() {

int iArray[5] = { 1, 2, 3, 4, 5 };

void printArray( iArray, 5 ); // Instantiated for int[] as passed array is of

type int []


cHar cArray[3] = { ‘a’, ‘b’, ‘c’ };

void printArray( cArray, 3 ); // Instantiated for cHar[] as argument is of type

cHar []

return 0;


Overloading vs. Templates


Function templates are used when we want to have exactly identical operations on

different data types in case of function templates we can not change implementation

from data type to data type however we can specialize implementation for a

particular data type.

In case we want to have similar operations on different data types we need function

overloading in function overloading case we can give similar but slightly different

implementation for each data type.

Example: Overloading vs. Templates


•      ‘+’ operation is overloaded for different operand types (different

implementation in each case)

•      A single function template can calculate sum of array of many types


Function Overloading

String operator +( const String& x,         const String& y ) {

String tmp;

tmp.pStr = new char[strlen(x.pStr) + strlen(y.pStr) + 1 ];

strcpy( tmp.pStr, x.pStr );

strcat( tmp.pStr, y.pStr );

return tmp;



String operator +( const char * str1, const String& y ) {

String tmp;

tmp.pStr = new char[ strlen(str1) + strlen(y.pStr) + 1 ];

strcpy( tmp.pStr, str1 );

strcat( tmp.pStr, y.pStr );

return tmp;




template< class T >

T sum( T* array, int size ) {

T sum = 0;


for (int i = 0; i < size; i++)

sum = sum + array[i];


return sum;


Template Arguments as Policy:


We can change behaviour of a template using template parameter. We can pass a template

argument to enforce some rule (policy). For example see the problem statement below,


“Write a function tHat compares two given cHaracter strings”


This function is similar to built in string comparison function strcmp with the

difference that it can perform both case sensitive and case insensitive comparisons



This is a member-supported website. Your contribution is greatly appreciated!

Latest Activity

+M.Tariq Malik replied to +M.Tariq Malik's discussion CS614 Current Final Term Papers Spring 2020 & Past Solved Papers, MCQs in the group CS614 Data Warehousing
2 minutes ago
+M.Tariq Malik replied to +M.Tariq Malik's discussion CS712 Current Final Term Papers Spring 2020 & Solved MCQs, Short Notes, Solved Past Papers, Solved Online Quizzes, E-Books, FAQs, Short Questions Answers & More in the group CS712 Distributed DBMS
4 minutes ago
+M.Tariq Malik replied to +M.Tariq Malik's discussion CS712 Current Final Term Papers Spring 2020 & Solved MCQs, Short Notes, Solved Past Papers, Solved Online Quizzes, E-Books, FAQs, Short Questions Answers & More in the group CS712 Distributed DBMS
4 minutes ago
+M.Tariq Malik replied to +M.Tariq Malik's discussion CS712 Current Final Term Papers Spring 2020 & Solved MCQs, Short Notes, Solved Past Papers, Solved Online Quizzes, E-Books, FAQs, Short Questions Answers & More in the group CS712 Distributed DBMS
5 minutes ago
+M.Tariq Malik liked +M.Tariq Malik's discussion CS712 Current Final Term Papers Spring 2020 & Solved MCQs, Short Notes, Solved Past Papers, Solved Online Quizzes, E-Books, FAQs, Short Questions Answers & More
5 minutes ago
+M.Tariq Malik's 3 discussions were featured
5 minutes ago
+M.Tariq Malik added a discussion to the group CS712 Distributed DBMS
6 minutes ago
+M.Tariq Malik replied to +M.Tariq Malik's discussion STA301 Final Term Papers Spring 2020 & Past Solved Papers, MCQs for Exam Preparation in the group STA301 Statistics and Probability
12 minutes ago

Today Top Members 

© 2020   Created by +M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service