| | |
help for error
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2006
Posts: 25
Reputation:
Solved Threads: 0
hello,
pls find out why code is not work for solitaire game...
Thanks in advance.:rolleyes:
code:
pls find out why code is not work for solitaire game...
Thanks in advance.:rolleyes:
code:
C++ Syntax (Toggle Plain Text)
#include<iostream> using namespace std; /*****CLASS PLAYING CARD*****/ class PlayingCard { private: int rank;//integer 1-13 int suit;//integer0-3 char color;//red('r') or black('b') public: PlayingCard(int,int); PlayingCard(); void display(); ~PlayingCard(); const static int diamond; const static int heart; const static int spade; const static int club; }; /***** CLASS MAKING PILE OF CARDS*****/ class PileofCards { private: PlayingCard *pile;//pointer to array of playing cards int top;//last element added to array int size;//no. of cards in pile int position;//position of pile amongst others public: PileofCards(int,int); ~PileofCards(); PlayingCard Peek(); PlayingCard Remove(); void display(); void Add(PlayingCard); bool IsEmpty(); bool IsFull(); }; /***** CLASS DECK OF CARDS*****/ class Deck { private: PlayingCard *deck[52]; int size; public: Deck(); int getSize(); bool IsEmpty(); PlayingCard getCard(int i); void Display(); PlayingCard removeCard(int i); ~Deck(); }; /*****CLASS SOLITIRE*****/ class Solitire{ private: Deck deckofCards; PileofCards shuffled; public: Solitire(); void shuffle(); void display(); }; Solitire::Solitire():shuffled(52,1) {} /*****INITIALIZING*****/ const int PlayingCard::diamond=0; const int PlayingCard::heart=1; const int PlayingCard::spade=2; const int PlayingCard::club=3; /*****CONSTRUCTOR PLAYING CARD*****/ PlayingCard::PlayingCard(int X,int Y) { rank=X; suit=Y; if(Y==0 || Y==1) { color='r'; } else if(Y==2 || Y==3) { color='b'; } else { cout<<"invalid suit,object not created"<<endl; } } /*****CONSTRUCTOR OVERLOADED*****/ PlayingCard::PlayingCard() { } /*****destructor*****/ PlayingCard::~PlayingCard() { } /*****CONSTRUCTOR PILE OF CARDS*****/ PileofCards::PileofCards(int X,int Y) { size=X; position=Y; pile= new PlayingCard[size]; top=-1;//empty array } /*****DESTRUCTOR*****/ PileofCards::~PileofCards() { delete [] pile; } /*****IS EMPTY*****/ bool PileofCards::IsEmpty() { if(top==-1) { cout<<"pile empty"<<endl; return true; } else { return false; } } /*****IS FULL*****/ bool PileofCards::IsFull() { if(top==size-1) { cout<<"sorry cannot add since pile is full"<<endl; return true; } else { return false; } } /*****ADDING PLAYING CARD TO THE PILE*****/ void PileofCards::Add(PlayingCard X) { if(!IsFull()) { pile[top+1]=X; top++; } } /*****REMOVING CARD FROM THE PILE*****/ PlayingCard PileofCards::Remove() { if(!IsEmpty()) { top--; } return pile[top+1]; } /*****PEEKING TOP OF THE PILE*****/ PlayingCard PileofCards::Peek() { return pile [top]; } /*****DISPLAY....PLAYING CARD*****/ void PlayingCard::display() { cout<<rank<<" "<<suit<<" "<<color<<endl; } /*****CONSTRUCTOR DECK*****/ Deck::deck() { int j=0; for(int i=1;i<=13;i++) { deck[j]=new PlayingCard(i,PlayingCard::spade); j++; } for(int k=1;k<=13;k++) { deck[j]=new PlayingCard(k,PlayingCard::diamond); j++; } for(int l=1;l<=13;l++) { deck[j]=new PlayingCard(l,PlayingCard::heart); j++; } for(int m=1;m<=13;m++) { deck[j]=new PlayingCard(m,PlayingCard::club); j++; } int size=52; } /*****DESTRUCTOR DECK*****/ Deck::~Deck() { if(!IsEmpty()) { for(int i=0;i<size;i++) { if(deck[i]!=NULL) { delete deck[i]; } } } else { delete [] deck; } } /*****GET SIZE*****/ int Deck::getSize() { return size; } /*****IS EMPTY....DECK*****/ bool Deck::IsEmpty() { if(getSize()==0) { return true; } else return false; } /*****GETCARD*****/ PlayingCard Deck::getCard(int j) { return *deck[j]; } /*****DISPLAY....DECK*****/ void Deck:display() { for(int i=0;i<size;i++) { deck[i]->display(); } } /*****REMOVE...DECK*****/ PlayingCard Deck::removeCard(int i) { PlayingCard temp; temp=getCard(i); delete deck[i]; if(!IsEmpty()) { for(int j=i;j<size;j++) { deck[j]=deck[j+1]; } } size--; return temp; } /*****SHUFFLE*****/ void Solitire::shuffle() { int i; while (!deckofCards.IsEmpty()) { i = rand()%deckofCards.getSize(); // cout<<"Remove Card \n"; shuffled.Add(deckofCards.removeCard(i)); } } /*****DISPLAY...SOLITIRE*****/ void Solitire::display() { if(!shuffled.IsEmpty()) { shuffled.display(); } } /*****DISPLAY...PILE OF CARDS*****/ void PileofCards::display() { int i=0; while(i<=top) { pile->display(); i++; pile++; } cout<<i<<endl; } /*****MAIN*****/ int main() { PlayingCard A(3,PlayingCard::spade); PlayingCard B(2,PlayingCard::spade); PlayingCard C(4,PlayingCard::heart); PlayingCard D(5,PlayingCard::club); PlayingCard E(3,PlayingCard::diamond); PlayingCard temp (3,PlayingCard::heart); PileofCards pile1(5,1); //cout<<"blah"<<endl; pile1.Add(A); pile1.Add(B); pile1.Add(C); pile1.Add(D); pile1.Add(E); pile1.Add(temp);//displays error //cout<<"blah"<<endl; temp=pile1.Remove(); temp.display(); temp=pile1.Remove(); temp.display(); temp=pile1.Remove(); temp.display(); temp=pile1.Remove(); temp.display(); temp=pile1.Remove(); temp.display(); temp=pile1.Remove();//displays error Deck D1; PlayingCard F(1,1); cout<<"original deck"<<endl; D1.Display(); // Original Deck- 52 cards should be displayed cout<<"removed cards"<<endl;//index from 0-51 F = D1.removeCard(1); F.display(); F = D1.removeCard(1); F.display(); F = D1.removeCard(1); F.display(); // three cards removed cout<<"final deck after removal"<<endl; D1.Display(); //49 cards should be displayed now. 3 cards are already removed cout<<"loop empties deck"<<endl; int i=0; while(!D1.IsEmpty()) { A = D1.removeCard(i); A.display(); } cout<<"emptied"<<endl; Solitire S; S.display(); //shuffled pile is empty- nothing should be displayed S.shuffle(); S.display(); //Shuffled pile now contains 52 shuffled cards. return 0; }
Last edited by ~s.o.s~; Dec 30th, 2006 at 4:42 pm. Reason: Fixed code tags, learn to use them.
Not without telling us what is it's doing wrong. Yuo have to tell us what the ptogram is doing, and what it should be doing instead. And don't forget to read the announcement above about BBCodes so you can post the code readably.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
•
•
Join Date: Nov 2006
Posts: 25
Reputation:
Solved Threads: 0
Sorry for code... it make confuse to findout why..
when I ran that code .. I got three error.. might be it from Deck..
Error 1 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Error 2 error C2063: 'Deck::deck' : not a function
Warning 3 warning C4154: deletion of an array expression; conversion to pointer supplied
pls help me to get it work.. thanks in advance.
when I ran that code .. I got three error.. might be it from Deck..
Error 1 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Error 2 error C2063: 'Deck::deck' : not a function
Warning 3 warning C4154: deletion of an array expression; conversion to pointer supplied
pls help me to get it work.. thanks in advance.
C++ Syntax (Toggle Plain Text)
Error 1 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Which line is this on?
C++ Syntax (Toggle Plain Text)
Warning 3 warning C4154: deletion of an array expression; conversion to pointer supplied
[edit] I get more errors than that.
MINGW
C++ Syntax (Toggle Plain Text)
sourceFile.cpp:171: ISO C++ forbids declaration of `deck' with no type sourceFile.cpp:171: no ` int Deck::deck()' member function declared in class `Deck' sourceFile.cpp:238: syntax error before `:' token sourceFile.cpp:240: `size' was not declared in this scope sourceFile.cpp:240: parse error before `;' token sourceFile.cpp:240: syntax error before `++' token sourceFile.cpp:372:2: warning: no newline at end of file
MSVC
C++ Syntax (Toggle Plain Text)
sourceFile.cpp sourceFile.cpp(171) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int sourceFile.cpp(171) : error C2063: 'Deck::deck' : not a function sourceFile.cpp(214) : warning C4154: deletion of an array expression; conversion to pointer supplied sourceFile.cpp(238) : error C2470: 'Deck' : looks like a function definition, but there is no parameter list; skipping apparent body
Last edited by dwks; Dec 30th, 2006 at 7:09 pm.
dwk
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
I don't have a line-numbering editor on this computer, and I'm not counting to 214. Post the actual line that is causing the error.
dwk
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
Okay, here's your problem.
deck() doesn't match the class name Deck so it isn't a constructor. C++ is case-sensitive. Use a constructor name that matches the class name exactly -- in this case, Deck.
C++ Syntax (Toggle Plain Text)
Deck::deck()
dwk
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
•
•
Join Date: Nov 2006
Posts: 25
Reputation:
Solved Threads: 0
but Deck is constructor..I cnt out anytype or void at there..but if i let it like that error again .. with not a function like before..
code:
Deck::deck()
{
int j=0;
for(int i=1;i<=13;i++)
{
deck[j]=new PlayingCard(i,PlayingCard::spade);
j++;
}
for(int k=1;k<=13;k++)
{
deck[j]=new PlayingCard(k,PlayingCard::diamond);
j++;
}
for(int l=1;l<=13;l++)
{
deck[j]=new PlayingCard(l,PlayingCard::heart);
j++;
}
for(int m=1;m<=13;m++)
{
deck[j]=new PlayingCard(m,PlayingCard::club);
j++;
}
int size=52;
}
/*****DESTRUCTOR DECK*****/
Deck::~Deck()
{
if(!IsEmpty())
{
for(int i=0;i<size;i++)
{
if(deck[i]!=NULL)
{
delete deck[i];
}
}
}
else
{
delete [] deck;
}
}
/*****GET SIZE*****/
code:
Deck::deck()
{
int j=0;
for(int i=1;i<=13;i++)
{
deck[j]=new PlayingCard(i,PlayingCard::spade);
j++;
}
for(int k=1;k<=13;k++)
{
deck[j]=new PlayingCard(k,PlayingCard::diamond);
j++;
}
for(int l=1;l<=13;l++)
{
deck[j]=new PlayingCard(l,PlayingCard::heart);
j++;
}
for(int m=1;m<=13;m++)
{
deck[j]=new PlayingCard(m,PlayingCard::club);
j++;
}
int size=52;
}
/*****DESTRUCTOR DECK*****/
Deck::~Deck()
{
if(!IsEmpty())
{
for(int i=0;i<size;i++)
{
if(deck[i]!=NULL)
{
delete deck[i];
}
}
}
else
{
delete [] deck;
}
}
/*****GET SIZE*****/
There's actually only 2 or 3 typos in the whole program - even if the compilers report more. Here's what I changed to make it compile:
Same problem here:
But even though it compiles, you've got a few bugs in there, too.
Hope this helps
/*****CONSTRUCTOR DECK*****/
Deck::deck() // you previously declared it as Deck::Deck
{
int j=0;
for(int i=1;i<=13;i++)
{
deck[j]=new PlayingCard(i,PlayingCard::spade);
j++;
}/*****DISPLAY....DECK*****/
void Deck:display() // missing capitalization, needs extra ':'
{
for(int i=0;i<size;i++)
{
deck[i]->display();
}But even though it compiles, you've got a few bugs in there, too.
Hope this helps
"Technological progress is like an axe in the hands of a pathological criminal."
See this line?
It should look like this.
[edit] Too slow. [/edit]
Deck::deck()Deck::Deck()[edit] Too slow. [/edit]
Last edited by dwks; Dec 30th, 2006 at 7:33 pm.
dwk
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
![]() |
Similar Threads
- Code 19 Registry Error (Windows NT / 2000 / XP)
- Error Loading operating System (Windows NT / 2000 / XP)
- svchost.exe error (Windows NT / 2000 / XP)
- New Hardware Causing Error (Windows NT / 2000 / XP)
- office 2000 install error (Windows NT / 2000 / XP)
- VMWare Unrecoverable Error (*nix Software)
- Error in Wrox Book (Perl)
Other Threads in the C++ Forum
- Previous Thread: passing data to a program
- Next Thread: point me in the right direction - Exam/quiz etc result calculating programme
| Thread Tools | Search this Thread |
api array based beginner bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion count database delete deploy desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project python random read recursion recursive return sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






