473,394 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Stacks and enum questions

I am gonna to create an ADT named JailCell, inside the JailCell class
I have 2 private attributes:
Here is my jailcell.h
Code:

// Jailcell.h
#ifndef JAILCELL_H
#define JAILCELL_H
#include "card.h"

class Jallcell
{
public:

private:
stack<Card> cards; // an STL stack of Card ADT's

enum suit; // an enumerated type(located in the Card ADT) that
// identifies the suit of the jail cell.
};
#endif
I feel confuse about the enumerated type attribute, since I think it's
from my Card class, anyone can advise me how i can code it?

Here is the card.h and card.cpp for references.
Code:

// card.cpp
#include <cassert>
#include <iostream>

#include "card.h"

using namespace std;

Card::Card() :
rank( ACE ),
suit( SPADES )
{
}

Card::Card( Rank newRank, Suit newSuit ) :
rank( newRank ),
suit( newSuit )
{
}

void Card::setRank( Rank newRank )
{
rank = newRank;
}

void Card::setSuit( Suit newSuit )
{
suit = newSuit;
}

ostream& operator<<( ostream& os, const Card& card )
{
switch( card.getRank() )
{
case Card::ACE:
os << "Ace";
break;
case Card::TWO:
os << "Two";
break;
case Card::THREE:
os << "Three";
break;
case Card::FOUR:
os << "Four";
break;
case Card::FIVE:
os << "Five";
break;
case Card::SIX:
os << "Six";
break;
case Card::SEVEN:
os << "Seven";
break;
case Card::EIGHT:
os << "Eight";
break;
case Card::NINE:
os << "Nine";
break;
case Card::TEN:
os << "Ten";
break;
case Card::JACK:
os << "Jack";
break;
case Card::QUEEN:
os << "Queen";
break;
case Card::KING:
os << "King";
break;
default:
assert( 0 );
}

os << " of ";

switch( card.getSuit() )
{
case Card::SPADES:
os << "Spades";
break;
case Card::HEARTS:
os << "Hearts";
break;
case Card::CLUBS:
os << "Clubs";
break;
case Card::DIAMONDS:
os << "Diamonds";
break;
default:
assert( 0 );
}

return os;
}

Code:

#include <iostream>

using namespace std;

class Card
{
public:

enum Rank
{
ACE,
TWO,
THREE,
FOUR,
FIVE,
SIX,
SEVEN,
EIGHT,
NINE,
TEN,
JACK,
QUEEN,
KING
};

enum Suit
{
SPADES,
HEARTS,
CLUBS,
DIAMONDS
};

Card(); // Default constructor will initialize to Ace of Spades
Card( Rank newRank, Suit newSuit );

Rank getRank() const {return rank;}
Suit getSuit() const {return suit;}

void setRank( Rank newRank );
void setSuit( Suit newSuit );

private:

Rank rank;
Suit suit;
};

ostream& operator<<( ostream& os, const Card& card );

Appericate it.

Jul 23 '05 #1
5 1730
joenchinghkg wrote:
I am gonna to create an ADT named JailCell, inside the JailCell class
I have 2 private attributes:
Here is my jailcell.h
Code:

// Jailcell.h
#ifndef JAILCELL_H
#define JAILCELL_H
#include "card.h"

class Jallcell
Did you notice that the name of the class is misspelled? That's what
happens when you instead of copy-and-pasting, just type into a newsgroup
posting.
{
public:

private:
stack<Card> cards; // an STL stack of Card ADT's

enum suit; // an enumerated type(located in the Card ADT) that
// identifies the suit of the jail cell.
Did you mean to say

Card::Suit suit;

?
[...]


V
Jul 23 '05 #2
I think this should be what I want, can i put it inside private
directly?

Card::Suti suit;

Jul 23 '05 #3
joenchinghkg wrote:
I think this should be what I want, can i put it inside private
directly?

Card::Suti suit;


Why not?
Jul 23 '05 #4
For Card::Suit suit, is it depends on the Card class?

Can you explain what Card::Suit means ?
thanks

Jul 23 '05 #5
joenchinghkg wrote:
For Card::Suit suit, is it depends on the Card class?
Depends? I guess. By the time the compiler encounters 'Card::Suit',
it better know what 'Card' is.
Can you explain what Card::Suit means ?


Card::Suit is a name. In your case, it's a name of the enumeration.
To the compiler the name of an enumeration is a type. So, Card::Suit
is a type.

V
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Martin | last post by:
This post asks two questions, which I've illustrated in one C source file (see below), which clean compiles on my GNU compiler. 1. In K&R2, Section A8.9 it says "Declarations whose storage class...
1
by: LedZep | last post by:
This program has to use a stack to determine whether a string is a palindrome (a string that is spelled identically backward and forward). The program has to ignore spaces, case sensitivity and...
6
by: Michael Isaacs | last post by:
Regarding use of enum's, I am wondering what the cost of memory is when creating the enumeration on the calling side, and then using it on the function/method side. See example below. If I...
7
by: Tiraman | last post by:
Hi , I have 2 Questions About Using Enum 1) i have the following Enum under my class but if i need to use it i must use it like this ConstantsFileSystem.CREATE_FILE how can i use it just...
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
3
by: Cmtk Software | last post by:
I'm trying to define an enum which will be used from unmanaged c++, C++/CLI managed c++ and from C#. I defined the following enum in a VS dll project set to be compiled with the /clr switch: ...
9
by: subramanian | last post by:
Hello. Consider the following code fragment : enum TestEnum { val1 = 10, val2 = 100, val3 = 1000 }; class Test { public : enum TestEnum { val1 = 1, val2 val3 }; Test(int i = 0, int j = 0,...
4
by: ice8595 | last post by:
Hi there, I'm fairly new at this, and I am having a bit of trouble wrapping my head around some concepts of enum for a project. So any help would be greatly appreciated. Essentially I'm...
0
by: csharpula csharp | last post by:
Hello , I have 2 questions about enums: 1) How can I recognize defined enum in other projects ,do I have to add the full namespace path before it such as: Projects.New...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.