Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    114
  • comments
    126
  • views
    64750

CPP Workshop

Sign in to follow this  
Sshado

103 views

Whelp, I have been very busy lately, but I am refocusing again. I have read through chapters 6 and 11 for the CPP Workshop. They gave us an exercise that I need to do before going on to the next chapter...


Exercise 1 - The random character generator

In the game "Dungeons & Dragons" by WoTC, each player controls a character. The character has a number of attributes, specifically, they have Strength, Dexterity, Stamina, Intellect, Wisdom, and Charisma - each which can have a score in the range of 1 to 20. These "ability" scores are used to determine the success and/or failure of skills used, as well as how your character performs in combat. We'll explore more of that later. For this week, I want you to write a program which contains a "Character" class. The character should have attributes representing the 6 ability scores, with accesses for each score. As well, the class should contain two constructors, 1 which takes as input 6 ability scores, and the second which is the default. The default constructor should randomly assign each ability score a value in the range of 1 to 20. To make it easier, I've posted the code below to help generate random numbers. Your main function should create two "characters"....one by using the default constructor, and one by passing in values between 1-20...might want to check in your constructor to make sure the input is valid (1-20). After both characters are created, use your accessors to print the attributes of each character to the screen with appropriate labels.

// Required headers
#include
#include

// Call this ONCE, in your main function to seed the random number generator
srand( (unsigned)time( NULL ) );

// Call this in your default constructor in order to generate a random number from 1 to 20.
int randomNum = ( rand() % 20 ) + 1;


I will not move on until I get this one done...

Sign in to follow this  


1 Comment


Recommended Comments

I've been thinking of joining the C++ workshop too, however I find I can learn just as well if not better by searching for solutions on the internet or in my C++ book when I get stuck on something in one of my projects.
Then again I suppose the workshop does encourage good coding practices >.>

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!