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

Functions

Candidate

CNIC

Integer/Character String

-Default constructor()

 

First_Name

Character String

-Function to overload  stream extraction operator ( >>)

 

Last_Name

Character String

- Function to overload stream      insertion operator ()

 

Sign_Alloted

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

Malika Eman 

Nice work Ap ki sloution file na booth help ki 

Most Welcome Bro...

Yar ye sab k bad bhi copy case hona hai koi guide kare step by step 

Should not lose ur confidence….must try to do it better to better at last moment…it’s not to understanding time to step by step…

 

Malika Eman 

Thanks alote for u Solution File Keep it up Malika Eman 

yar vu valy phly plagiarism detector say file ko check krty hian, agr bhut sari assignment ak jaisi milen to woh sabi to reject kr dety hian .. chund ak bate jo reject hony sy bcha skti hian woh yeh hian.

change the comment section with your own words .. (like in above solution change //..Candidate Class with your own words)

change the variable use .

most important you get the idea here, above is the complete solution just change the wording and your copy case problem solved :)

CS304 Object Oriented Programming Assignment # 4  100% Correct Solution 


Attachments:

//100% Correct Solution...

#include <iostream>
#include <string.h>
using namespace std;
//..Candidate Class
class Candidate
{
//..Atributes
char* cnic;
char* fistName;
char* lastName;
char* signAlloted;
public:
//..Required Operations
Candidate();
friend ostream & operator (ostream& os, const Candidate&);
friend istream & operator >> (istream& is, Candidate&);
bool operator == (const Candidate&);
};
//..Default Constructor
Candidate::Candidate()
{
this->cnic = new char[26];
this->fistName = new char[26];
this->lastName = new char[26];
this->signAlloted = new char[26];
}
//..Stream Inseration
ostream & operator (ostream & os, const Candidate& c)
{
os "\t\t" c.cnic;
os "\t\t" c.fistName;
os "\t\t " c.lastName;
os "\t " c.signAlloted;
return os;
}
//..Stream Extraction
istream & operator >> (istream & is, Candidate& c)
{
cout "\n Enter Your CNIC# :";
is >> c.cnic;
cout "\n Enter Your First- Name :";
is >> c.fistName;
cout"\n Enter Your LastName :";
is >> c.lastName;
cout "\n Enter Sign- Alloted :";
is >> c.signAlloted;
return is;
}
//..Equality Operator
bool Candidate:: operator==(const Candidate & can)
{
bool isEqual = false;
if(!strcmp(this->cnic, can.cnic))
{
cout"\n\n Insertion failed! Record against this CNIC already exists.";
cout"\n\n =====================================================";
return true;
}
if(!strcmp(this->fistName, can.fistName))
{
cout"\n\n Insertion failed! Record against this First Name already exists.";
cout"\n\n =====================================================";
return true;
}
if(!strcmp(this->lastName, can.lastName))
{
cout "\n\n Insertion failed! Record against this Last Name already exists.";
cout "\n\n =====================================================";
return true;
}
if(!strcmp(this->signAlloted, can.signAlloted))
{
cout "\n\n Insertion failed! Record against this Sign already exists.";
cout "\n\n =====================================================";
return true;
}
return false;
}

int main(int argc, const char * argv[])
{

cout "\n ================================================\n";
cout "\n Candidates Registration Interface\n";
cout "\n ================================================\n";
char choice;
cout "\n Do you want to start registration for wanting candidates? (y/n):";
cin >> choice;
if(choice == 'y' || choice == 'Y')
{
int noOfCandidates = 0;
//..get no of candidates and create array.
cout "\n\n Enter No. of candidates to be registered: ";
cin >> noOfCandidates;
Candidate candidates[noOfCandidates];
//..take input for each candidates.
for(int i = 0; i < noOfCandidates; i++)
{
cout"\n\n Enter Candidate " i+1 " Information";
cout"\n\n =====================================================";
cin >> candidates[i];
//..match the input for given cadidate with previous candidates and show messages accordingly.
if(i != 0)
{
for(int j = 0; j < i; j++)
{

if(candidates[i] == candidates[j])
{
//if matches then take the input for this candidate again.
i -= 1;
}
else
{
cout "\n\n Record " i+1 " is sucessfully inserted.";
cout "\n\n =====================================================";
}
}
}
else
{
cout "\n\n Record " i+1" is sucessfully inserted.";
cout "\n\n =====================================================";
}
}
cout "\n\n Do you want to view Candidate's Information (y/n): ";
cin >> choice;
if(choice == 'y' || choice == 'Y')
{
cout "\n\n******************************************************";
cout "\n\n Displaying Registered Candidates Information";
cout "\n\n******************************************************";
cout "\n\n S.No.\t\t CNIC#\t\t Name\t\t Sign Alloted";
//..show the all candidates Information.
for(int i = 0; i < noOfCandidates; i++)
{
cout "\n\n " i+1 candidates[i];
}
cout "\n\n Thanks for using this program "endl;
}
else
{
cout "\n\n Thanks for using this program "endl;
}
}
else
{
cout "\n\n Thanks for using this program "endl;
}
system("pause");
return 0;
}

4th assignment idea solution 
 Dont Copy paste 


How to make changes in this assignment ?  

