help for error

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2006
Posts: 25
Reputation: sTorM is an unknown quantity at this point 
Solved Threads: 0
sTorM sTorM is offline Offline
Light Poster

help for error

 
0
  #1
Dec 30th, 2006
hello,
pls find out why code is not work for solitaire game...
Thanks in advance.:rolleyes:
code:
  1. #include<iostream>
  2. using namespace std;
  3. /*****CLASS PLAYING CARD*****/
  4. class PlayingCard
  5. {
  6. private:
  7. int rank;//integer 1-13
  8. int suit;//integer0-3
  9. char color;//red('r') or black('b')
  10. public:
  11. PlayingCard(int,int);
  12. PlayingCard();
  13. void display();
  14. ~PlayingCard();
  15. const static int diamond;
  16. const static int heart;
  17. const static int spade;
  18. const static int club;
  19. };
  20. /***** CLASS MAKING PILE OF CARDS*****/
  21. class PileofCards
  22. {
  23. private:
  24. PlayingCard *pile;//pointer to array of playing cards
  25. int top;//last element added to array
  26. int size;//no. of cards in pile
  27. int position;//position of pile amongst others
  28. public:
  29. PileofCards(int,int);
  30. ~PileofCards();
  31. PlayingCard Peek();
  32. PlayingCard Remove();
  33. void display();
  34. void Add(PlayingCard);
  35. bool IsEmpty();
  36. bool IsFull();
  37. };
  38.  
  39. /***** CLASS DECK OF CARDS*****/
  40. class Deck
  41. {
  42. private:
  43. PlayingCard *deck[52];
  44. int size;
  45. public:
  46. Deck();
  47. int getSize();
  48. bool IsEmpty();
  49. PlayingCard getCard(int i);
  50. void Display();
  51. PlayingCard removeCard(int i);
  52. ~Deck();
  53. };
  54. /*****CLASS SOLITIRE*****/
  55. class Solitire{
  56.  
  57. private:
  58. Deck deckofCards;
  59. PileofCards shuffled;
  60. public:
  61. Solitire();
  62. void shuffle();
  63. void display();
  64. };
  65. Solitire::Solitire():shuffled(52,1)
  66. {}
  67.  
  68. /*****INITIALIZING*****/
  69. const int PlayingCard::diamond=0;
  70. const int PlayingCard::heart=1;
  71. const int PlayingCard::spade=2;
  72. const int PlayingCard::club=3;
  73. /*****CONSTRUCTOR PLAYING CARD*****/
  74. PlayingCard::PlayingCard(int X,int Y)
  75. {
  76. rank=X;
  77. suit=Y;
  78. if(Y==0 || Y==1)
  79. {
  80. color='r';
  81. }
  82. else if(Y==2 || Y==3)
  83. {
  84. color='b';
  85. }
  86. else
  87. {
  88. cout<<"invalid suit,object not created"<<endl;
  89. }
  90. }
  91. /*****CONSTRUCTOR OVERLOADED*****/
  92. PlayingCard::PlayingCard()
  93. {
  94. }
  95. /*****destructor*****/
  96. PlayingCard::~PlayingCard()
  97. {
  98. }
  99.  
  100. /*****CONSTRUCTOR PILE OF CARDS*****/
  101. PileofCards::PileofCards(int X,int Y)
  102. {
  103. size=X;
  104. position=Y;
  105. pile= new PlayingCard[size];
  106. top=-1;//empty array
  107. }
  108. /*****DESTRUCTOR*****/
  109. PileofCards::~PileofCards()
  110. {
  111. delete [] pile;
  112. }
  113. /*****IS EMPTY*****/
  114. bool PileofCards::IsEmpty()
  115. {
  116. if(top==-1)
  117. {
  118. cout<<"pile empty"<<endl;
  119. return true;
  120. }
  121. else
  122. {
  123. return false;
  124. }
  125. }
  126. /*****IS FULL*****/
  127. bool PileofCards::IsFull()
  128. {
  129. if(top==size-1)
  130. {
  131. cout<<"sorry cannot add since pile is full"<<endl;
  132. return true;
  133. }
  134. else
  135. {
  136. return false;
  137. }
  138.  
  139.  
  140. }
  141. /*****ADDING PLAYING CARD TO THE PILE*****/
  142. void PileofCards::Add(PlayingCard X)
  143. {
  144. if(!IsFull())
  145. {
  146. pile[top+1]=X;
  147. top++;
  148. }
  149. }
  150. /*****REMOVING CARD FROM THE PILE*****/
  151. PlayingCard PileofCards::Remove()
  152. {
  153. if(!IsEmpty())
  154. {
  155. top--;
  156. }
  157. return pile[top+1];
  158. }
  159. /*****PEEKING TOP OF THE PILE*****/
  160. PlayingCard PileofCards::Peek()
  161. {
  162. return pile [top];
  163. }
  164. /*****DISPLAY....PLAYING CARD*****/
  165. void PlayingCard::display()
  166. {
  167. cout<<rank<<" "<<suit<<" "<<color<<endl;
  168. }
  169. /*****CONSTRUCTOR DECK*****/
  170. Deck::deck()
  171. {
  172. int j=0;
  173. for(int i=1;i<=13;i++)
  174. {
  175. deck[j]=new PlayingCard(i,PlayingCard::spade);
  176. j++;
  177. }
  178.  
  179. for(int k=1;k<=13;k++)
  180. {
  181. deck[j]=new PlayingCard(k,PlayingCard::diamond);
  182. j++;
  183. }
  184.  
  185. for(int l=1;l<=13;l++)
  186. {
  187. deck[j]=new PlayingCard(l,PlayingCard::heart);
  188. j++;
  189. }
  190.  
  191. for(int m=1;m<=13;m++)
  192. {
  193. deck[j]=new PlayingCard(m,PlayingCard::club);
  194. j++;
  195. }
  196. int size=52;
  197. }
  198. /*****DESTRUCTOR DECK*****/
  199.  
  200. Deck::~Deck()
  201. {
  202. if(!IsEmpty())
  203. {
  204. for(int i=0;i<size;i++)
  205. {
  206. if(deck[i]!=NULL)
  207. {
  208. delete deck[i];
  209. }
  210. }
  211. }
  212. else
  213. {
  214. delete [] deck;
  215. }
  216. }
  217. /*****GET SIZE*****/
  218. int Deck::getSize()
  219. {
  220. return size;
  221. }
  222. /*****IS EMPTY....DECK*****/
  223. bool Deck::IsEmpty()
  224. {
  225. if(getSize()==0)
  226. {
  227. return true;
  228. }
  229. else
  230. return false;
  231. }
  232. /*****GETCARD*****/
  233. PlayingCard Deck::getCard(int j)
  234. {
  235. return *deck[j];
  236. }
  237. /*****DISPLAY....DECK*****/
  238. void Deck:display()
  239. {
  240. for(int i=0;i<size;i++)
  241. {
  242. deck[i]->display();
  243. }
  244.  
  245. }
  246. /*****REMOVE...DECK*****/
  247. PlayingCard Deck::removeCard(int i)
  248. {
  249.  
  250. PlayingCard temp;
  251. temp=getCard(i);
  252.  
  253. delete deck[i];
  254. if(!IsEmpty())
  255. {
  256. for(int j=i;j<size;j++)
  257. {
  258. deck[j]=deck[j+1];
  259. }
  260.  
  261. }
  262.  
  263. size--;
  264.  
  265. return temp;
  266. }
  267. /*****SHUFFLE*****/
  268. void Solitire::shuffle()
  269. {
  270. int i;
  271. while (!deckofCards.IsEmpty())
  272. {
  273. i = rand()%deckofCards.getSize();
  274. // cout<<"Remove Card \n";
  275. shuffled.Add(deckofCards.removeCard(i));
  276.  
  277. }
  278.  
  279. }
  280. /*****DISPLAY...SOLITIRE*****/
  281. void Solitire::display()
  282. {
  283.  
  284. if(!shuffled.IsEmpty())
  285. {
  286. shuffled.display();
  287. }
  288.  
  289. }
  290. /*****DISPLAY...PILE OF CARDS*****/
  291. void PileofCards::display()
  292. {
  293. int i=0;
  294. while(i<=top)
  295. {
  296. pile->display();
  297. i++;
  298. pile++;
  299. }
  300. cout<<i<<endl;
  301. }
  302. /*****MAIN*****/
  303. int main()
  304. {
  305. PlayingCard A(3,PlayingCard::spade);
  306. PlayingCard B(2,PlayingCard::spade);
  307. PlayingCard C(4,PlayingCard::heart);
  308. PlayingCard D(5,PlayingCard::club);
  309. PlayingCard E(3,PlayingCard::diamond);
  310.  
  311. PlayingCard temp (3,PlayingCard::heart);
  312.  
  313. PileofCards pile1(5,1);
  314.  
  315. //cout<<"blah"<<endl;
  316.  
  317. pile1.Add(A);
  318. pile1.Add(B);
  319. pile1.Add(C);
  320. pile1.Add(D);
  321. pile1.Add(E);
  322.  
  323. pile1.Add(temp);//displays error
  324.  
  325. //cout<<"blah"<<endl;
  326. temp=pile1.Remove();
  327. temp.display();
  328.  
  329. temp=pile1.Remove();
  330. temp.display();
  331.  
  332. temp=pile1.Remove();
  333. temp.display();
  334.  
  335. temp=pile1.Remove();
  336. temp.display();
  337.  
  338. temp=pile1.Remove();
  339. temp.display();
  340.  
  341. temp=pile1.Remove();//displays error
  342.  
  343. Deck D1;
  344. PlayingCard F(1,1);
  345. cout<<"original deck"<<endl;
  346. D1.Display(); // Original Deck- 52 cards should be displayed
  347.  
  348. cout<<"removed cards"<<endl;//index from 0-51
  349. F = D1.removeCard(1);
  350. F.display();
  351. F = D1.removeCard(1);
  352. F.display();
  353. F = D1.removeCard(1);
  354. F.display(); // three cards removed
  355.  
  356. cout<<"final deck after removal"<<endl;
  357. D1.Display(); //49 cards should be displayed now. 3 cards are already removed
  358. cout<<"loop empties deck"<<endl;
  359. int i=0;
  360. while(!D1.IsEmpty())
  361. {
  362. A = D1.removeCard(i);
  363. A.display();
  364. }
  365. cout<<"emptied"<<endl;
  366. Solitire S;
  367. S.display(); //shuffled pile is empty- nothing should be displayed
  368. S.shuffle();
  369. S.display(); //Shuffled pile now contains 52 shuffled cards.
  370.  
  371. return 0;
  372. }
