CS304 Assignment #3 Solution Spring 2013
Page 1 of 1 • Share
CS304 Assignment #3 Solution Spring 2013
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
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- Monstars
-
Posts : 267
Join date : 2013-05-12
Age : 35
Location : Victoria
Re: CS304 Assignment #3 Solution Spring 2013
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- Monstars
-
Posts : 267
Join date : 2013-05-12
Age : 35
Location : Victoria
Similar topics
» CS304- Object Oriented Programming Assignment # 1 Solution Semester Fall 2013
» CS609 Assignment # 02 Solution Spring 2013
» CS614 Assignment # 3 Solution Spring 2013
» CS614 Assignment # 2 Solution Spring 2013
» MGMT627 - Assignment No. 01 Solution Spring 2013
» CS609 Assignment # 02 Solution Spring 2013
» CS614 Assignment # 3 Solution Spring 2013
» CS614 Assignment # 2 Solution Spring 2013
» MGMT627 - Assignment No. 01 Solution Spring 2013
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Yesterday at 12:21 pm by ali001
» Hemangiom'App
Tue Nov 05, 2024 11:25 am by ali001
» MindfulMe - Mental Health App
Mon Nov 04, 2024 10:50 am by ali001
» Learn Candlestick Patterns
Tue Oct 15, 2024 5:51 am by ali001
» Woh Pagal Si Episode 52 to 62 - Top Pakistani Drama
Sat Sep 21, 2024 6:26 pm by Mir Emmad Ali Khan Domki
» Nearu - share your socials
Sat Sep 21, 2024 1:12 pm by ali001
» Nightclub Tycoon: Idle Empire
Thu Sep 19, 2024 9:16 pm by ali001
» Carnivore - Meat Diet Recipes
Wed Sep 18, 2024 2:37 pm by ali001
» Eid Milad un Nabi Mubarak 2024 (Rabiʻ I 14, 1446 AH)
Tue Sep 17, 2024 3:44 pm by Mir Emmad Ali Khan Domki