Changes you can make in program
-First data variables name. Meray data variables kay naam changes hay assignment say. I have firstName there is mention First_Name.
-Change implementation in == overload method. For example hum jantay hain kay strcmp 0 return karta hay agar strings equal ho tu aik check ternay operator ki help say ban sakta hay. Aap yehi pattern next checks kay liya bhi use kar saktay hain.
bool isEqual = false;
isEqual = strcmp(this->cnic, can.cnic) == 0 ? true : false;
if(isEqual)
{
cout "\n\n Insertion failed! Record against this CNIC already exists.";
cout "\n\n =====================================================";
return true;
}
- In main you can change alot. For example main nay for loop use kia hay input kay liya tu aap while use kar saktay hain
int i = 0;
while(true)
{
if(i < noOfCandidates)
{
i++
}
else
{
break;
}
//....For loop body code paste from here ........
cout "\n\n Enter Candidate " i+1 " Information";
cout "\n\n =====================================================";
cin >> candidates[i];
//..match the input for given cadidate with previous candidates and show messages accordingly.
//........Incomplete code here...........
}
for loop ki body is main paste kar dain.
Aap is tarha ki change candidates ki information print karnay kay liya bhi use kar saktay hain. Wah bhi main nay for loop use kia hay. See
for(int i = 0; i < noOfCandidates; i++)
{
cout "\n\n " i+1 candidates[i];
}


------------------------------


#include <iostream>
#include <string.h>
using namespace std;
//..Candidate Class
class Candidate
{
//..Atributes
char* cnic;
char* fistName;
char* lastName;
char* signAlloted;

public:
//..Required Operations
Candidate();
friend ostream & operator (ostream& os, const Candidate&);
friend istream & operator >> (istream& is, Candidate&);
bool operator == (const Candidate&);
};

//..Default Constructor
Candidate::Candidate()
{
this->cnic = new char[25];
this->fistName = new char[25];
this->lastName = new char[25];
this->signAlloted = new char[25];
}
//..Stream Inseration
ostream & operator (ostream & os, const Candidate& c)
{
os "\t\t" c.cnic;
os "\t\t" c.fistName " " c.lastName;
os "\t " c.signAlloted;
return os;
}
//..Stream Extraction
istream & operator >> (istream & is, Candidate& c)
{
cout "\n Enter Your CNIC# :";
is >> c.cnic;
cout "\n Enter Your First Name :";
is >> c.fistName;
cout "\n Enter Your Last Name :";
is >> c.lastName;
cout "\n Enter Sign Alloted :";
is >> c.signAlloted;
return is;
}
//..Equality Operator
bool Candidate:: operator==(const Candidate & can)
{
bool isEqual = false;
if(!strcmp(this->cnic, can.cnic))
{
cout "\n\n Insertion failed! Record against this CNIC already exists.";
cout "\n\n =====================================================";
return true;
}
if(!strcmp(this->fistName, can.fistName))
{
cout "\n\n Insertion failed! Record against this First Name already exists.";
cout "\n\n =====================================================";
return true;
}
if(!strcmp(this->lastName, can.lastName))
{
cout "\n\n Insertion failed! Record against this Last Name already exists.";
cout "\n\n =====================================================";
return true;
}
if(!strcmp(this->signAlloted, can.signAlloted))
{
cout "\n\n Insertion failed! Record against this Sign already exists.";
cout "\n\n =====================================================";
return true;
}
return false;
}


int main(int argc, const char * argv[])
{

cout "\n ================================================\n";
cout "\n Candidates Registration Interface\n";
cout "\n ================================================\n";
char choice;
cout "\n Do you want to start registration for wanting candidates? (y/n):";
cin >> choice;
if(choice == 'y' || choice == 'Y')
{
int noOfCandidates = 0;
//..get no of candidates and create array.
cout "\n\n Enter No. of candidates to be registered: ";
cin >> noOfCandidates;
Candidate candidates[noOfCandidates];
//..take input for each candidates.
for(int i = 0; i < noOfCandidates; i++)
{
cout "\n\n Enter Candidate " i+1 " Information";
cout "\n\n =====================================================";
cin >> candidates[i];
//..match the input for given cadidate with previous candidates and show messages accordingly.
if(i != 0)
{
for(int j = 0; j < i; j++)
{

if(candidates[i] == candidates[j])
{
//if matches then take the input for this candidate again.
i -= 1;
}
else
{
cout "\n\n Record " i+1 " is sucessfully inserted.";
cout "\n\n =====================================================";
}
}
}
else
{
cout "\n\n Record " i+1 " is sucessfully inserted.";
cout "\n\n =====================================================";
}
}
cout "\n\n Do you want to view Candidate's Information (y/n): ";
cin >> choice;
if(choice == 'y' || choice == 'Y')
{
cout "\n\n******************************************************";
cout "\n\n Displaying Registered Candidates Information";
cout "\n\n******************************************************";
cout "\n\n S.No.\t\t CNIC#\t\t Name\t\t Sign Alloted";
//..show the all candidates Information.
for(int i = 0; i < noOfCandidates; i++)
{
cout "\n\n " i+1 candidates[i];
}
cout "\n\n Thanks for using this program " endl;
}
else
{
cout "\n\n Thanks for using this program " endl;
}

}
else
{
cout "\n\n Thanks for using this program " endl;
}
system("pause");
return 0;
}

error aa raha hay system ("pause");

RSS

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

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