https://www.google.com/contributor/welcome/?utm_source=publisher&utm_medium=banner&utm_campaign=2376261057261409

Search This Blog

Search with our Site

Custom Search

Monday, June 24, 2013

CS304 Object Oriented Programming Assignment # 4 100% Correct Solution



//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;
}


No comments:

Post a Comment