Latest Activity In Study Groups

Join Your Study Groups

VU Past Papers, MCQs and More

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.

Consider Candidate class from E-Voting System discussed in Assignment No. 01. Class Details are given as follows:

Class Name

Attribute Name

Attribute Data Type




Integer/Character String

-Default constructor()



Character String

-Function to overload  stream extraction operator ( >>)



Character String

- Function to overload stream      insertion operator ()



Character String

-Function to overload comparison operator (= = )

Write a Program in C++ that implements the candidate class with given attributes and functions. Your program should be able to do the following:


  1. There should be a default constructor to initialize data members of candidate class.


  1. There should be a function to overload stream extraction operator so that we should take input for each object data members directly from main function using cin statement e.g. cin>>Candidate1.


            Note: Make sure you take input against each data member specified in above table.


  1. While inputting, you also have to check for duplicate records i.e. information of a single candidate should not be entered more than one. For this, you have to overload “= =” operator so that comparison operation would be performed on objects directly in main( ) function by writing this type of statement C1= = C2.


  1. There should be a function to overload stream insertion operator so that we should display each object data directly from main function using cout statement e.g. . coutCandidate1.


  1. In main() function, you are required to create an array of objects to store candidates information. For example if you want to register data of 5 candidates, you should create an array of 5 objects.


Sample Output:


For sample output look the attached animated GIF file.

Lectures Covered:  This assignment covers Lecture #    16-21

Deadline:             Your assignment must be uploaded/submitted at or before. June 21, 2013

Views: 5438

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.


The objective of this assignment is:


  • To give you the idea of practical implementation of overloading different operators.

Read The following detail to Understand the Objective of Assignment

Overloading operators (C++ only)

You can redefine or overload the function of most built-in operators in C++. These operators can be overloaded globally or on a class-by-class basis. Overloaded operators are implemented as functions and can be member functions or global functions.

Operator overloading involving vector types is not supported.

An overloaded operator is called an operator function. You declare an operator function with the keyword operator preceding the operator. Overloaded operators are distinct from overloaded functions, but like overloaded functions, they are distinguished by the number and types of operands used with the operator.

Consider the standard + (plus) operator. When this operator is used with operands of different standard types, the operators have slightly different meanings. For example, the addition of two integers is not implemented in the same way as the addition of two floating-point numbers. C++ allows you to define your own meanings for the standard C++ operators when they are applied to class types. In the following example, a class called complx is defined to model complex numbers, and the + (plus) operator is redefined in this class to add two complex numbers.

// This example illustrates overloading the plus (+) operator.  #include <iostream> using namespace std;  class complx {       double real,              imag; public:       complx( double real = 0., double imag = 0.); // constructor       complx operator+(const complx&) const;       // operator+() };  // define constructor complx::complx( double r, double i ) {       real = r; imag = i; }  // define overloaded + (plus) operator complx complx::operator+ (const complx& c) const {       complx result;       result.real = (this->real + c.real);       result.imag = (this->imag + c.imag);       return result; }  int main() {       complx x(4,4);       complx y(6,6);       complx z = x + y; // calls complx::operator+() }

You can overload any of the following operators:

+ - * / % ^ & | ~
! = /td> > += -= *= /= %=
^= &= |= >> = >>= == !=
<= >= && || ++ -- , ->* ->
( ) [ ] new delete new[] delete[]      

where () is the function call operator and [] is the subscript operator.

You can overload both the unary and binary forms of the following operators:

+ - * &

You cannot overload the following operators:

. .* :: ?:

You cannot overload the preprocessor symbols # and ##.

An operator function can be either a nonstatic member function, or a nonmember function with at least one parameter that has class, reference to class, enumeration, or reference to enumeration type.

You cannot change the precedence, grouping, or the number of operands of an operator.

An overloaded operator (except for the function call operator) cannot have default arguments or an ellipsis in the argument list.

You must declare the overloaded =[](), and -> operators as nonstatic member functions to ensure that they receive lvalues as their first operands.

The operators newdeletenew[], and delete[] do not follow the general rules described in this section.

All operators except the = operator are inherited.

good  plz write the code

this is the assignmnet file 


Rushda Ehsan Please upload your folder in .ZIP does not support the .rar format folder..thanks 

here is the assignment file


 qaiser abbas thanks 

pori assign upload kro

Thanx  Little Chef  good efffort done by you but at the end of out put in demo there is combined record of registered candidate too which is not displayung in your output please insert that code too , quickly . May you always be happy

thanx Little Chef

Thank you so much little chef.....Good effort....Keep it up.............Can we some more ideas and solution please

g u r right but ek chez r clear kr dain k kanha changes krain ta k dito copy ka case na bny. r ye k kia ap mje online is course ki tips and guide line dy sakty hain kia ta k m b proficient ho jaon in making ideas and assignment. mje samj nai ati k pehly kia krna r phir kia, either i listened lecture and handouts reading but at the end of making assignment i failed. so pls help me. regards


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

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