Implement With C++ using class .
notes: candidate are 3 types . Use array andqueue, and priority is related with age.
Covid Vaccine registration booth:
1. frontline fighter
2. Citizen over 40 years
3. Student
Candidate info:
1.Name
2.Category
3.Registration no
4. Priority (age)
5. Age
Operation:
1. Registration
2. Show candidate list
3. Search candidate
#include <iostream>
#include <queue>
using namespace std;
struct Candidate {
string name;
int category;
bool register_no;
int age;
};
queue<Candidate> que;
void register()
{
struct Candidate c;
cout << "Name: "; cin >> c->name;
cout << "Category: "; cin >> c->category;
cout << "Register no: "; cin >> c->register_no;
cout << "Age: "; cin >> c->age;
que.push_back(c);
}
void show(struct Candidate c)
{
cout << "---";
cout << c->name << endl;
cout << c->category << endl;
cout << c->register_no << endl;
cout << c->age << endl;
}
struct Candidate search(string name)
{
for (struct Candidate c : que) {
if (c->name == name)
return c;
}
return nullptr;
}
int main()
{
while (true) {
cout << "1) Register" << endl;
cout << "2) Show Candidate List" << endl;
cout << "3) Search" << endl;
string name;
int i;
cin >> i;
switch (i) {
case 1:
register();
break;
case 2:
show();
break;
case 3:
cout << "Name: "; cin >> name;
struct Candidate c = search(name);
if (c) {
cout << c->name << endl;
cout << c->category << endl;
cout << c->register_no << endl;
cout << c->age << endl;
} else {
cout << "Candidate with name '" << name << "' not exists" << endl;
}
break;
default:
cout << "Invalid choice" << endl;
break;
}
}
return 0;
}
Comments
Leave a comment