C++ HW8-1 for WallPower

撰寫一個C++打卡鐘程式,有打卡與查詢功能。打卡功能為輸入人ID後再輸入到達與離開時間。查詢功能為輸入個人ID後顯示上次打卡資料。
參考操作畫面如圖。
參考答案。
  1. #include <string>
  2. #include <stdio.h>
  3. #include <iostream>
  4. using namespace std;
  5. typedef struct Data
  6. {
  7. int id;
  8. string enter, exit;
  9. };
  10. void show(Data _data[], int index);
  11. Data read();
  12. Data _data[20];
  13. int now = 0;
  14. int select;
  15. int index;
  16. int main()
  17. {
  18. while (1)
  19. {
  20. cout << "1) 打卡 2) 查詢 0) 離開:";
  21. cin >> select;
  22. if (select == 1)
  23. {
  24. if (now < 20)
  25. {
  26. _data[now] = read();
  27. now++;
  28. }
  29. else
  30. cout << "名單已滿!" << endl;
  31. }
  32. else if (select == 2 && now != 0)
  33. {
  34. cout << "想查詢誰的資料:";
  35. cin >> index;
  36. show(_data, index);
  37. }
  38. else if (select == 0)
  39. break;
  40. fflush(stdin);
  41. }
  42. system("pause");
  43. return 0;
  44. }
  45. void show(Data _data[], int index)
  46. {
  47. for (int i = 0; i < 20; i++)
  48. if (_data[i].id == index)
  49. cout << "上次到啥時間為:" << _data[i].enter << endl << "上次離開時間為:" << _data[i].exit << endl;
  50. }
  51. Data read()
  52. {
  53. Data newdata;
  54. cout << "請輸入你在公司的ID:";
  55. cin >> newdata.id;
  56. cout << "您今天到班的時間是:";
  57. cin >> newdata.enter;
  58. cout << "   離開的時間是:";
  59. cin >> newdata.exit;
  60. cout << "謝謝,下一位。" << endl;
  61. return newdata;
  62. }

留言

這個網誌中的熱門文章

C# 井字遊戲