Last edited by ~s.o.s~; Dec 30th, 2006 at 4:42 pm. Reason: Fixed code tags, learn to use them.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: help for error

 
0
  #2
Dec 30th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 25
Reputation: sTorM is an unknown quantity at this point 
Solved Threads: 0
sTorM sTorM is offline Offline
Light Poster

Re: help for error

 
0
  #3
Dec 30th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 251
Reputation: dwks has a spectacular aura about dwks has a spectacular aura about 
Solved Threads: 25
dwks's Avatar
dwks dwks is offline Offline
Posting Whiz in Training

Re: help for error

 
0
  #4
Dec 30th, 2006
  1. Error 1 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Use int function() or void function(), not just function().

Which line is this on?
  1. Warning 3 warning C4154: deletion of an array expression; conversion to pointer supplied

[edit] I get more errors than that.

MINGW
  1. sourceFile.cpp:171: ISO
  2. C++ forbids declaration of `deck' with no type
  3. sourceFile.cpp:171: no `
  4. int Deck::deck()' member function declared in class `Deck'
  5. sourceFile.cpp:238: syntax
  6. error before `:' token
  7. sourceFile.cpp:240: `size'
  8. was not declared in this scope
  9. sourceFile.cpp:240: parse
  10. error before `;' token
  11. sourceFile.cpp:240: syntax
  12. error before `++' token
  13. sourceFile.cpp:372:2: warning: no newline at end of file
  14.  

