Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE READ THE QUESTION BEFORE YOU POST THE ANSWER. USE C++ AND DO IT IN FOURE

ID: 3714791 • Letter: P

Question

PLEASE READ THE QUESTION BEFORE YOU POST THE ANSWER. USE C++ AND DO IT IN FOURE FILES . ALSO RUN YOUR PROGRAM AND ANSWER IT PLEASE.

MOST OF THE ANSWER BEFORE ARE FALSE. SO PLEASE DONOT JUST COPY AND PASTE. DO IT FROM SCRATCH.

THANKS.

Requested files: Dice.h, Dice.cpp, DiceAndDanger.cpp, DiceAndDanger_test.cpp
Type of work: Individual work

With this program, you will begin the practice of breaking source code into distinct modules that are responsible for limited scopes of behavior and data. You will create the framework of a game that uses dice to generate random decisions. This game is called DiceAndDanger.cpp.

Create a class (header and implmentation files) named Dice that can be used to create objects that simulate the behavior of one or more Die. This class should be able to simulate a die with an arbitrary number of sides; for example, it should be able to simulate a three sided die or a 21 sided die.

This class must have at least two public methods:

void roll() - which will simulate rolling a die by returning a random number between 1 and N where N represents the number of sides on the die.

int read() - which will return the value showing on the "top" of the die. This value represents the number of "pips" on the face of the die considered to be the top. If you store the values of the faces of your die in an array, the top should be the first element.

int read(int n) - return the value associated with the nth side of the die.

Your class must have a default constructor that will create a die with 6 sides. It should also have a parameterized constructor which will take an argument that indicates the number of sides that the new die object should contain.

DiceAndDanger.cpp should contain two methods:

rollCharacter(int* attributeArray) which will use 6 rolls of an 18-sided die to determine each of the following character attributes: Strength, Constitution, Dexterity, Intelligence, Wisdom, Charisma.

printCharacter(int *attributeArray) which will print each of the characters attributes and the value rolled: Strength:17,Constitution:12,Dexterity:8,Intelligence:16,Wisdom:11,Charisma:4

After the first set of character attributes is generated, the program should ask:

"Roll another characer? (y/n): "

If yes, the program should re-roll the character. If no the program should exit.

Explanation / Answer

Solution:

Note: The 4th file details not provoded, i think it is with you

Dice.h

#ifndef DICE_H_
#define DICE_H_

using namespace std;

class Dice
{

   private:
   int N;
   int DiceFace[];
public:
   Dice();
   Dice(int n);
   void roll();
   int read();
   int read(int n);
};
#endif

Dice.Cpp

#include "Dice.h"
#include <stdlib.h>
#include <ctime>
#include<iostream>

Dice::Dice()
{
   N=6;
   for(int i=1;i<7;i++)
   {
       DiceFace[i]=i;
   }
}

Dice::Dice(int n)
{
   N=n;
   for(int i=1;i<=N;i++)
   {
       DiceFace[i]=i;
   }
}

void Dice::roll()
{
   for(int itr=0;itr<N;itr++)
        {
           srand ( time(NULL) );
            int index=rand()%((N)-itr);
            int holder=DiceFace[index];
            DiceFace[index]=DiceFace[N-itr-1];
            DiceFace[N-1-itr]=holder;
        }
}

int Dice::read()
{

   return DiceFace[N-1];
}

int Dice::read(int n)
{
   cout<<n;
   return DiceFace[N-n-1];
}

DiceAndDanger.cpp

#include "Dice.h"
#include<iostream>

using namespace std;

class DiceAndDanger
{
public:
   void rollCharacter(int *atrtributeArray)
   {
       for(int i=0;i<6;i++)
       {
           Dice dobj(18);
           dobj.roll();
           int x=dobj.read(17);
           cout<<x;
           atrtributeArray[i]=dobj.read(17);
       }
   }


   void printCharacter(int *atrtributeArray)
   {
      
   cout<<"Strength: "<<*(atrtributeArray+0);
   cout<<"Constitution: "<<*(atrtributeArray+1);
   cout<<"Dexterity: "<<*(atrtributeArray+2);
   cout<<"Intelligence: "<<*(atrtributeArray+3);
   cout<<"Wisdom: "<<*(atrtributeArray+4);
   cout<<"Charisma: "<<*(atrtributeArray+5);

   }
};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote