Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 135,919 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,578 people online right now. Registration is fast and FREE... Join Now!




Where To Go Next?

 
Reply to this topicStart new topic

Where To Go Next?

alexmccormack
19 May, 2008 - 04:25 AM
Post #1

New D.I.C Head
*

Joined: 19 May, 2008
Posts: 3

The following code is supposed to be object-orientated and to fulfill the following -


QUOTE
Scenario
“The Goblet of Fire” is to be a role playing game involving a number of different characters, weapons, magical objects and spells. The characteristics of each object are as follows:
Characters:
Unique name
Sex
Type: wizard/witch/hero/heroine/sponsor/worker/creature
Magical ability: Value between 0 and 10
Strength: Value between 0 and 10
Health: Value between 0 and 10
Wealth: Value between 0 and 10

Weapon:
Unique name
Type Axe/sword/dagger/catapult
Magical resistance: Value between 0 and 10
Cost Value between 0 and 10

Magical object:
Unique name
Type: wand/shield/invisibility cloak/transporter
Magical strength: Value between 0 and 10
Cost Value between 0 and 10

Spell:
Unique name
Action: stunning/revealer/object or weapon summoning
Magical strength: Value between 0 and 10
Cost Value between 0 and 10

Throughout the game a player can acquire or loose any of the above, although they must have at least one character left in order to continue with the game

Task- part 1
Using an object oriented approach, design and write a program that uses appropriate classes to store, add and delete items from a players bank of characters, weapons, magical objects and spells.



The code is as follows (the boldened line has a declaration error - does anyone know how to fix this?)


CODE
#include <stdio.h>
#include <iostream.h>
{
class Character //a record holding all the data on one character
      public:
            char uniquename[35];   //allows for a char called uniquename that can be up to 35 characters long
            char sex[6];  //allows for a char called sex that can be up to 6 characters long
            char type[8]; //allows for a char called type that can be up to 8 characters long
            int magicalability[2]; //holds the magicalability of the character
            int strength[2];       //holds the strength of the character
            int health[2];         //holds the health of the character
            int wealth[2];         //holds the wealth of the character
}
{
class Weapon //a record holding all of the data on the weapon of a character
      public:
          char uniqueweapon[25]; //allows for a char called uniqueweapon that can be up to 25 characters long
          char weapontype[15]; //allows for a char called weapontype that can be up to 15 characters long
          int magicalresistance[2]; //holds the magical resistance of the character
          int cost[2]; //holds the cost of the character
{
class MagicalObject //a record holding all of the data on a magical object
      public:
         char uniqueobject[25]; //allows for a char called uniqueobject that can be up to 25 characters long
         char objecttype[15]; //allows for a char called objecttype that can be up to 15 characters long
         int magicalstrength[2]; //holds the magical strength of the character
         int magicalcost[2]; //holds the magical cost of the magical object
}
{
class Spell //a record holding all of the data on a spell
      public:
         char uniquespell[25]; //allows for a character called uniquespell that can be up to 25 characters long
         char actionspell[15]; //allows for a character called actionspell that can be up to 15 characters long
         int spellstrength[2]; //holds the magical strength of the spell
         int spellcost[2]; //holds the cost of the spell
}


What do I need to do now?


User is offlineProfile CardPM
+Quote Post

gabehabe
RE: Where To Go Next?
19 May, 2008 - 04:37 AM
Post #2

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,514



Thanked: 96 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
QUOTE
The Goblet of Fire
That sounds strangely familiar. unsure.gif

Anyway, it doesn't show boldness inside of code tags, so can you just copy and paste the line that gives you errors?

From what I can see though, you have you class definitions set up wrong (specifically the {} tags) Here's the syntax:
cpp

class <class name>
{ // beginning
public:
<some public members>;
private:
<some private members>;
protected:
<some protected members>;
}; // end (don't forget the semi-colon!)

You don't need stuff in each of your public, private and protected, but there's a guideline for you smile.gif
cpp
#include <stdio.h>
#include <iostream.h>

class Character //a record holding all the data on one character
{
public:
char uniquename[35]; //allows for a char called uniquename that can be up to 35 characters long
char sex[6]; //allows for a char called sex that can be up to 6 characters long
char type[8]; //allows for a char called type that can be up to 8 characters long
int magicalability[2]; //holds the magicalability of the character
int strength[2]; //holds the strength of the character
int health[2]; //holds the health of the character
int wealth[2]; //holds the wealth of the character
};

class Weapon //a record holding all of the data on the weapon of a character
{
public:
char uniqueweapon[25]; //allows for a char called uniqueweapon that can be up to 25 characters long
char weapontype[15]; //allows for a char called weapontype that can be up to 15 characters long
int magicalresistance[2]; //holds the magical resistance of the character
int cost[2]; //holds the cost of the character
};
class MagicalObject //a record holding all of the data on a magical object
{
public:
char uniqueobject[25]; //allows for a char called uniqueobject that can be up to 25 characters long
char objecttype[15]; //allows for a char called objecttype that can be up to 15 characters long
int magicalstrength[2]; //holds the magical strength of the character
int magicalcost[2]; //holds the magical cost of the magical object
};

class Spell //a record holding all of the data on a spell
{
public:
char uniquespell[25]; //allows for a character called uniquespell that can be up to 25 characters long
char actionspell[15]; //allows for a character called actionspell that can be up to 15 characters long
int spellstrength[2]; //holds the magical strength of the spell
int spellcost[2]; //holds the cost of the spell
};

Hope this helps smile.gif

This post has been edited by gabehabe: 19 May, 2008 - 04:42 AM
User is offlineProfile CardPM
+Quote Post

gabehabe
RE: Where To Go Next?
19 May, 2008 - 04:45 AM
Post #3

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,514



Thanked: 96 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
Sorry to double post, but this is about a different part of your code:
cpp
#include <stdio.h> // you don't need this
#include <iostream> // the .h has been deprecated

Also, you have c-style strings (char arrays) but you are using C++
Can't you use strings?
User is offlineProfile CardPM
+Quote Post

alexmccormack
RE: Where To Go Next?
19 May, 2008 - 04:50 AM
Post #4

New D.I.C Head
*

Joined: 19 May, 2008
Posts: 3

QUOTE(gabehabe @ 19 May, 2008 - 05:45 AM) *

Sorry to double post, but this is about a different part of your code:
cpp
#include <stdio.h> // you don't need this
#include <iostream> // the .h has been deprecated

Also, you have c-style strings (char arrays) but you are using C++
Can't you use strings?


I'm rubbish at strings, to be honest.
User is offlineProfile CardPM
+Quote Post

gabehabe
RE: Where To Go Next?
19 May, 2008 - 04:54 AM
Post #5

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,514



Thanked: 96 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
Why? They're pretty useful happy.gif
Any questions? I can talk you through the use of them
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 08:05AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month