Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // main.cpp
- #include "VolleyballSet.h"
- int main() {
- std::string vTeam1{ "Polska" }, vTeam2{ "Brazylia" };
- VolleyballSet volleyballSet{ vTeam1, vTeam2 };
- volleyballSet.play();
- return 0;
- }
- // VolleyballSet.h
- #pragma once
- #include <iostream>
- class VolleyballSet {
- std::string mTeam1;
- std::string mTeam2;
- short int mPointsRequired{ 25 };
- short int mPointsTeam1{ 0 };
- short int mPointsTeam2{ 0 };
- bool continueSet() const;
- void givePoint();
- void printResult() const;
- void printStatus() const;
- public:
- VolleyballSet(const std::string& aTeam1, const std::string& aTeam2) : mTeam1(aTeam1), mTeam2(aTeam2) {}
- void play();
- };
- // VolleyballSet.cpp
- #include "VolleyballSet.h"
- #include <conio.h>
- #include <cstdlib>
- #include <ctime>
- void VolleyballSet::play() {
- do {
- printStatus();
- _getch();
- givePoint();
- } while (continueSet());
- printResult();
- }
- bool VolleyballSet::continueSet() const {
- if (mPointsTeam1 >= mPointsRequired) {
- if (mPointsTeam1 - mPointsTeam2 > 1) {
- return false;
- }
- }
- if (mPointsTeam2 >= mPointsRequired) {
- if (mPointsTeam2 - mPointsTeam1 > 1) {
- return false;
- }
- }
- return true;
- }
- void VolleyballSet::givePoint() {
- srand(time(nullptr));
- rand() % 2 == 0 ? ++mPointsTeam1 : ++mPointsTeam2;
- }
- void VolleyballSet::printResult() const {
- if (mPointsTeam1 > mPointsTeam2) {
- std::cout << "Druzyna " << mTeam1 << " wygrywa set " << mPointsTeam1 << ':' << mPointsTeam2 << std::endl;
- }
- else {
- std::cout << "Druzyna " << mTeam2 << " wygrywa set " << mPointsTeam2 << ':' << mPointsTeam1 << std::endl;
- }
- }
- void VolleyballSet::printStatus() const {
- std::cout << mTeam1 << '\t' << mPointsTeam1 << ':' << mPointsTeam2 << '\t' << mTeam2 << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement