Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "Dice.h"
- #include <ctime>
- void assignmentOne();
- void assignmentTwo();
- void assignmentThree();
- void assignmentFour();
- int main() {
- _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
- srand((unsigned)time(0));
- //assignmentOne();
- //assignmentTwo();
- //assignmentThree();
- assignmentFour();
- std::getchar();
- return 0;
- }
- void assignmentOne()
- {
- Dice* ptr = nullptr;
- int nrOfSides = 0;
- std::cout << "Number of sides: ";
- std::cin >> nrOfSides;
- std::cin.ignore();
- ptr = new Dice(nrOfSides);
- ptr->toss();
- std::cout << "Toss: " << ptr->getValue() << std::endl;
- Dice* ptr2 = new Dice(*ptr);
- ptr2->toss();
- std::cout << "Toss: " << ptr2->getValue() << std::endl;
- Dice* tmp = ptr;
- ptr = ptr2;
- ptr2 = tmp;
- delete ptr;
- delete ptr2;
- }
- void assignmentTwo()
- {
- const int CAP = 5;
- const int NR_OF_FACES = 9;
- Dice *arr[CAP];
- for (int i = 0; i < CAP; ++i) {
- arr[i] = new Dice(NR_OF_FACES);
- arr[i]->toss();
- std::cout << i << ":" << arr[i]->getValue() << std::endl;
- }
- std::cout << std::endl;
- Dice *arrReversed[CAP];
- for (int i = 0; i < CAP; ++i) {
- arrReversed[i] = arr[(CAP -1) - i];
- std::cout << i << ":" << arrReversed[i]->getValue() << std::endl;
- }
- for (int i = 0; i < CAP; ++i) {
- delete arr[i];
- }
- }
- void assignmentThree()
- {
- const int CAP = 4;
- Dice** arr = new Dice*[CAP] {nullptr};
- int nrOfSixes = 0;
- for (int i = 0; i < CAP; ++i) {
- arr[i] = new Dice();
- arr[i]->toss();
- std::cout << i << ": " << arr[i]->getValue() << std::endl;
- if (arr[i]->getValue() == 6) {
- ++nrOfSixes;
- }
- }
- std::cout << "Number sixes rolled: " << nrOfSixes << std::endl;
- for (int i = 0; i < CAP; ++i) {
- delete arr[i];
- }
- delete[] arr;
- }
- void assignmentFour()
- {
- int cap = 4;
- int nrOf = 0;
- const int NR_OF_SIDES = 11;
- Dice** arr = new Dice*[cap] {nullptr};
- for (int i = 0; i < cap; ++i) {
- arr[nrOf++] = new Dice(NR_OF_SIDES);
- }
- cap = 7;
- Dice** tmp = new Dice*[cap] {nullptr };
- for (int i = 0; i < nrOf; ++i) {
- tmp[i] = arr[i];
- }
- delete[]arr;
- arr = tmp;
- for (int i = nrOf; i < cap; ++i) {
- arr[nrOf++] = new Dice(NR_OF_SIDES);
- }
- for (int i = 0; i < nrOf; ++i) {
- arr[i]->toss();
- std::cout << arr[i]->getValue() << std::endl;
- }
- for (int i = 0; i < nrOf; ++i) {
- delete arr[i];
- }
- delete[] arr;
- }
Advertisement
Add Comment
Please, Sign In to add comment