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: 7334

Attachments:

Replies to This Discussion

see the following solution    

Attachments:

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

Irfan khan thanks for sharing..keep it up 

Attention Students: You don’t need to go any other site for this assignment/GDB/Online Quiz solution, Because All discussed data of our members in this discussion are going from here to other sites. You can judge this at other sites yourself. So don’t waste your precious time with different links.

Here is the idea, 

Not 100 % identical in output as required in assignment. Just idea, to avoid to have copy case.

Anyone can make the identical output as required in assignment using cout.

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

#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\Zoya mcs ....Vulearners.com\n\n";

   cout  "\n\n Thanks for using this program.\n\n";
    
    system("pause");
    
    return 0;

#include<iostream.h>
#include<conio.h>
class base
{
    public:
      virtual void show()
      {
                cout"\n  Base class show:";
      }
      void display()
      {
              cout"\n  Base class display:" ;
      }
};
 
class drive:public base
{
   public:
      void display()
      {
              cout"\n  Drive class display:";
      }
      void show()
      {
              cout"\n  Drive class show:";
      }
};
 
void main()
{
   clrscr();
   base obj1;
   base *p;
   cout"\n\t P points to base:\n"  ;
 
   p=&obj1;
   p->display();
   p->show();
 
   cout"\n\n\t P points to drive:\n";
   drive obj2;
   p=&obj2;
   p->display();
   p->show();
   getch();
}

Voter Class base class hay. Is main cast_Vote() pure virtual function hay, is ki body nahi ho gi. Is method ko hum child classes disable or overseas mein override karin gain. Login_data() kay method mein hum user say uskay password or cnic number ki input lain gain or yeah non virtual ho ga. 

Example could be

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 "Please Enter your password :";

        cin >> password;

        cout "Please enter your cnic";

        cin >> cnic;

    }

};

CS304-Object Oriented Programming Assignment No.5 Final Solution

#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;

}

sir! the above codes do not take input for "password" and "cast vote". please help regarding this problem.

Dear Students,

The assignment no. 5 file has a typing mistake as highlighted below, 

 

  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.

 

Students are required to read the above paragraph (highlighted) as follows,

 

3.      In Disable class:

a.       Make Cast_vote() a virtual function.

b.      Cast_vote() 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.

 

 

Note:  Those students who have already submitted their assignments will NOT be suffered.

 

Regards,

tariq bhi iss m eeror  aa raha h

RSS

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

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