diff --git "a/infobank/Articles/\303\230ving 6.pdf" "b/infobank/Articles/\303\230ving 6.pdf" new file mode 100644 index 0000000000000000000000000000000000000000..5e0eb0b6fa522b75e1d8204c5570565611d0a1d0 Binary files /dev/null and "b/infobank/Articles/\303\230ving 6.pdf" differ diff --git a/templates/_folder_Exercises/O06/CourseCatalog.cpp b/templates/_folder_Exercises/O06/CourseCatalog.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d9881434b22cba6bdc4bdd060ee9f750fc83df60 --- /dev/null +++ b/templates/_folder_Exercises/O06/CourseCatalog.cpp @@ -0,0 +1,29 @@ +#include "CourseCatalog.h" + +// BEGIN: 3a + +// END: 3a + +// BEGIN: 3b + +// END: 3b + +// BEGIN: 3c + +// END: 3c + +// BEGIN: 3d + +// END: 3d + +// BEGIN: 3e + +// END: 3e + +// BEGIN: 3g + +// END: 3g + +// BEGIN: 3h + +// END: 3h \ No newline at end of file diff --git a/templates/_folder_Exercises/O06/CourseCatalog.h b/templates/_folder_Exercises/O06/CourseCatalog.h new file mode 100644 index 0000000000000000000000000000000000000000..2c8dce7128d296723ed885a89f0b2564432cb58c --- /dev/null +++ b/templates/_folder_Exercises/O06/CourseCatalog.h @@ -0,0 +1,20 @@ +#pragma once +#include "std_lib_facilities.h" + +class CourseCatalog +{ +public: + void addCourse(const string& key, const string& value); + void removeCourse(const string& key); + string getCourse(const string& key) const; + + friend ostream& operator<<(ostream& os, const CourseCatalog& cc); + + void saveToFile(const std::string& filename) const; + void loadFromFile(const std::string& filename); + +private: + map<string, string> courses; +}; + +void testCourseCatalog(); \ No newline at end of file diff --git a/templates/_folder_Exercises/O06/FileUtils.cpp b/templates/_folder_Exercises/O06/FileUtils.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fdcfb93b5e357656ae4aa5f68cbb3b62bb00ae63 --- /dev/null +++ b/templates/_folder_Exercises/O06/FileUtils.cpp @@ -0,0 +1,17 @@ +#include "FileUtils.h" + + +void writeUserInputToFile(const std::string &path) +{ + // BEGIN: 1a + + // END: 1a +} + + +void addLineNumbers(const std::string &filename) +{ + // BEGIN: 1b + + // END: 1b +} \ No newline at end of file diff --git a/templates/_folder_Exercises/O06/FileUtils.h b/templates/_folder_Exercises/O06/FileUtils.h new file mode 100644 index 0000000000000000000000000000000000000000..1e8fdbf67611e3b3ec45cbc5f5ee24f2c5d6c8e1 --- /dev/null +++ b/templates/_folder_Exercises/O06/FileUtils.h @@ -0,0 +1,5 @@ +#pragma once +#include "std_lib_facilities.h" + +void writeUserInputToFile(const std::string &filename); +void addLineNumbers(const std::string &filename); \ No newline at end of file diff --git a/templates/_folder_Exercises/O06/bouncingBall.cpp b/templates/_folder_Exercises/O06/bouncingBall.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7f76bbeadbc13844689798a74d6e5c0e88dfd5d5 --- /dev/null +++ b/templates/_folder_Exercises/O06/bouncingBall.cpp @@ -0,0 +1,96 @@ +#pragma once +#include "bouncingBall.h" + +// BEGIN: 4b + +// END: 4b + +// BEGIN: 4c + +// END: 4c + +constexpr Point BOUNCE_WINDOW_TOP_LEFT{50, 50}; +constexpr int BOUNCE_WINDOW_WIDTH{800}; +constexpr int BOUNCE_WINDOW_HEIGHT{500}; + +// FJERN DETTE NAAR DU BEGYNNER PÅ OPPGAVE 4e) +#define BOUNCING_BALL +// + +void bouncingBall(){ + #ifndef BOUNCING_BALL + AnimationWindow window{BOUNCE_WINDOW_TOP_LEFT.x, BOUNCE_WINDOW_TOP_LEFT.y, + BOUNCE_WINDOW_WIDTH, BOUNCE_WINDOW_HEIGHT, "Bouncing ball"}; + + const int radius{30}; + int alpha{1}; + int velocity{2}; + Color colour_up{Color::blue}; + Color colour_down{Color::blue}; + int x{0}; + int y{360}; + int increment_x{0}; + int increment_y{0}; + int count_bounce_top{0}; + int count_bounce_bottom{0}; + int count_num_passes{0}; + + Config slow = {1, 1, 0}; + Config fast = {1, 1, 0}; + + // read in the configurations + filesystem::path file_name{"konfigurasjon.txt"}; + ifstream is{file_name}; + is >> slow >> fast; + + // initialise the run + velocity = slow.velocity; + colour_up = ball_colour.at(slow.colour_up); + colour_down = ball_colour.at(slow.colour_down); + + while (!window.should_close()) { + // determine increments based on the velocity + increment_x = velocity * cos(alpha); + increment_y = velocity * sin(alpha); + + // movement i x-direction + if ((increment_x + x) > window.width()) { + // reached right side - wrap around to the leftmost + x = 0; + // increment counter which counts number of full left-to-right passes + count_num_passes++; + // alternate between slow and fast configuration every second pass + if (count_num_passes % 2 == 0) { + if (velocity == slow.velocity) { + velocity = fast.velocity; + colour_up = ball_colour.at(fast.colour_up); + colour_down = ball_colour.at(fast.colour_down); + } else { + velocity = slow.velocity; + colour_up = ball_colour.at(slow.colour_up); + colour_down = ball_colour.at(slow.colour_down); + } + } + } else { + // moving rightwards + x += increment_x; + } + + + // HINT 1: Ta en titt på koden ovenfor og se hvilke variabler som brukes. + // Bruk disse variablene for å implementere bevegelsen til den sprettende ballen. For eksempel: + // Variablene count_bounce_top og count_bounce_bottom kan brukes + // for å holde styr på hvilken retning ballen skal gå. + // Variabelen increment_y skal brukes for å øke y. + + // HINT 2: window.draw_circle({x, y}, r, c) tegner en sirkel med radius r, + // sentrum i (x, y) og fargen c + + // BEGIN: 4d + // movement in y-direction + // END: 4d + + window.next_frame(); + } + #endif +} \ No newline at end of file diff --git a/templates/_folder_Exercises/O06/bouncingBall.h b/templates/_folder_Exercises/O06/bouncingBall.h new file mode 100644 index 0000000000000000000000000000000000000000..0711ac65d6a9b423518a9a8f5067e4ca84472732 --- /dev/null +++ b/templates/_folder_Exercises/O06/bouncingBall.h @@ -0,0 +1,15 @@ +#pragma once +#include "std_lib_facilities.h" +#include "AnimationWindow.h" + +struct Config{ + // BEGIN: 4a + + // END: 4a +}; + +extern map<int, Color> ball_colour; + +istream& operator>>(istream& is, Config& cfg); + +void bouncingBall(); diff --git a/templates/_folder_Exercises/O06/konfigurasjon.txt b/templates/_folder_Exercises/O06/konfigurasjon.txt new file mode 100644 index 0000000000000000000000000000000000000000..7043f2bf4599442e60bcd7f17e5e8a8cb4ada453 --- /dev/null +++ b/templates/_folder_Exercises/O06/konfigurasjon.txt @@ -0,0 +1,2 @@ +1 2 3 +3 4 15 \ No newline at end of file diff --git a/templates/_folder_Exercises/O06/main.cpp b/templates/_folder_Exercises/O06/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..157771dbc664c778e6caf9ba47fe3256991e1a80 --- /dev/null +++ b/templates/_folder_Exercises/O06/main.cpp @@ -0,0 +1,10 @@ +#include "std_lib_facilities.h" +#include "CourseCatalog.h" +#include "FileUtils.h" +#include "bouncingBall.h" + +int main() +{ + // Her kan du teste din kode ved å kalle på de ulike funksjonene du har implementert + return 0; +} \ No newline at end of file