thinhckhcmus

Cách Code Liên Quan Đến file( Con Chỏ Chỉ Vị )

Oct 11th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. <<<<<<<<<<<<<<<<<<<BinhChon.h>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  2. #pragma once
  3. #include <iostream>
  4. #include <string>
  5. #include <conio.h>
  6. #define _CRT_SECURE_NO_WARNINGS
  7. using namespace std;
  8. class BinhChon
  9. {
  10. private:
  11. string TimeStart;
  12. string TimeEnd;
  13.  
  14. string TimeStart1min;
  15. string TimeEnd1min;
  16.  
  17. string Hour;
  18. string Minnute;
  19. string Vote_Code;// mã số bình chọn
  20. string Vote_NameSinger;// Tên Ca Sĩ Bình Chọn;
  21. public:
  22. int Getter_TimeStart();
  23. int Getter_TimeStart1min();
  24.  
  25. int Getter_TimeEnd();
  26. int Getter_TimeEnd1min();
  27.  
  28. int Getter_Hour();
  29. int Getter_Minnute();
  30. string Getter_Vote_Code();
  31. string Getter_Vote_NameSinger();
  32. public:
  33. void EnterTheTime();
  34. bool CheckTime();
  35. void input();
  36. BinhChon();
  37. ~BinhChon();
  38. };
  39. <<<<<<<<<<<<<<<<<<<<<<<<BinhChon.cpp>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  40. #include "BinhChon.h"
  41. void BinhChon::input()
  42. {
  43. cin >> Vote_Code;
  44. //cin.seekg(1, cin.cur);
  45. getline(cin, Vote_NameSinger, '\n');// nhập tên ca sĩ;
  46. Vote_NameSinger = Vote_NameSinger.substr(0, Vote_NameSinger.size() - 6);
  47. cin.seekg(-7, cin.cur);
  48. getline(cin, Hour, ':');// nhập giờ:
  49. //Hour.substr(0, 1);
  50. getline(cin, Minnute, '\n');// nhập phút:
  51. //Minnute.substr(0, 1);
  52. }
  53. void BinhChon::EnterTheTime()
  54. {
  55. getline(cin, TimeStart, ':');// giờ bắt đầu
  56. getline(cin, TimeStart1min, ' ');//phút bắt đầu
  57. getline(cin, TimeEnd, ':');// giờ kết thúc
  58. getline(cin, TimeEnd1min);// phút kết thúc
  59.  
  60. }
  61. bool BinhChon::CheckTime()
  62. {
  63. int a = (Getter_TimeStart() * 60) + Getter_TimeStart1min(); // giờ bắt đầu + phút bắt đầu
  64. int b = (Getter_TimeEnd() * 60) + Getter_TimeEnd1min();// giờ kết thúc + phút kết thúc
  65. int temp = (Getter_Hour() * 60) + Getter_Minnute();// giờ + phút hiện tại
  66. if (temp >= a && temp <= b) // duyệt a và b nếu thời gian hiện nằm trong khoảng thời gian bắt đầu và kết thúc
  67. {
  68. return true;
  69. }
  70. return false;
  71. }
  72. int BinhChon::Getter_TimeStart()
  73. {
  74. return (stof(TimeStart));
  75. }
  76. int BinhChon::Getter_TimeStart1min()
  77. {
  78. return (stof(TimeStart1min));
  79. }
  80.  
  81. int BinhChon::Getter_TimeEnd()
  82. {
  83. return(stof(TimeEnd));
  84. }
  85. int BinhChon::Getter_TimeEnd1min()
  86. {
  87. return(stof(TimeEnd1min));
  88. }
  89.  
  90. int BinhChon::Getter_Hour()
  91. {
  92. return(stof(Hour));
  93. }
  94. int BinhChon::Getter_Minnute()
  95. {
  96. return(stof(Minnute));
  97. }
  98. string BinhChon::Getter_Vote_Code()
  99. {
  100. return Vote_Code;
  101. }
  102. string BinhChon::Getter_Vote_NameSinger()
  103. {
  104. return Vote_NameSinger;
  105. }
  106. BinhChon::BinhChon()
  107. {
  108. }
  109.  
  110.  
  111. BinhChon::~BinhChon()
  112. {
  113. }
  114. <<<<<<<<<<<<<<<<<<<<<<main.cpp>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  115. #include "BinhChon.h"
  116. int main()
  117. {
  118. int dem[7] = { 0,0,0,0,0,0,0 };
  119. freopen("input.txt", "rt", stdin);
  120. BinhChon DanhSach[100];
  121. int n = 0;
  122. BinhChon temp;
  123. temp.EnterTheTime();
  124. while (!cin.eof())
  125. {
  126. temp.input();
  127. if (temp.CheckTime() == true)
  128. {
  129. DanhSach[n] = temp;
  130. n++;
  131. }
  132. }
  133. freopen("output.txt", "wt", stdout);
  134. for (int i = 0; i < n; i++)
  135. {
  136. for (int j = i; j < n; j++)
  137. {
  138. if (DanhSach[j].Getter_Vote_Code() == DanhSach[i].Getter_Vote_Code())
  139. {
  140. dem[i]++;
  141. }
  142. }
  143. }
  144. int Max = 0;
  145. for (int i = 0; i < n; i++)
  146. {
  147. if (dem[i] > Max)
  148. {
  149. Max = dem[i];
  150. }
  151. }
  152. for (int i = 0; i < n; i++)
  153. {
  154. if (Max == dem[i])
  155. {
  156. cout << DanhSach[i].Getter_Vote_NameSinger() << " " << dem[i] << endl;
  157. }
  158. }
  159. _getch();
  160. }
Add Comment
Please, Sign In to add comment