Liguidsoul
03-03-2005, 01:40 AM
Three files:
card.h
// Chapter 6 of C++ How to Program
// Debugging Problem (card.h)
#ifndef CARD_H
#define CARD_H
// class card definition
class Card {
public:
void Card();
void Card( int, int );
void ~Card();
void setSuit( int );
int getSuit() const;
void setValue( int );
int getValue() const;
void print() const;
private:
int suit = 4;
int value = 1;
bool validCard() const;
}; // end class Card
#endif // CARD_H
card.cpp
// Chapter 6 of C++ How to Program
// Debugging Problem (card.cpp)
#include <iostream>
using std::cout;
using std::endl;
#include "card.h"
// default constructor
void Card::Card()
{
suit = 4;
value = 1;
} // end class Card constructor
// constructor
Card::Card( int s, int v )
{
suit = s; value = v;
} // end class Card constructor
// destructor
Card::~Card()
{
cout << "The destructor has been invoked\n";
} // end class Card destructor
// set suit
void Card::setSuit( int s )
{
suit = s;
} // end function setSuit
// set value
void Card::setValue( int v )
{
value = v;
} // end function setValue
// function print definition
void print()
{
// is card valid
if ( !validCard() ) {
cout << "This card is not valid\n";
return;
} // end if
cout << "This is the: ";
// determine face of card
switch ( value ) {
case 1:
cout << "Ace ";
break;
case 11:
cout << "Jack ";
break;
case 12:
cout << "Queen ";
break;
case 13:
cout << "King ";
break;
default:
cout << value << " ";
} // end switch
// determine suit
switch ( suit ) {
case 1:
cout << "of clubs\n";
break;
case 2:
cout << "of diamonds\n";
break;
case 3:
cout << "of hearts\n";
break;
case 4:
cout << "of spades\n";
break;
default:
cout << "\ninvalid suit\n";
} // end switch
} // end function print
// return suit
int Card::getSuit()
{
return suit;
} // end function getSuit
// return value
int Card::getValue()
{
return value;
} // end function getValue
// function validCard definition
bool validCard()
{
return value >= 1 && value <= 13 && suit >= 1 && suit <= 4;
} // end function validCard
debugging06.cpp
// Chapter 6 of C++ How to Program
// Debugging Problem
#include <iostream>
using std::cout;
using std::endl;
#include "card.h"
int main()
{
Card c1;
Card c2( 3, 4 );
Card c3( 1, 14 );
Card *p1 = &c2;
c1.print();
c2.print();
c3.print();
p1->print();
cout << endl;
c1.setSuit( p1->getSuit() );
c3.value = 12;
p1->value = 5;
c1.print();
c2.print();
c3.print();
*p1.print();
cout << endl;
return 0;
} // end main
The errors are something along the lines of this:
In file included from debugging06.cpp:9:
card.h:11: return type specification for constructor invalid
card.h:12: return type specification for constructor invalid
card.h:13: return type specification for destructor invalid
card.h:24: ANSI C++ forbids initialization of member `suit'
card.h:24: making `suit' static
card.h:24: ANSI C++ forbids in-class initialization of non-const static member `
suit'
card.h:25: ANSI C++ forbids initialization of member `value'
card.h:25: making `value' static
card.h:25: ANSI C++ forbids in-class initialization of non-const static member `
value'
debugging06.cpp: In function `int main()':
card.h:25: `int Card::value' is private
debugging06.cpp:26: within this context
card.h:25: `int Card::value' is private
debugging06.cpp:27: within this context
debugging06.cpp:32: request for member `print' in `p1', which is of non-aggregat
e type `Card *'
I do not need you to fix every single error... just whatever you can notice off-hand that is obvious. Thanks!
card.h
// Chapter 6 of C++ How to Program
// Debugging Problem (card.h)
#ifndef CARD_H
#define CARD_H
// class card definition
class Card {
public:
void Card();
void Card( int, int );
void ~Card();
void setSuit( int );
int getSuit() const;
void setValue( int );
int getValue() const;
void print() const;
private:
int suit = 4;
int value = 1;
bool validCard() const;
}; // end class Card
#endif // CARD_H
card.cpp
// Chapter 6 of C++ How to Program
// Debugging Problem (card.cpp)
#include <iostream>
using std::cout;
using std::endl;
#include "card.h"
// default constructor
void Card::Card()
{
suit = 4;
value = 1;
} // end class Card constructor
// constructor
Card::Card( int s, int v )
{
suit = s; value = v;
} // end class Card constructor
// destructor
Card::~Card()
{
cout << "The destructor has been invoked\n";
} // end class Card destructor
// set suit
void Card::setSuit( int s )
{
suit = s;
} // end function setSuit
// set value
void Card::setValue( int v )
{
value = v;
} // end function setValue
// function print definition
void print()
{
// is card valid
if ( !validCard() ) {
cout << "This card is not valid\n";
return;
} // end if
cout << "This is the: ";
// determine face of card
switch ( value ) {
case 1:
cout << "Ace ";
break;
case 11:
cout << "Jack ";
break;
case 12:
cout << "Queen ";
break;
case 13:
cout << "King ";
break;
default:
cout << value << " ";
} // end switch
// determine suit
switch ( suit ) {
case 1:
cout << "of clubs\n";
break;
case 2:
cout << "of diamonds\n";
break;
case 3:
cout << "of hearts\n";
break;
case 4:
cout << "of spades\n";
break;
default:
cout << "\ninvalid suit\n";
} // end switch
} // end function print
// return suit
int Card::getSuit()
{
return suit;
} // end function getSuit
// return value
int Card::getValue()
{
return value;
} // end function getValue
// function validCard definition
bool validCard()
{
return value >= 1 && value <= 13 && suit >= 1 && suit <= 4;
} // end function validCard
debugging06.cpp
// Chapter 6 of C++ How to Program
// Debugging Problem
#include <iostream>
using std::cout;
using std::endl;
#include "card.h"
int main()
{
Card c1;
Card c2( 3, 4 );
Card c3( 1, 14 );
Card *p1 = &c2;
c1.print();
c2.print();
c3.print();
p1->print();
cout << endl;
c1.setSuit( p1->getSuit() );
c3.value = 12;
p1->value = 5;
c1.print();
c2.print();
c3.print();
*p1.print();
cout << endl;
return 0;
} // end main
The errors are something along the lines of this:
In file included from debugging06.cpp:9:
card.h:11: return type specification for constructor invalid
card.h:12: return type specification for constructor invalid
card.h:13: return type specification for destructor invalid
card.h:24: ANSI C++ forbids initialization of member `suit'
card.h:24: making `suit' static
card.h:24: ANSI C++ forbids in-class initialization of non-const static member `
suit'
card.h:25: ANSI C++ forbids initialization of member `value'
card.h:25: making `value' static
card.h:25: ANSI C++ forbids in-class initialization of non-const static member `
value'
debugging06.cpp: In function `int main()':
card.h:25: `int Card::value' is private
debugging06.cpp:26: within this context
card.h:25: `int Card::value' is private
debugging06.cpp:27: within this context
debugging06.cpp:32: request for member `print' in `p1', which is of non-aggregat
e type `Card *'
I do not need you to fix every single error... just whatever you can notice off-hand that is obvious. Thanks!
