View on GitHub

oop

Αντικειμενοστραφής Προγραμματισμός (C++)

Λύση πρώτης εργασίας 2021-2022

Ερώτημα Α

Κλάση horse

Test για τη συνάρτηση horse::move_forward

Μεταγλώττιση test

$ g++ horse.cpp horse_races_a.cpp -o horse_races_a -std=c++17
$ horse_races_a.exe
===============================================================================
All tests passed (6 assertions in 1 test case)

Ερώτημα Β

Κλάση arena

Πρόγραμμα οδηγός για το ερώτημα Β

$ g++ .\horse.cpp .\arena.cpp .\horse_races_b.cpp -o horse_races_b -Wall -Werror -pedantic -std=c++17
$ horse_races_b.exe
Race horses
1 Hulk startup = 54 power = 97 stamina = 57
2 Raider startup = 82 power = 64 stamina = 65
3 Bolt startup = 68 power = 84 stamina = 52
4 Storm startup = 98 power = 67 stamina = 65
5 Rogue startup = 79 power = 66 stamina = 73
1.........
2.........
3.........
4.........
5.........
Press <ENTER> to advance one step
.1........
.2........
.3........
4.........
.5........
Press <ENTER> to advance one step
.1........
..2.......
..3.......
.4........
..5.......
Press <ENTER> to advance one step
..1.......
...2......
...3......
.4........
...5......
Press <ENTER> to advance one step
...1......
....2.....
....3.....
..4.......
....5.....
Press <ENTER> to advance one step
....1.....
.....2....
.....3....
...4......
....5.....
Press <ENTER> to advance one step
.....1....
.....2....
......3...
...4......
.....5....
Press <ENTER> to advance one step
......1...
.....2....
.......3..
...4......
.....5....
Press <ENTER> to advance one step
.......1..
......2...
.......3..
....4.....
.....5....
Press <ENTER> to advance one step
........1.
......2...
........3.
.....4....
......5...
Press <ENTER> to advance one step
.........1
......2...
.........3
......4...
......5...
Press <ENTER> to advance one step
.........1
.......2..
.........3
.......4..
.......5..
Press <ENTER> to advance one step
.........1
........2.
.........3
........4.
........5.
Press <ENTER> to advance one step
.........1
.........2
.........3
.........4
.........5
1 - 1 Hulk startup = 54 power = 97 stamina = 57
2 - 3 Bolt startup = 68 power = 84 stamina = 52
3 - 2 Raider startup = 82 power = 64 stamina = 65
4 - 4 Storm startup = 98 power = 67 stamina = 65
5 - 5 Rogue startup = 79 power = 66 stamina = 73   

Ερώτημα Γ

Πρόγραμμα οδηγός για το ερώτημα Γ

$ g++ .\horse.cpp .\arena.cpp .\horse_races_c.cpp -o horse_races_c -Wall -Werror -pedantic -std=c++17
$ horse_races_c.exe
Enter initial amount: 100
You deposited  100 euros
Race horses
1 Nitro startup = 65 power = 93 stamina = 61
2 Storm startup = 92 power = 65 stamina = 72
3 Blitz startup = 52 power = 53 stamina = 87
4 Rogue startup = 72 power = 97 stamina = 52
5 Raider startup = 56 power = 92 stamina = 62
6 Danger startup = 94 power = 65 stamina = 64
7 Hulk startup = 95 power = 79 stamina = 69
8 Hercules startup = 68 power = 99 stamina = 79
Enter horse number: 1
Enter bet: 50
You bet 50 euros on horse Nitro. Good luck!
Do you want to see the race step by step (y/n)? n
The race is about to start
1.........
2.........
3.........
4.........
5.........
6.........
7.........
8.........
.1........
.2........
.3........
.4........
.5........
.6........
.7........
.8........
==========
.1........
..2.......
.3........
..4.......
.5........
..6.......
..7.......
..8.......
==========
..1.......
...2......
.3........
...4......
..5.......
..6.......
...7......
...8......
==========
...1......
....2.....
..3.......
....4.....
...5......
..6.......
....7.....
....8.....
==========
....1.....
....2.....
..3.......
.....4....
...5......
..6.......
.....7....
.....8....
==========
.....1....
.....2....
..3.......
......4...
....5.....
...6......
......7...
......8...
==========
......1...
.....2....
..3.......
.......4..
.....5....
...6......
.......7..
.......8..
==========
.......1..
.....2....
..3.......
........4.
......5...
...6......
........7.
........8.
==========
........1.
......2...
...3......
.........4
.......5..
....6.....
.........7
.........8
==========
.........1
.......2..
...3......
.........4
........5.
....6.....
.........7
.........8
==========
.........1
.......2..
....3.....
.........4
.........5
.....6....
.........7
.........8
==========
.........1
.......2..
.....3....
.........4
.........5
......6...
.........7
.........8
==========
.........1
.......2..
......3...
.........4
.........5
......6...
.........7
.........8
==========
.........1
........2.
.......3..
.........4
.........5
.......6..
.........7
.........8
==========
.........1
........2.
........3.
.........4
.........5
........6.
.........7
.........8
==========
.........1
........2.
.........3
.........4
.........5
.........6
.........7
.........8
==========
.........1
.........2
.........3
.........4
.........5
.........6
.........7
.........8
1 - 4 Rogue startup = 72 power = 97 stamina = 52
2 - 7 Hulk startup = 95 power = 79 stamina = 69
3 - 8 Hercules startup = 68 power = 99 stamina = 79
4 - 1 Nitro startup = 65 power = 93 stamina = 61
5 - 5 Raider startup = 56 power = 92 stamina = 62
6 - 3 Blitz startup = 52 power = 53 stamina = 87
7 - 6 Danger startup = 94 power = 65 stamina = 64
8 - 2 Storm startup = 92 power = 65 stamina = 72
:( You have lost 50 euros
You now have 50 euros. Do you want to continue (y/n)? n
You started with 100 euros and now you have 50 euros