We are here with you hands in hands to facilitate your learning & don't appreciate the idea of copying or replicating solutions. Read More>>

Looking For Something at vustudents.ning.com? Click Here to Search

www.bit.ly/vucodes

+ Link For Assignments, GDBs & Online Quizzes Solution

www.bit.ly/papersvu

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

Assignment No. 04 Total Marks: 20
Semester: Spring 2015
CS304: Object Oriented Programming Due Date: 17/08/2015

Instructions:

Please read the following instructions carefully before submitting assignment. It should be clear that your assignment will not get any credit if:

The assignment is submitted after due date.

The submitted assignment does not open or file is corrupt.

Assignment is copied(partial or full) from any source (websites, forums, students, etc)

Note: You have to upload only .cpp file. Assignment in any other format (extension) will not be accepted and will be awarded with zero marks. For example, if you submit code in .doc (Microsoft Word Document) or .txt files or

.exe file, no reward will be given in any case.

Objective:

The objective of this assignment is to provide hands on experience of:

Inheritance

Generic Programming Polymorphism

Guidelines:

Code should be properly indented and well commented.

Follow C/C++ guide lines while writing variable names & function names etc. Use only Dev-C++ for this assignment.

For any query about the assignment, contact at cs304@vu.edu.pk

Assignment

Problem Statement:

In this assignment, write a generic code that will work for all data types. You are required to write a template function named add() in your program. This function will take two arguments of template type that will add these passed parameters and return the result of addition. i.e.

template

T add (T value1, T value2)

Within main() function, you are required to call the template function add() for int, float and Complex types. Now, display the result of all these functions.

int v1 = 5, v2 = 6 ; float x = 2.3, y = 3.5 ;

Complex c1(2, 3), c2(2, 3), t ;

Note: For complex numbers, you will have to create a user defined type.

Sample output of the program:

+ How to Follow the New Added Discussions at Your Mail Address?

+ How to Join Subject Study Groups & Get Helping Material?

+ How to become Top Reputation, Angels, Intellectual, Featured Members & Moderators?

+ VU Students Reserves The Right to Delete Your Profile, If?


See Your Saved Posts Timeline

Views: 9288

.

+ 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)

Attachments:

Replies to This Discussion

Attachments:

ye lo guays 100% c0rrect solution 

sab zain ka chappa laga rahy hainnnn

jo ke wrong solve hai 

sorry guys 

phir na kehna batya niii tha

#include