MSVC
  1. sourceFile.cpp
  2. sourceFile.cpp(171) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
  3. sourceFile.cpp(171) : error C2063: 'Deck::deck' : not a function
  4. sourceFile.cpp(214) : warning C4154: deletion of an array expression; conversion to pointer supplied
  5. sourceFile.cpp(238) : error C2470: 'Deck' : looks like a function definition, but there is no parameter list; skipping apparent body
[/edit]
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 25
Reputation: sTorM is an unknown quantity at this point 
Solved Threads: 0
sTorM sTorM is offline Offline
Light Poster

Re: help for error

 
0
  #5
Dec 30th, 2006
hey thanks a lot for help me..
warning is on line 214
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 251
Reputation: dwks has a spectacular aura about dwks has a spectacular aura about 
Solved Threads: 25
dwks's Avatar
dwks dwks is offline Offline
Posting Whiz in Training

Re: help for error

 
0
  #6
Dec 30th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 251
Reputation: dwks has a spectacular aura about dwks has a spectacular aura about 
Solved Threads: 25
dwks's Avatar
dwks dwks is offline Offline
Posting Whiz in Training

Re: help for error

 
0
  #7
Dec 30th, 2006
Okay, here's your problem.
  1. Deck::deck()
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.
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 25
Reputation: sTorM is an unknown quantity at this point 
Solved Threads: 0
sTorM sTorM is offline Offline
Light Poster

Re: help for error

 
0
  #8
Dec 30th, 2006
Originally Posted by sTorM View Post
hey thanks a lot for help me..
warning is on line 214
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*****/
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: help for error

 
0
  #9
Dec 30th, 2006
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:
/*****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++;
}
Same problem here:

/*****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."
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 251
Reputation: dwks has a spectacular aura about dwks has a spectacular aura about 
Solved Threads: 25
dwks's Avatar
dwks dwks is offline Offline
Posting Whiz in Training

Re: help for error

 
0
  #10
Dec 30th, 2006
See this line?
Deck::deck()
It should look like this.
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC