From a99b1439bb6e6d960a2d2bcca2edb502d3c485b5 Mon Sep 17 00:00:00 2001
From: bartvbl <bartvblokl@gmail.com>
Date: Sun, 7 Apr 2024 22:00:08 +0200
Subject: [PATCH] Added lecture 14 handout

---
 .../Lecture 14 - handout/Stopwatch.cpp        | 12 +++++++++++
 .../Lecture 14 - handout/Stopwatch.h          | 20 +++++++++++++++++++
 2 files changed, 32 insertions(+)
 create mode 100644 templates/_folder_Lectures/Lecture 14 - handout/Stopwatch.cpp
 create mode 100644 templates/_folder_Lectures/Lecture 14 - handout/Stopwatch.h

diff --git a/templates/_folder_Lectures/Lecture 14 - handout/Stopwatch.cpp b/templates/_folder_Lectures/Lecture 14 - handout/Stopwatch.cpp
new file mode 100644
index 0000000..a4be1c7
--- /dev/null
+++ b/templates/_folder_Lectures/Lecture 14 - handout/Stopwatch.cpp	
@@ -0,0 +1,12 @@
+#include "Stopwatch.h"
+
+void Stopwatch::start() {
+    startTime = std::chrono::steady_clock::now();
+}
+
+double Stopwatch::stop() {
+    std::chrono::time_point endTime = std::chrono::steady_clock::now();
+    long durationInMicroseconds = std::chrono::duration_cast<std::chrono::microseconds>(endTime - startTime).count();
+    double durationInSeconds = double(durationInMicroseconds)/1000000.0;
+    return durationInSeconds;
+}
\ No newline at end of file
diff --git a/templates/_folder_Lectures/Lecture 14 - handout/Stopwatch.h b/templates/_folder_Lectures/Lecture 14 - handout/Stopwatch.h
new file mode 100644
index 0000000..307f383
--- /dev/null
+++ b/templates/_folder_Lectures/Lecture 14 - handout/Stopwatch.h	
@@ -0,0 +1,20 @@
+#pragma once
+#include <iostream>
+#include <chrono>
+
+// This class abstracts some (somewhat) nasty code that is
+// definitely outside the scope of this course.
+// Its main purpose is to return the amount of time 
+// taken by the program in main.cpp
+
+// Calling start() starts the stopwatch
+// Calling stop() stops it and returns the amount of time
+// that has elapsed since start() was called in seconds
+
+class Stopwatch {
+    std::chrono::time_point<std::chrono::steady_clock> startTime;
+
+public:
+    void start();
+    double stop();
+};
\ No newline at end of file
-- 
GitLab