#include
using namespace std;
template
T add(T value1, T value2)
{
return (value1+value2);
}
class Complex
{
public:
double real,img;
Complex(): real(0.0), img(0.0) {}
Complex (double real, double img):real(real), img(img) {}
double getre() const {return real;}
double getimg() const {return img;}
friend Complex operator +(const Complex&, const Complex&);
};
Complex operator +(const Complex& value1, const Complex& value2)
{
double r, i;
r = value1.getre() + value2.getre();
i = value1.getimg() + value2.getimg();
return Complex(r,i);
}
int main()
{
int v1 = 5, v2 = 6 ;
float x = 2.3, y = 3.5 ;
Complex c1(2, 3), c2(2, 3), t ;
cout"Addition of the Integers: "/p>

Done Chk this one

Attachments:

kya ye correct hai bro.

Attachments:

#include
#include
using namespace std;
template
T add(T value1, T value2)
{
return (value1+value2);
}
class Complex
{
public:
double real,img;
Complex(): real(0.0), img(0.0) {}
Complex (double real, double img):real(real), img(img) {}
double getre() const {return real;}
double getimg() const {return img;}
friend Complex operator +(const Complex&, const Complex&);
};
Complex operator +(const Complex& value1, const Complex& value2)
{
double r, i;
r = value1.getre() + value2.getre();
i = value1.getimg() + value2.getimg();
return Complex(r,i);
}
int main()
{
int v1 = 5, v2 = 6 ;
float x = 2.3, y = 3.5 ;
Complex c1(2, 3), c2(2, 3), t ;
cout"Addition of the Integers: ";add(v1,v2)'\n';
cout"Addition of the Float: "add(x,y)'\n';
t = add(c1, c2);
cout"Addition of Complex Numbers : Real Part :"t.real'\t'"Imaginary Part :"t.imgendl;
system("PAUSE");
}

RSS

Latest Activity

فقیہہ اقدس liked ٹمبکٹو's discussion محبّت اور دل - عشق مجازی
14 minutes ago
Choudary Nafees Ejaz commented on + M.Tariq Malik's group STAT404 Regression and Correlation
2 hours ago
Choudary Nafees Ejaz joined + M.Tariq Malik's group
2 hours ago
Choudary Nafees Ejaz liked + M.Tariq Malik's group STAT404 Regression and Correlation
2 hours ago
MUHAMMAD KASHIF replied to + M.Tariq Malik's discussion ENG506 World Englishes Assignment No 01 Fall 2019 Solution & Discussion in the group ENG506 World Englishes
4 hours ago
MUHAMMAD KASHIF joined + M.Tariq Malik's group
4 hours ago
+ M.Tariq Malik replied to ayesha's discussion CS614 Assignment NO.1 Fall 2019 Solution&Discussion Due date: 14 Nov 2019 in the group CS614 Data Warehousing
4 hours ago
+ M.Tariq Malik replied to ayesha's discussion CS614 Assignment NO.1 Fall 2019 Solution&Discussion Due date: 14 Nov 2019 in the group CS614 Data Warehousing
4 hours ago
Profile IconKhadija Naveed, Muhammad Abdullah, maha khan and 6 more joined Virtual University of Pakistan
4 hours ago
MUHAMMAD KASHIF replied to + M.Tariq Malik's discussion ENG505 Language Learning Theories Assignment No 01 Fall 2019 Solution & Discussion in the group ENG505 Language Learning Theories
4 hours ago
MUHAMMAD KASHIF joined + M.Tariq Malik's group
4 hours ago
+ M.Tariq Malik replied to + M.Tariq Malik's discussion CS201 Assignment No 01 Fall 2019 Solution & Discussion Due Date: 14-11-2019 in the group CS201 Introduction to Programming
4 hours ago
+ M.Tariq Malik replied to + M.Tariq Malik's discussion PAK301 Assignment No 01 Fall 2019 Solution & Discussion Due Date: 21-11-2019 in the group PAK301 Pakistan Studies
4 hours ago
+ M.Tariq Malik replied to + M.Tariq Malik's discussion PAK301 Assignment No 01 Fall 2019 Solution & Discussion Due Date: 21-11-2019 in the group PAK301 Pakistan Studies
5 hours ago
+ M.Tariq Malik replied to Rana Ali's discussion EDU201 Learning Theories Assignment No 01 Fall 2019 Solution & Discussion in the group EDU201 Learning Theories
5 hours ago
+ M.Tariq Malik replied to + M.Tariq Malik's discussion HRM624 Conflict Management Assignment No 01 Fall 2019 Solution & Discussion Due Date: 21-11-2019 in the group HRM624 Conflict Management
5 hours ago
+ M.Tariq Malik liked + M.Tariq Malik's discussion HRM624 Conflict Management Assignment No 01 Fall 2019 Solution & Discussion Due Date: 21-11-2019
5 hours ago
+ M.Tariq Malik added a discussion to the group HRM624 Conflict Management
5 hours ago
+ M.Tariq Malik replied to + M.Tariq Malik's discussion CS723 Probability and Stochastic Processes Assignment No 01 Fall 2019 Solution & Discussion in the group CS723 Probability and Stochastic Processes
5 hours ago
+ M.Tariq Malik liked + M.Tariq Malik's discussion CS723 Probability and Stochastic Processes Assignment No 01 Fall 2019 Solution & Discussion
5 hours ago

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

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