Need Help

Hello, I am very confused regarding this assignment.

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.
Class Diagram Pic: http://postimg.org/image/gabl3fjxn/

1.Make Voter base/parent class and inherit classes Disable and Overseas from it.

2.In voter class:
a.Make Cast_vote ( ) function a pure virtual function.
b.Login_data() should be a non-virtual function.

3.In Disable class:
a.Make Cast_vote() a virtual function.
b.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.

4.In Overseas class:
a.Make Cast_vote() a virtual function.
b.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.

The output should be like this: http://postimg.org/image/emq7u0a7f/ & http://postimg.org/image/5f1400irb/

I have implemented the code, But it is not accurate and do not fulfill the requirements. Please let me know my mistakes.
Thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <iostream>
#include <conio.h>

using namespace std;

class Voter
{
      private:
              int CNIC_No;
              char Password;
      public:
             virtual void Cast_vote(); // pure virtual function
             void Login_data(){            // non virtual function
                  cout<<"Please Enter Your Password: ";
                  cin>>Password;
                  cout<<"\nPlease Enter Your CNIC#: "<<endl;
                  cin>>CNIC_No;
                  if(CNIC_No!=0)
                  {
                  cout<<"\n\n\nLogin Successful!...";
                  }
                  }
};
      
class Disable: public Voter
{
      private:
             int User_choice;
      public:
             virtual void Cast_vote()          // virtual function
             {
                     Voter::Login_data();      // Login_data() function of the voter
                     cout<<"\n\n*********************************"<<endl;
                     cout<<"\nVote Casting Menu"<<endl;
                     cout<<"*********************************"<<endl;
                     cout<<"\nSelect Your Option: <1 for Bat and 2 for Ball>"<<endl;
                     cout<<"\n1. Bat"<<endl;
                     cout<<"2. Ball"<<endl;
                     cin>>User_choice;
                     if(User_choice == 1){
                               cout<<"Your Vote is successfully casted to Bat."<<endl;
                               }
                     else if(User_choice == 2){
                          cout<<"Your Vote is successfully casted to Ball."<<endl;
                          }
                     else {
                          cout<<"\nPlease select a valid option.";
                          
                          }

             }
};
      
class Overseas: public Voter
{
      private:
              int User_choice;
      public:
              virtual void Cast_vote()          // virtual function
             {
                     Voter::Login_data();     // Login_data() function of the voter
                     cout<<"\n\n*********************************";
                     cout<<"\nVote Casting Menu"<<endl;
                     cout<<"*********************************";
                     cout<<"\nSelect Your Option: <1 for Bat and 2 for Ball>"<<endl;
                     cout<<"1. Bat"<<endl;
                     cout<<"2. Ball"<<endl;
                     cin>>User_choice;
                     if(User_choice == 1){
                               cout<<"Your Vote is successfully casted to Bat."<<endl;
                               }
                     else if(User_choice == 2){
                          cout<<"Your Vote is successfully casted to Ball."<<endl;
                          }
                     else {
                          cout<<"\nPlease select a valid option.";
                          
                          }

                     
             }

};
      
      
      
int main(int argc, const char*argv[])
{
    char choice;
    Voter *voters[25];
    for(int i=0; i<5; i++){
            cout<<"\nDo you want to cast vote? <Y/N> ";
            cin>>choice;
            if(choice=='Y' || choice == 'y'){
               cout<<"\n\n*********************************"<<endl;
               cout<<"Press 'D' or 'd' for disable voter"<<endl;
               cout<<"\nPress 'O' or 'o' for overseas voter"<<endl;
               cout<<"*********************************"<<endl;
               cin>>choice;
               if(choice=='D' || choice=='d'){
                  voters[i] = new Disable();           // Polymorphism
                  voters[i] -> Cast_vote();
               }
               else if(choice=='O' || choice=='o'){
                 voters[i] = new Overseas();              //Polymorphism
                 voters[i] -> Cast_vote();
               }
               else
               {
                  cout<<"\nPlease select a valid option.";
                  --i;
               }
            }
            else if(choice=='N' || choice=='n'){
                 cout<<"\nPress any key to Exit...";
                 }
            break;
    }
    cout<<"\n\nThanks for using this program"<<endl;
    system("pause");
}
For pure virtual function
virtual void Cast_vote()=0; // pure virtual function
The =0 part is important. That means that all derived classes must implement their own Cast_vote

What else is inaccurate?
Ooooops yeah . Thanks for pointing out my mistake. :)

Another problem is that it doesn't repeat the process, Like if we have done casting the vote. It should ask again that either to cast vote again or not. It should repeat the process until we do say it to break the process.
I assume that the break should happen only when you answer N. Take a look at line 117, which right now is executed after you answered either Y or N
Topic archived. No new replies allowed.