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.


Assignment No. 05
SEMESTER Spring 2013
CS304- Object Oriented Programming

Total Marks: 20

Due Date: 05/07/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:

  • The assignment is submitted after due date.
  • The submitted assignment is other than .cpp file.
  • The submitted assignment does NOT open or file is corrupted.
  • The assignment is copied (from other student or ditto copy from handouts or internet).

Uploading instructions

 

  • For clarity and simplicity, you are required to Upload/Submit only .CPP file

Objective

The objective of this assignment is:

 

  • To give you the idea of practical implementation of concepts inheritance and polymorphism.

 

For any query about the assignment, contact at CS304@vu.edu.pk

GOOD LUCK

 

Marks: 20 

Consider the following Class Diagram; detailed description of the diagram is given in the table.

 

Class Name

Attribute Name

Attribute Data Type

Behavior (Functions)

Voter

Password

Character String

-Default Constructor()

-Login _data()

-Cast_vote()

CNIC_No

Integer

Disable

 

 

-Cast_vote()

Overseas

 

 

-Cast_vote()

 

 

In given class diagram, voter is a base class; while Disable and Overseas is its derived classes sharing its all attributes and functions.

 

You are required to implement the above class diagram in C++. For this you have to use the concept of inheritance and polymorphism. In order to cast vote, your program should be able to produce different interfaces for each category of voter e.g. interface for disable voter should be different from the interface of overseas voter.

 

Solution Guidelines:

 

  1. Make Voter base/parent class and inherit classes Disable and Overseas from it.
  2. In voter class:
    1. Make Cast_vote ( ) function a pure virtual function.
    2. Login_data() should be a  non-virtual function.

 

  1. In Disable class:
    1. Make Cast_vote() a virtual function.
    2. Login_data( ) function of disable class should generate an interface that would help disable voters to cast their vote easily. In the body of this function, you also have to call Login_data() function of Voter.

 

  1. In Overseas class:
    1. Make Cast_vote() a virtual function.
    2. Cast_vote()  function of overseas class should generate an interface that would help overseas voters to cast their vote easily. In the body of this function, you also have to call Login_data() function of Voter

Sample Output:

 

 

Lectures Covered:  This assignment covers Lecture #   22-31

Deadline:             Your assignment must be uploaded/submitted at or before. 5th July , 2013

 

Views: 7293

Attachments:

Replies to This Discussion

 Little Chef ka solution our modify kr dyea ha Best Of luck

Attachments:

 Little Chef bro hum VU family hain as kyea father & mother of this site  M.Tariq Malik & 

+ ıllıllı Amel ıllıllı + and we r all Child of this site I love My VU Family 

wrong.. is m voting k liay time  to deta he ni. khud he cast kr deta jesy n league ny ki. lolz

best for PMLN

Kindly check and tell if any mistake

//  main.cpp

#include <iostream>
using namespace std;

//...Class Voter
class Voter
{
private:
    char password[25];
    int cnic;
public:
    virtual void castVote() = 0; //...Pure Virtual Function
    //..Login Data Funtion will take input
    void loginData()
    {
        cout " \n Please Enter your password: ";
        cin >> password;
        cout " \n Please enter your cnic: ";
        cin >> cnic;
        
        cout "\n Login Successfull!";
    }
};

//..Class Disable Publicly Inherited from Voter
class Disable : public Voter
{
    //implementing the castVote method
    void castVote()
    {
        //calling the voter loginData method
        Voter::loginData();
        int voteNo = 0;
        cout "\n Vote Casting Menu\n";
        cout "\n 1. Button1";
        cout "\n 2. Button2";
        cout "\n Type 1 for press button 1 (for Bat) and type 2 to press button 2 (for Ball): ";
        cin >> voteNo;
        if(voteNo == 1)
        {
            cout "\n Your vote is successfully to casted to Bat.";
        }
        else if(voteNo == 2)
        {
            cout "\n Your vote is successfully to casted to Ball.";
            
        }
        
    }
    
};

//..Class Overseas Publicly Inherited from Voter
class Overseas : public Voter
{
    //implementing the castVote method
    void castVote()
    {
        
        //calling the voter loginData method
        Voter::loginData();
        int voteNo = 0;
        cout "\n Vote Casting Menu\n";
        cout "\n Select your option: (1 for Bat and 2 for Ball)\n";
        cout "\n 1. Bat";
        cout "\n 2. Ball\n";
        cin >> voteNo;
        if(voteNo == 1)
        {
            cout "\n Your vote is successfully to casted to Bat.";
        }
        else if(voteNo == 2)
        {
            cout "\n Your vote is successfully to casted to Ball.";
            
        }

    }
};


///.... Main
int main(int argc, const char * argv[])
{
    char choice;
    Voter *voters[5];
    for (int i = 0; i < 5; i++)
    {
        cout "\n\n Do you want to cast vote (Y/N): ";
        cin >> choice;
        if(choice == 'Y' || choice == 'y')
        {
            cout "\n\n Press D or d for disable voter.";
            cout "\n\n Press O or o for overseas voter.\n";
            cin >> choice;
            if (choice == 'D' || choice == 'd')
            {
                voters[i] = new Disable();
                //here comes the polymorphism. The correct method based on the underlying object will be called.
                voters[i]->castVote();
            }
            else if (choice == 'O' || choice == 'o')
            {
                voters[i] = new Overseas();
                //here comes the polymorphism. The correct method based on the underlying object will be called.
                voters[i]->castVote();
                
            }
            else
            {
                cout "\n\n Incorrect option.\n";
                --i;
            }
        }
        else if(choice == 'N' || choice == 'n')
        {
            cout "\n Press any key to Exit... ";
            break;
        }
        else
        {
            break;
        }
    }
    cout  "\n\n Thanks for using this program.\n\n";
    
    system("pause");
    
    return 0;
}

