Advertisement
Guest User

Untitled

a guest
Oct 4th, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <unistd.h>
  5.  
  6. using namespace std;
  7.  
  8. enum facultet {GUP, GUI, UIR};
  9. const char* const FcltStrings[] = {"ГУП", "ГУИ", "УИР"};
  10.  
  11. class Student
  12. {
  13. private:
  14. string Name, SName;
  15. facultet fclt;
  16. public:
  17. void SetName(string name){
  18. this->Name = name;
  19. }
  20. void SetSName(string sname){
  21. this->SName = sname;
  22. }
  23. void SetFclt(int fclt){
  24. this->fclt = facultet(fclt);
  25. }
  26. string GetName(){
  27. return this->Name;
  28. }
  29. string GetSName(){
  30. return this->SName;
  31. }
  32. void PrintInfo(){
  33. cout << this->GetName() << ' ' << this->GetSName() << ' ' << FcltStrings[this->GetFclt()] << endl;
  34. }
  35. facultet GetFclt(){
  36. return this->fclt;
  37. }
  38. Student(string name, string sname, int fclt){
  39. this->SetFclt(fclt);
  40. this->SetName(name);
  41. this->SetSName(sname);
  42. }
  43. Student(){}
  44. };
  45.  
  46.  
  47. class Candidate:public Student
  48. {
  49. private:
  50. int totalVoices, VoicesInFclt[3];
  51. public:
  52. void AddVoice(int fclt){
  53. this->totalVoices++;
  54. this->VoicesInFclt[fclt]++;
  55. }
  56. Candidate(string name, string sname, int fclt
  57. ):Student(name, sname, fclt){
  58. this->totalVoices = 0;
  59. for(int i = 0; i < 3; i++)
  60. this->VoicesInFclt[i] = 0;
  61. }
  62. int GetVoices(){
  63. return this->totalVoices;
  64. }
  65. int GetFcltVoices(int fclt){
  66. return this->VoicesInFclt[fclt];
  67. }
  68.  
  69. };
  70.  
  71.  
  72. using namespace std;
  73.  
  74. int main()
  75. {
  76. vector<Candidate> candidates;
  77. vector<Student> students;
  78. Candidate cd1("PETR", "MERKULEV", 2);
  79. candidates.push_back(cd1);
  80. Candidate cd2("ANNA", "NESGOVORINA", 1);
  81. candidates.push_back(cd2);
  82.  
  83. while(true){
  84. cout << "Выберите пункт нашего выборного меню" << endl;
  85. cout << "1. Проголосовать." << endl;
  86. cout << "2. Закончить выборы." << endl;
  87. int num;
  88. cin >> num;
  89. if(num != 1 && num != 2){
  90. cout << "Error!" << endl;
  91. usleep(1000);
  92. continue;
  93. }
  94. if(num == 2) break;
  95. string name, sname;
  96. int fclt;
  97. cout << "Введите ваше имя" << endl;
  98. cin >> name;
  99. cout << "Введите фамилию" << endl;
  100. cin >> sname;
  101. cout << "Факультет " << FcltStrings[0] << " - 0 " << FcltStrings[1] << " - 1 " << FcltStrings[2] << " - 2" << endl;
  102. while(1){
  103. cin >> fclt;
  104. if(fclt < 0 || fclt > 2)
  105. cout << "Введите номер факультета еще раз" << endl;
  106. else break;
  107. }
  108. Student st(name, sname, fclt);
  109. students.push_back(st);
  110. for(int i = 0; i < candidates.size(); i++){
  111. cout << "Кандидат №" << i+1 << ' ';
  112. candidates[i].PrintInfo();
  113. }
  114. cout << "Голосуйте! (Выберите номер вашего кандидата)" << endl;
  115. while(1){
  116. cin >> num;
  117. if(num < 0 || num > candidates.size())
  118. cout << "Проголосуйте корректно!" << endl;
  119. else break;
  120. }
  121. num--;
  122. candidates[num].AddVoice(st.GetFclt());
  123. cout << "Спасибо вам" << endl;
  124. }
  125. int totalVoices = 0;
  126. for(int i = 0; i < candidates.size(); i++)
  127. totalVoices += candidates[i].GetVoices();
  128. cout << "Результаты выборов!!!!" << endl;
  129. for(int i = 0; i < candidates.size(); i++){
  130. cout << "Кандидат №" << i+1 << ' ';
  131. candidates[i].PrintInfo();
  132. int cnt = candidates[i].GetVoices();
  133. cout << "Получил голосов: " << cnt << "(" << ((double)cnt / (double)totalVoices)*100.0 << "%)" << endl;
  134. for(int j = 0; j < 3; j++){
  135. int cntFclt = candidates[i].GetFcltVoices(j);
  136. cout << "Факультет " << FcltStrings[j] << ' ' << cntFclt << "(" <<( (double)cntFclt / (double)cnt)*100.0 << "%)" << endl;
  137. }
  138. cout << endl;
  139. }
  140. return 0;
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement