Skip to content
Snippets Groups Projects
Commit 84f188dc authored by Bianca Mazzetti's avatar Bianca Mazzetti
Browse files

publish exercise 6

parent 208fc488
No related branches found
No related tags found
No related merge requests found
File added
#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
#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
#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
#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
#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
#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();
1 2 3
3 4 15
\ No newline at end of file
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment