Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

用來測試分析頁面, 還沒完成

  • Loading branch information...
commit 6e661a1af694091b2c2de28fc72d4e30ede5ef09 1 parent 0309a17
doremi authored
Showing with 60 additions and 2 deletions.
  1. +2 −1  .gitignore
  2. +4 −1 Makefile
  3. +54 −0 analysis.cpp
View
3  .gitignore
@@ -21,4 +21,5 @@ class
sleep
clock
ptr
-count
+count
+analysis
View
5 Makefile
@@ -1,4 +1,4 @@
-TARGET = notify notify2 ass1 bsf itoa fsm jump clock ptr count
+TARGET = notify notify2 ass1 bsf itoa fsm jump clock ptr count analysis
all:$(TARGET)
@@ -32,6 +32,9 @@ ptr:ptr.cpp
count:count.c
gcc -Wall -o $@ $< -g
+analysis:analysis.cpp
+ g++ -Wall -std=c++0x -o $@ $< -g
+
clean:
rm -rf $(TARGET)
View
54 analysis.cpp
@@ -0,0 +1,54 @@
+#include <stdio.h>
+#include <vector>
+#include <time.h>
+#include <stdint.h>
+
+using namespace std;
+
+struct Record {
+ int time;
+ int meter;
+};
+
+vector<Record> days[2];
+
+void make_record(int day, int time, int meter)
+{
+ Record record;
+ record.time = time;
+ record.meter = meter;
+ days[day].push_back(record);
+}
+
+void list_day(int day)
+{
+ printf("=== Day %d ===\n", day+1);
+ auto it = days[day].begin();
+ for (; it != days[day].end(); ++it) {
+ printf("Time: %02d, meter: %d\n", it->time, it->meter);
+ }
+}
+
+void analysis()
+{
+ int day = 0;
+ for (uint32_t i = 1; i < days[day].size(); ++i) {
+ Record prev = days[day][i-1];
+ Record curr = days[day][i];
+ printf("ave time: %d, avg meter: %f\n",
+ (curr.time+prev.time)/2, (double)(curr.meter-prev.meter)/((curr.time-prev.time)*60));
+ }
+}
+
+int main()
+{
+ make_record(0, 8, 5);
+ make_record(0, 12, 10);
+ make_record(0, 19, 20);
+ make_record(0, 22, 25);
+ list_day(0);
+
+ analysis();
+
+ return 0;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.