Virtual Position Forum
Please register to watch content in detail
Thanks
Admin virtual position


Join the forum, it's quick and easy

Virtual Position Forum
Please register to watch content in detail
Thanks
Admin virtual position
Virtual Position Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

CS304 Assignment #3 Solution Spring 2013

View previous topic View next topic Go down

GMT + 8 Hours CS304 Assignment #3 Solution Spring 2013

Post by Victoria333 Sun May 19, 2013 12:43 pm

CS304 Object Oriented Programming.Assignment No. 3 Solution Spring Semester 2013


Assignment No. 03
SEMESTER Spring 2013
CS304- Object Oriented Programming Total Marks: 20
Due Date: 20/05/2013
Instructions
Please read the following instructions carefully before solving & submitting assignment:
It should be clear that your assignment will not get any credit (zero marks) if:
o The assignment is submitted after due date.
o The submitted assignment is other than .cpp file.
o The submitted assignment does NOT open or file is corrupted.
o The assignment is copied (from other student or ditto copy from handouts or internet).
Uploading instructions

o For clarity and simplicity, you are required to Upload/Submit only .CPP file
Objective
The objective of this assignment is:

o To give you the idea of practical implementation of some concepts like, definition of classes, Data members, member functions, Aggregation, Composition, Constructors etc.

For any query about the assignment, contact at [You must be registered and logged in to see this link.]
GOOD LUCK
Marks: 20
Composition and Aggregation is an important relationship between objects in object oriented paradigm. Consider the following class diagram, which shows some classes and their relationship (Composition and Aggregation), while the detail of classes is given in the table
Class Name Attribute Name Attribute Data Type Functions
Sign Name Character String -Constructor
-Getters and Setters
Candidate Name Character String -Default constructor()
Votes_obtain Integer -Overloaded Constructor
sign Sign -Getters and Setters
-Count_votes()
Constituency ConNo Character String -Default constructor()
Candidate_name Cadidate -Overloaded Constructor
-Getters and Setters
Result DayOf_result Character String -Default constructor
-Getters and Setters
-compile_result()
VB_Paper CanName Candidate -Default constructor
res Result -Overloaded Constructor
-Getters and Setter
-Get_result()
You are required to implement this class diagram (Write complete program) in to C++ with all functions and concepts (Aggregation and composition) given in the class diagram/table.

You need to consider that there may be two or more than two candidates who can contest in the constituency.

Details of important Member functions:
Count_votes(): This function will count votes of each candidate.
compile_result() : This function will Compile (calculate) the result of the contesting candidates.
Get_result(): This function will get/show result from the Result class through the part object “res” of the VB_Paper class.
Output:
Lectures Covered: This assignment covers Lecture # 07-15
Deadline: Your assignment must be uploaded/submitted at or before. May 20, 2013
Victoria333
Victoria333
Monstars
Monstars

Scorpio Snake
Posts : 267
Join date : 2013-05-12
Age : 34
Location : Victoria
Woot

Back to top Go down

GMT + 8 Hours Re: CS304 Assignment #3 Solution Spring 2013

Post by Victoria333 Sun May 19, 2013 12:44 pm

Final Solution of CS304 Assignment No 3
Code:
#include <iostream>
using std::cin;
using std::cout;
using std::endl;

#include <string>
using std::string;

//Implementation of the sing class.....................
class Sign {
private:
string voterSign;
public:

void setSign(string _voterSign) {
voterSign = _voterSign;
}
string getSign() const {
//coutvoterSign;
return voterSign;
}
};
//End of the sign class.................................

//Implementing the candidate class......................
class Candidate {
private:
string Name;
int numberOfVotes;

public:
Sign candidateSign;
Candidate() {
Name = "";
numberOfVotes = 0;
candidateSign.setSign("");
}

Candidate(string _name, int _votes, string sign) {
Name = _name;
numberOfVotes = _votes;
candidateSign.setSign(sign);
}
void incrementVotes() {
numberOfVotes++;
}
int getVotes()const {
return numberOfVotes;
}
void setCandidateName(string _name){
Name = _name;
}
string getCandidateName()const{
return Name;
}

};
//End of the candidate class..........................

//Implementation of constituency class................
class Constituency {
private:
int numberOfCandidates;
int numberOfVoters;
string constituencyName;

public:
Candidate* Candidates;
Constituency() {
numberOfCandidates = 2;
numberOfVoters = 350;
constituencyName = "NA-63";
Candidates = new Candidate[numberOfCandidates];
setCandidateInfo();
}

string getConstituencyName() {
return constituencyName;
}
void displayConstituencyInfo() {
cout"\nConstituency Name\t"getConstituencyName()
"\nNumber of Candidates\t"numberOfCandidates"\nRegistered Voters\t"
numberOfVoters"\n\n";
displayCandidateInfo();
}
void setCandidateInfo() {
//setting first Candidates data
Candidates[0].setCandidateName("Imran Khan");
Candidates[0].candidateSign.setSign("Bat");

//setting data for the second candidate
Candidates[1].setCandidateName("Iqbal Mehdi");
Candidates[1].candidateSign.setSign("Lion");

//coutCandidates[1].getCandidateSign()"\t";
//Candidates[2].getVotes()"\n";*/
}
void displayCandidateInfo() {
cout"\nCandidate Name\tSign\n";
coutCandidates[0].getCandidateName()"\t"
Candidates[0].candidateSign.getSign()"\n";

coutCandidates[1].getCandidateName()"\t"
Candidates[1].candidateSign.getSign()"\n";

}
void showVotingMenu() {
for(int i=0; i<numberOfCandidates;i++) {
cout"Type in "i+1" for "Candidates[i].getCandidateName()
"\t "Candidates[i].candidateSign.getSign()"\n";
}
}
void pollVote(int optionNumber) {
Candidates[optionNumber-1].incrementVotes();
}



};
//End of the constituency class implementation

//implementation of result class
class Result {
private:
string resultDay;

public:
Constituency NA;
Result(): resultDay("May 11, 2013")
{}
void compileResult() {
string winner, sign;
int votes;
if(NA.Candidates[0].getVotes()>NA.Candidates[1].getVotes()) {
winner = NA.Candidates[0].getCandidateName();
votes = NA.Candidates[0].getVotes();
sign = NA.Candidates[0].candidateSign.getSign();
}
else {
winner = NA.Candidates[1].getCandidateName();
votes = NA.Candidates[1].getVotes();
sign = NA.Candidates[1].candidateSign.getSign();
}
displayWinner(winner, votes, sign);
}
void displayWinner(string name, int votes, string sign) {
if(votes!=0){
cout"\nOfficial Results announced on "resultDay
"\nWinner from this constituency is "name
" with the sign *"sign"\nHe obtained "votes" votes\n\n";
}
else {
cout"\n No votes polled yet.";
}
}
};

int main() {
string constituencyName;
char choice;
int optionNumber;
Result R1;
cout"Online VOTING [National Assembly]\n"
"\nType in the Constituency Name [NA-63].";
getline(cin,constituencyName);
while(constituencyName!= "NA-63") {
cout"Type in the correct constituency name";
getline(cin,constituencyName);
}
R1.NA.displayConstituencyInfo();
do {
cout"\nDo you wish to vote for a candidate? [y/n] ";
cin>>choice;
if(choice=='y') {
R1.NA.showVotingMenu();
cin>>optionNumber;
R1.NA.pollVote(optionNumber);
}

}while(choice!='n');

cout"Do you wish to see the results? [y/n]";
cin>>choice;
if(choice=='y') {
R1.compileResult();
}
system("pause");
return 0;
}
Victoria333
Victoria333
Monstars
Monstars

Scorpio Snake
Posts : 267
Join date : 2013-05-12
Age : 34
Location : Victoria
Woot

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

Permissions in this forum:
You cannot reply to topics in this forum