// Changed Vote Cast Method and Override the loginData method in disable and overseas voter.

#include <iostream>
using namespace std;

//...Class Voter
class Voter
{
private:
char password[25];
int cnic;
public:
virtual void castVote() = 0; //...Pure Virtual Function
//..Login Data Funtion will take input
void loginData()
{
cout " \n Please Enter your password: ";
cin >> password;
cout " \n Please enter your cnic: ";
cin >> cnic;
cout "\n Login Successfull!";
}
};

//..Class Disable Publicly Inherited from Voter
class Disable : public Voter
{
//overriding the loginData()
void loginData()
{
Voter::loginData();
int voteNo = 0;
cout "\n Vote Casting Menu\n";
cout "\n 1. Button1";
cout "\n 2. Button2";
cout "\n Type 1 for press button 1 (for Bat) and type 2 to press button 2 (for Ball): ";

cin >> voteNo;
if(voteNo == 1)
{
cout "\n Your vote is successfully to casted to Bat.";
}
else if(voteNo == 2)
{
cout "\n Your vote is successfully to casted to Ball.";

}
}
//implementing the castVote method
void castVote()
{
//calling the loginData method
loginData();
}

};

//..Class Overseas Publicly Inherited from Voter
class Overseas : public Voter
{

//Overriding the LoginData()
void loginData()
{
Voter::loginData();
int voteNo = 0;
cout "\n Vote Casting Menu\n";
cout "\n Select your option: (1 for Bat and 2 for Ball)\n";
cout "\n 1. Bat";
cout "\n 2. Ball\n";
cin >> voteNo;
if(voteNo == 1)
{
cout "\n Your vote is successfully to casted to Bat.";
}
else if(voteNo == 2)
{
cout "\n Your vote is successfully to casted to Ball.";

}
}
//implementing the castVote method
void castVote()
{

//calling the loginData method
loginData();

}
};


///.... Main
int main(int argc, const char * argv[])
{
char choice;
Voter *voters;
while (true)
{
cout "\n\n Do you want to cast vote (Y/N): ";
cin >> choice;
if(choice == 'Y' || choice == 'y')
{
cout "\n\n Press D or d for disable voter.";
cout "\n\n Press O or o for overseas voter.\n";
cin >> choice;
if (choice == 'D' || choice == 'd')
{
voters = new Disable();
//here comes the polymorphism. The correct method based on the underlying object will be called.
voters->castVote();
}
else if (choice == 'O' || choice == 'o')
{
voters = new Overseas();
//here comes the polymorphism. The correct method based on the underlying object will be called.
voters->castVote();

}
else
{
cout "\n\n Incorrect option.\n";
}
}
else if(choice == 'N' || choice == 'n')
{
cout "\n Press any key to Exit... ";
break;
}
else
{
break;
}
}
cout "\n\n Thanks for using this program.\n\n";
return 0;
}

#include <iostream>
using namespace std;

class Voters
{
private:
int cnic;
char pswrd[20];
int voteno;
public:
virtual void CastVote() = 0;
void logInData()

{
cout " \n Please Enter your CNIC: ";
cin >> cnic;
cout " \n Please Enter your password: ";
cin >> pswrd;
cout "\n Login Successful!...";
cout "\n*************************************\n";
}
};
class Disable : public Voters
{
void CastVote()

Voters::logInData();
int voteno = 0;
cout "\n Vote Casting Menu\n";
cout "\n*************************************\n";
cout "\n\n 1. Button1";
cout "\n\n 2. Button2";
cout "\n Type 1 to press button 1 (for BAT) and type 2 to press button 2 (for BALL): \n";
cin >> voteno;
if(voteno == 1)
{
cout "\n Your vote is successfully casted to BAT.\n";
}
else if(voteno == 2)
{
cout "\n Your vote is successfully casted to BALL. \n";
}
}
};
class Overseas : public Voters
{
void CastVote()
{
Voters::logInData();
int voteno = 0;

cout "\n Vote Casting Menu\n";
cout "\n*************************************\n";
cout "\n Select your option: (1 for BAT and 2 for BALL)\n";
cout "\n 1. BAT \n";
cout "\n 2. BALL \n";
cin >> voteno;
if(voteno == 1)
{
cout "\n Your vote is successfully casted to BAT \n";
}
else if(voteno == 2)
{
cout "\n Your vote is successfully casted to BALL \n";
}
}
};
int main(int argc, const char * argv[])
{
char select;
Voters *voters[7];
for (int i = 0; i < 7; i++)
{
cout "\n Do you want to cast vote <Y/N>? \n";
cin >> select;
if(select == 'Y' || select == 'y')
{
cout "\n Press 'D' or 'd' for disable voter. \n";
cout "\n Press 'O' or 'o' for overseas voter.\n";
cin >> select;
cout "\n*************************************\n";
if (select == 'D' || select == 'd')
{
voters[i] = new Disable();
voters[i]->CastVote();
}
else if (select == 'O' || select == 'o')
{
voters[i] = new Overseas();
voters[i]->CastVote();
}
else
cout "\n Incorrect Option.\n";
}
}
else if(select == 'N' || select == 'n')
{
cout "\n Press any key to Exit... \n";
break;
}
else
{
break;
}
}
cout "\n Thanks for using this program... \n";

system("pause");

return 0;
}



























































nt 100% corct

RSS

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

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