Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <unistd.h>
- using namespace std;
- enum facultet {GUP, GUI, UIR};
- const char* const FcltStrings[] = {"ГУП", "ГУИ", "УИР"};
- class Student
- {
- private:
- string Name, SName;
- facultet fclt;
- public:
- void SetName(string name){
- this->Name = name;
- }
- void SetSName(string sname){
- this->SName = sname;
- }
- void SetFclt(int fclt){
- this->fclt = facultet(fclt);
- }
- string GetName(){
- return this->Name;
- }
- string GetSName(){
- return this->SName;
- }
- void PrintInfo(){
- cout << this->GetName() << ' ' << this->GetSName() << ' ' << FcltStrings[this->GetFclt()] << endl;
- }
- facultet GetFclt(){
- return this->fclt;
- }
- Student(string name, string sname, int fclt){
- this->SetFclt(fclt);
- this->SetName(name);
- this->SetSName(sname);
- }
- Student(){}
- };
- class Candidate:public Student
- {
- private:
- int totalVoices, VoicesInFclt[3];
- public:
- void AddVoice(int fclt){
- this->totalVoices++;
- this->VoicesInFclt[fclt]++;
- }
- Candidate(string name, string sname, int fclt
- ):Student(name, sname, fclt){
- this->totalVoices = 0;
- for(int i = 0; i < 3; i++)
- this->VoicesInFclt[i] = 0;
- }
- int GetVoices(){
- return this->totalVoices;
- }
- int GetFcltVoices(int fclt){
- return this->VoicesInFclt[fclt];
- }
- };
- using namespace std;
- int main()
- {
- vector<Candidate> candidates;
- vector<Student> students;
- Candidate cd1("PETR", "MERKULEV", 2);
- candidates.push_back(cd1);
- Candidate cd2("ANNA", "NESGOVORINA", 1);
- candidates.push_back(cd2);
- while(true){
- cout << "Выберите пункт нашего выборного меню" << endl;
- cout << "1. Проголосовать." << endl;
- cout << "2. Закончить выборы." << endl;
- int num;
- cin >> num;
- if(num != 1 && num != 2){
- cout << "Error!" << endl;
- usleep(1000);
- continue;
- }
- if(num == 2) break;
- string name, sname;
- int fclt;
- cout << "Введите ваше имя" << endl;
- cin >> name;
- cout << "Введите фамилию" << endl;
- cin >> sname;
- cout << "Факультет " << FcltStrings[0] << " - 0 " << FcltStrings[1] << " - 1 " << FcltStrings[2] << " - 2" << endl;
- while(1){
- cin >> fclt;
- if(fclt < 0 || fclt > 2)
- cout << "Введите номер факультета еще раз" << endl;
- else break;
- }
- Student st(name, sname, fclt);
- students.push_back(st);
- for(int i = 0; i < candidates.size(); i++){
- cout << "Кандидат №" << i+1 << ' ';
- candidates[i].PrintInfo();
- }
- cout << "Голосуйте! (Выберите номер вашего кандидата)" << endl;
- while(1){
- cin >> num;
- if(num < 0 || num > candidates.size())
- cout << "Проголосуйте корректно!" << endl;
- else break;
- }
- num--;
- candidates[num].AddVoice(st.GetFclt());
- cout << "Спасибо вам" << endl;
- }
- int totalVoices = 0;
- for(int i = 0; i < candidates.size(); i++)
- totalVoices += candidates[i].GetVoices();
- cout << "Результаты выборов!!!!" << endl;
- for(int i = 0; i < candidates.size(); i++){
- cout << "Кандидат №" << i+1 << ' ';
- candidates[i].PrintInfo();
- int cnt = candidates[i].GetVoices();
- cout << "Получил голосов: " << cnt << "(" << ((double)cnt / (double)totalVoices)*100.0 << "%)" << endl;
- for(int j = 0; j < 3; j++){
- int cntFclt = candidates[i].GetFcltVoices(j);
- cout << "Факультет " << FcltStrings[j] << ' ' << cntFclt << "(" <<( (double)cntFclt / (double)cnt)*100.0 << "%)" << endl;
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement