-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvoter.cpp
More file actions
145 lines (135 loc) · 4.47 KB
/
voter.cpp
File metadata and controls
145 lines (135 loc) · 4.47 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include "voter.h"
#include <fstream>
#include <iostream>
using std::ifstream;
using std::ios;
using std::ofstream;
extern void GetVoterId();
extern int voterId;
extern int stateCount;
extern void funHeading(const std::string &heading);
extern void GetStateCount();
extern int countDigits(int a);
extern int cityCount;
extern void GetCityCount();
extern void setVoterId();
Voter::Voter() {
partyId = 0;
age = 18;
voterID = 0;
strcpy(partyName, "null");
strcpy(voterName, "null");
setPassword("1234");
setstateId(0);
setCityId(0);
setstateName("NoName");
setcityName("NoName");
}
void Voter::getVoterInfo() {
GetVoterId();
voterID = ++voterId;
std::cout << "\n\n Your Id : " << voterID;
std::cin.ignore();
std::cout << "\n\n Enter Your Name : ";
std::cin.getline(voterName, 24);
std::cout << "\n Enter Your Age : ";
std::cin >> age;
std::cout << "\n Enter Your Gender(M/F) : ";
std::cin >> gender;
GetStateCount();
int sr;
State bs1[stateCount];
do {
funHeading("Creating Voter Account : ");
std::cout << "\n\n Your Id : " << voterID;
std::cout << "\n\n Enter Your Name : " << voterName;
std::cout << "\n\n Enter Your Age : " << age;
std::cout << "\n\n Enter Your Gender(M/F) : " << gender << "\n\n";
std::cout << "\n S.No. State\n\n";
for (int i = 0; i < stateCount; i++) {
bs1[i].getStates(i);
std::cout << " " << i + 1 << ".";
int j = countDigits(i + 1);
for (int k = j; k < 8; k++)
std::cout << " ";
bs1[i].showStateInfo();
}
std::cout << "\n Choose Your State (S.No) : ";
std::cin >> sr;
if (sr <= 0 || sr > stateCount) {
std::cout << "\n Invalid Choice!";
}
} while (sr <= 0 || sr > stateCount);
setstateId(bs1[sr - 1].getstateId());
setstateName(bs1[sr - 1].getstateName().c_str());
GetCityCount();
City cs1[cityCount];
do {
funHeading("Creating Voter Account : ");
std::cout << "\n\n Your Id : " << voterID;
std::cout << "\n\n Enter Your Name : " << voterName;
std::cout << "\n\n Enter Your Age : " << age;
std::cout << "\n\n Enter Your Gender(M/F) : " << gender;
std::cout << "\n\n Select Your State : " << getstateName()
<< "\n\n";
std::cout << std::endl << " S.No. City\n\n";
for (int i = 0; i < cityCount; i++) {
cs1[i].getCity(i);
if (cs1[i].getstateId() == getstateId()) {
std::cout << " " << i + 1 << ".";
int j = countDigits(i + 1);
for (int k = j; k < 8; k++)
std::cout << " ";
cs1[i].showCityInfo();
}
}
std::cout << "\n Choose Your City (S.No) : ";
std::cin >> sr;
if (sr <= 0 || sr > cityCount) {
std::cout << "\n Invalid Choice!";
}
} while (sr <= 0 || sr > cityCount);
setCityId(cs1[sr - 1].getcityId());
setcityName(cs1[sr - 1].getcityName().c_str());
funHeading("Creating Voter Account : ");
std::cout << "\n\n Your Id : " << voterID;
std::cout << "\n\n Enter Your Name : " << voterName;
std::cout << "\n\n Enter Your Age : " << age;
std::cout << "\n\n Enter Your Gender(M/F) : " << gender;
std::cout << "\n\n Select Your State : " << getstateName();
std::cout << "\n\n Select Your City : " << getcityName()
<< "\n\n";
partyId = 0;
strcpy(partyName, "null");
setLeadCandidateId(0);
char arr[10], cr;
std::cout << "\n Enter the Password : ";
std::string password;
do {
std::getline(std::cin >> std::ws, password);
if (password.length() > 10) {
std::cout << "Password Length cannot be more than 10." << std::endl;
}
} while (password.length() > 10);
setPassword(password.c_str());
setVoterId();
}
void Voter::getVoter(int x) {
int i = 0;
ifstream finVoterRecord;
finVoterRecord.open("voter.txt", ios::in | ios::binary);
if (!finVoterRecord) {
std::cout << "\n File not Found";
} else {
while (!finVoterRecord.eof() && i != x + 1) {
finVoterRecord.read(reinterpret_cast<char *>(this), sizeof(*this));
i++;
}
}
}
void Voter::storeVoter() {
ofstream foutVoter;
foutVoter.open("voter.txt", ios::app | ios::binary);
foutVoter.write(reinterpret_cast<char *>(this), sizeof(*this));
foutVoter.close();
}