added more code
This commit is contained in:
BIN
CPE212/Project_02/Project02.pdf
Normal file
BIN
CPE212/Project_02/Project02.pdf
Normal file
Binary file not shown.
39
CPE212/Project_02/blackcard.cpp
Normal file
39
CPE212/Project_02/blackcard.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
// blackcard.cpp inherits from card
|
||||
#include "blackcard.h"
|
||||
|
||||
BlackCard::BlackCard(int v) : Card::Card(v) // Parameterized constructor that creates a black card with value v and unknown suit
|
||||
{
|
||||
Card::SetColor("black"); // set color to black
|
||||
}
|
||||
|
||||
|
||||
string BlackCard::Description() const // Outputs card characteristics - value and color as a string
|
||||
{
|
||||
int Bval = Card::GetValue();
|
||||
string Bcol = Card::GetColor();
|
||||
string d = "Value = "; // temporary variable used to accumulate result
|
||||
|
||||
switch (Bval) // Append card value to variable's value
|
||||
{
|
||||
case 2: d = d + "2"; break; // Number cards
|
||||
case 3: d = d + "3"; break;
|
||||
case 4: d = d + "4"; break;
|
||||
case 5: d = d + "5"; break;
|
||||
case 6: d = d + "6"; break;
|
||||
case 7: d = d + "7"; break;
|
||||
case 8: d = d + "8"; break;
|
||||
case 9: d = d + "9"; break;
|
||||
case 10: d = d + "10"; break;
|
||||
case 11: d = d + "J"; break; // Face cards
|
||||
case 12: d = d + "Q"; break;
|
||||
case 13: d = d + "K"; break;
|
||||
case 14: d = d + "A"; break;
|
||||
|
||||
default: d = d + "?"; break; // Unknown card
|
||||
}
|
||||
d=d+", Color = "; // adds color to output string
|
||||
if (Bcol=="black") d=d + "black";
|
||||
if (Bcol=="red") d=d + "red";
|
||||
else d=+ "unknown";
|
||||
return d; // Return string describing card value
|
||||
}
|
28
CPE212/Project_02/blackcard.h
Normal file
28
CPE212/Project_02/blackcard.h
Normal file
@ -0,0 +1,28 @@
|
||||
//
|
||||
// blackcard.h -- CPE 212-01, Fall 2010 -- Project02 -- Classes
|
||||
//
|
||||
// DO NOT MODIFY OR SUBMIT THIS FILE!!!
|
||||
//
|
||||
|
||||
#ifndef BLACKCARD_H
|
||||
#define BLACKCARD_H
|
||||
|
||||
#include "card.h"
|
||||
|
||||
class BlackCard : public Card
|
||||
{
|
||||
private:
|
||||
// No additional private members
|
||||
|
||||
public:
|
||||
// Constructors
|
||||
BlackCard(int v); // Creates a black card with value v and unknown suit
|
||||
|
||||
string Description() const; // Outputs card characteristics - value and color as a string
|
||||
// Hint: use base class Description method to generate part of
|
||||
// the description and append the color information at the end
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
BIN
CPE212/Project_02/blackcard.o
Normal file
BIN
CPE212/Project_02/blackcard.o
Normal file
Binary file not shown.
99
CPE212/Project_02/card.cpp
Normal file
99
CPE212/Project_02/card.cpp
Normal file
@ -0,0 +1,99 @@
|
||||
//
|
||||
// card.cpp -- CPE 212-01, Fall 2010 -- Project02 -- Classes
|
||||
//
|
||||
// Add the missing statements to complete each method below
|
||||
// and SUBMIT this file for grading !!!
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include "card.h"
|
||||
|
||||
Card::Card()
|
||||
// Default Constructor: Initializes value to 0, color to "unknown", and suit to 'U'
|
||||
{
|
||||
value=0;
|
||||
color = "Unknown";
|
||||
suit = 'U';
|
||||
}
|
||||
|
||||
|
||||
Card::Card(int v)
|
||||
// Parameterized Constructor: Initializes value to v, color to "unknown", and suit to 'U'
|
||||
{
|
||||
value=v;
|
||||
color = "Unknown";
|
||||
suit = 'U';
|
||||
}
|
||||
|
||||
|
||||
int Card::GetValue() const
|
||||
// Returns variable value
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
string Card::GetColor() const
|
||||
// Returns variable color
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
char Card::GetSuit() const
|
||||
// Returns variable suit
|
||||
{
|
||||
return suit;
|
||||
}
|
||||
|
||||
|
||||
void Card::SetValue(int v)
|
||||
// Sets value to v
|
||||
{
|
||||
value = v;
|
||||
}
|
||||
|
||||
|
||||
void Card::SetColor(string c)
|
||||
// Sets color to c
|
||||
{
|
||||
color = c;
|
||||
}
|
||||
|
||||
|
||||
void Card::SetSuit(char s)
|
||||
// Sets suit to s
|
||||
{
|
||||
suit = s;
|
||||
}
|
||||
|
||||
|
||||
string Card::Description() const
|
||||
// Outputs card characteristics - value as a string
|
||||
// DO NOT MODIFY THIS METHOD !!!!
|
||||
{
|
||||
string d = "Value = "; // temporary variable used to accumulate result
|
||||
|
||||
switch (value) // Append card value to variable's value
|
||||
{
|
||||
case 2: d = d + "2"; break; // Number cards
|
||||
case 3: d = d + "3"; break;
|
||||
case 4: d = d + "4"; break;
|
||||
case 5: d = d + "5"; break;
|
||||
case 6: d = d + "6"; break;
|
||||
case 7: d = d + "7"; break;
|
||||
case 8: d = d + "8"; break;
|
||||
case 9: d = d + "9"; break;
|
||||
case 10: d = d + "10"; break;
|
||||
case 11: d = d + "J"; break; // Face cards
|
||||
case 12: d = d + "Q"; break;
|
||||
case 13: d = d + "K"; break;
|
||||
case 14: d = d + "A"; break;
|
||||
|
||||
default: d = d + "?"; break; // Unknown card
|
||||
}
|
||||
|
||||
return d; // Return string describing card value
|
||||
}
|
||||
|
48
CPE212/Project_02/card.h
Normal file
48
CPE212/Project_02/card.h
Normal file
@ -0,0 +1,48 @@
|
||||
//
|
||||
// card.h -- CPE 212-01, Fall 2010 -- Project02 -- Classes
|
||||
//
|
||||
// Add the missing statements to complete the class declaration below
|
||||
// and SUBMIT this file for grading !!!
|
||||
//
|
||||
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
#ifndef CARD_H
|
||||
#define CARD_H
|
||||
|
||||
class Card // Class modeling Card ADT
|
||||
{
|
||||
private:
|
||||
int value; // Card value: 2-10 for number cards, 11-14 for JQKA; 0 for unknown
|
||||
string color; // Card color: "red", "black", or "unknown"
|
||||
char suit; // Card suit: 'H' for hearts, 'D' for diamonds, 'C' for clubs, 'S' for spades or 'U' for unknown
|
||||
|
||||
public:
|
||||
//******** Add Constructor Prototypes Below *********//
|
||||
Card(); // Default constructor prototype: creates card with value v, color unknown, and suit U
|
||||
|
||||
Card(int v); // Parameterized constructor prototype: creates card with value v, color unknown, and suit U
|
||||
|
||||
//******** Add Transformer Prototypes Below *********//
|
||||
void SetValue(int v); // SetValue prototype: Sets card value equal to v
|
||||
|
||||
void SetColor(string c); // SetColor prototype: Sets color value equal to c
|
||||
|
||||
void SetSuit(char s); // SetSuit prototype: Sets suit value equal to s
|
||||
|
||||
//******** Add Observer Prototypes Below *********//
|
||||
int GetValue() const; // GetValue prototype: Returns current value of value
|
||||
|
||||
string GetColor() const; // GetColor prototype: Returns current value of color
|
||||
|
||||
char GetSuit() const; // GetSuit prototype: Returns current value of suit
|
||||
|
||||
virtual string Description() const; // Description prototype: Polymorphic Function!!!
|
||||
// Outputs card characteristics - value as a string (see sample output from p01input1.txt)
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
BIN
CPE212/Project_02/card.o
Normal file
BIN
CPE212/Project_02/card.o
Normal file
Binary file not shown.
51
CPE212/Project_02/club.cpp
Normal file
51
CPE212/Project_02/club.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
// club inherits from blackcard
|
||||
#include "club.h"
|
||||
|
||||
Club::Club(int v) : BlackCard::BlackCard(v) // Parameterized constructor that creates a black card with value v and unknown suit
|
||||
{
|
||||
Club::SetSuit('C'); // sets suit to C
|
||||
BlackCard::SetColor("black");
|
||||
}
|
||||
|
||||
string Club::Description() const // Outputs card characteristics - value and color and suit as a string
|
||||
{
|
||||
int Cval = BlackCard::GetValue();
|
||||
string Ccol = BlackCard::GetColor();
|
||||
char Cst = BlackCard::GetSuit();
|
||||
string d = "Value = "; // temporary variable used to accumulate result
|
||||
|
||||
switch (Cval) // Append card value to variable's value
|
||||
{
|
||||
case 2: d = d + "2"; break; // Number cards
|
||||
case 3: d = d + "3"; break;
|
||||
case 4: d = d + "4"; break;
|
||||
case 5: d = d + "5"; break;
|
||||
case 6: d = d + "6"; break;
|
||||
case 7: d = d + "7"; break;
|
||||
case 8: d = d + "8"; break;
|
||||
case 9: d = d + "9"; break;
|
||||
case 10: d = d + "10"; break;
|
||||
|
||||
case 11: d = d + "J"; break; // Face cards
|
||||
case 12: d = d + "Q"; break;
|
||||
case 13: d = d + "K"; break;
|
||||
case 14: d = d + "A"; break;
|
||||
|
||||
default: d = d + "?"; break; // Unknown card
|
||||
}
|
||||
d = d + ", Color = "; // adds color to output string
|
||||
if (Ccol=="black") d = d + "black";
|
||||
if (Ccol=="red") d = d + "red";
|
||||
else d=+ "unknown";
|
||||
// appends suit to output string
|
||||
d =+ ", Suit = ";
|
||||
switch (Cst)
|
||||
{
|
||||
case 'H': d =+ "H"; break;
|
||||
case 'C': d =+ 'C'; break;
|
||||
case 'D': d =+ 'D'; break;
|
||||
case 'U': d =+ 'U'; break;
|
||||
}
|
||||
|
||||
return d; // Return string describing card value
|
||||
}
|
27
CPE212/Project_02/club.h
Normal file
27
CPE212/Project_02/club.h
Normal file
@ -0,0 +1,27 @@
|
||||
//
|
||||
// club.h -- CPE 212-01, Fall 2010 -- Project02 -- Classes
|
||||
//
|
||||
// DO NOT MODIFY OR SUBMIT THIS FILE!!!
|
||||
//
|
||||
|
||||
#ifndef CLUB_H
|
||||
#define CLUB_H
|
||||
|
||||
#include "blackcard.h"
|
||||
|
||||
class Club : public BlackCard
|
||||
{
|
||||
private:
|
||||
// No additional private members
|
||||
|
||||
public:
|
||||
// Constructors
|
||||
Club(int v); // Creates a black club card with value v
|
||||
|
||||
string Description() const; // Outputs card characteristics - value, color, suit
|
||||
// Hint: use base class Description method to generate part of
|
||||
// the description and append the suit information at the end
|
||||
};
|
||||
|
||||
#endif
|
||||
|
BIN
CPE212/Project_02/club.o
Normal file
BIN
CPE212/Project_02/club.o
Normal file
Binary file not shown.
51
CPE212/Project_02/diamond.cpp
Normal file
51
CPE212/Project_02/diamond.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
// Diamond inherits from redcard
|
||||
#include "diamond.h"
|
||||
|
||||
Diamond::Diamond(int v) : RedCard::RedCard(v) // Parameterized constructor that creates a black card with value v and suit s
|
||||
{
|
||||
Card::SetSuit('D'); // sets suit to D
|
||||
}
|
||||
RedCard::Card di; // allows access to functions in Card
|
||||
|
||||
string Diamond::Description() const // Outputs card characteristics - value and color and suit as a string
|
||||
{
|
||||
int Dval = Card::GetValue();
|
||||
string Dcol = Card::GetColor();
|
||||
char Dst = Card::GetSuit();
|
||||
string d = "Value = "; // temporary variable used to accumulate result
|
||||
|
||||
switch (Dval) // Append card value to variable's value
|
||||
{
|
||||
case 2: d = d + "2"; break; // Number cards
|
||||
case 3: d = d + "3"; break;
|
||||
case 4: d = d + "4"; break;
|
||||
case 5: d = d + "5"; break;
|
||||
case 6: d = d + "6"; break;
|
||||
case 7: d = d + "7"; break;
|
||||
case 8: d = d + "8"; break;
|
||||
case 9: d = d + "9"; break;
|
||||
case 10: d = d + "10"; break;
|
||||
|
||||
case 11: d = d + "J"; break; // Face cards
|
||||
case 12: d = d + "Q"; break;
|
||||
case 13: d = d + "K"; break;
|
||||
case 14: d = d + "A"; break;
|
||||
|
||||
default: d = d + "?"; break; // Unknown card
|
||||
}
|
||||
d = d + ", Color = "; // adds color to output string
|
||||
if (Dcol=="black") d = d + "black";
|
||||
if (Dcol=="red") d = d + "red";
|
||||
else d=+ "unknown";
|
||||
// appends suit to output string
|
||||
d =+ ", Suit = ";
|
||||
switch (Dst)
|
||||
{
|
||||
case 'H': d =+ "H"; break;
|
||||
case 'C': d =+ 'C'; break;
|
||||
case 'D': d =+ 'D'; break;
|
||||
case 'U': d =+ 'U'; break;
|
||||
}
|
||||
|
||||
return d; // Return string describing card value
|
||||
}
|
27
CPE212/Project_02/diamond.h
Normal file
27
CPE212/Project_02/diamond.h
Normal file
@ -0,0 +1,27 @@
|
||||
//
|
||||
// diamond.h -- CPE 212-01, Fall 2010 -- Project02 -- Classes
|
||||
//
|
||||
// DO NOT MODIFY OR SUBMIT THIS FILE!!!
|
||||
//
|
||||
|
||||
#ifndef DIAMOND_H
|
||||
#define DIAMOND_H
|
||||
|
||||
#include "redcard.h"
|
||||
|
||||
class Diamond : public RedCard
|
||||
{
|
||||
private:
|
||||
// No additional private members
|
||||
|
||||
public:
|
||||
// Constructors
|
||||
Diamond(int v); // Creates a red diamond card with value v
|
||||
|
||||
string Description() const; // Outputs card characteristics - value, color, suit
|
||||
// Hint: use base class Description method to generate part of
|
||||
// the description and append the suit information at the end
|
||||
};
|
||||
|
||||
#endif
|
||||
|
BIN
CPE212/Project_02/diamond.o
Normal file
BIN
CPE212/Project_02/diamond.o
Normal file
Binary file not shown.
51
CPE212/Project_02/heart.cpp
Normal file
51
CPE212/Project_02/heart.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
// heart inherits from redcard
|
||||
#include "heart.h"
|
||||
|
||||
Heart::Heart(int v) : RedCard::RedCard(v) // Parameterized constructor that creates a black card with value v and unknown suit
|
||||
{
|
||||
Card::SetSuit('H'); // sets suit to H
|
||||
}
|
||||
RedCard::Card ht; // allows access to functions in Card
|
||||
|
||||
string Heart::Description() const // Outputs card characteristics - value and color and suit as a string
|
||||
{
|
||||
int Hval = Card::GetValue();
|
||||
string Hcol = Card::GetColor();
|
||||
char Hst = Card::GetSuit();
|
||||
string d = "Value = "; // temporary variable used to accumulate result
|
||||
|
||||
switch (Hval) // Append card value to variable's value
|
||||
{
|
||||
case 2: d = d + "2"; break; // Number cards
|
||||
case 3: d = d + "3"; break;
|
||||
case 4: d = d + "4"; break;
|
||||
case 5: d = d + "5"; break;
|
||||
case 6: d = d + "6"; break;
|
||||
case 7: d = d + "7"; break;
|
||||
case 8: d = d + "8"; break;
|
||||
case 9: d = d + "9"; break;
|
||||
case 10: d = d + "10"; break;
|
||||
|
||||
case 11: d = d + "J"; break; // Face cards
|
||||
case 12: d = d + "Q"; break;
|
||||
case 13: d = d + "K"; break;
|
||||
case 14: d = d + "A"; break;
|
||||
|
||||
default: d = d + "?"; break; // Unknown card
|
||||
}
|
||||
d = d + ", Color = "; // adds color to output string
|
||||
if (Hcol=="black") d = d + "black";
|
||||
if (Hcol=="red") d = d + "red";
|
||||
else d=+ "unknown";
|
||||
// appends suit to output string
|
||||
d =+ ", Suit = ";
|
||||
switch (Hst)
|
||||
{
|
||||
case 'H': d =+ "H"; break;
|
||||
case 'C': d =+ 'C'; break;
|
||||
case 'D': d =+ 'D'; break;
|
||||
case 'U': d =+ 'U'; break;
|
||||
}
|
||||
|
||||
return d; // Return string describing card value
|
||||
}
|
28
CPE212/Project_02/heart.h
Normal file
28
CPE212/Project_02/heart.h
Normal file
@ -0,0 +1,28 @@
|
||||
//
|
||||
// heart.h -- CPE 212-01, Fall 2010 -- Project02 -- Classes
|
||||
//
|
||||
// DO NOT MODIFY OR SUBMIT THIS FILE!!!
|
||||
//
|
||||
|
||||
#ifndef HEART_H
|
||||
#define HEART_H
|
||||
|
||||
#include "redcard.h"
|
||||
|
||||
class Heart : public RedCard
|
||||
{
|
||||
private:
|
||||
// No additional private members
|
||||
|
||||
public:
|
||||
// Constructors
|
||||
Heart(int v); // Creates a red heart card with value v
|
||||
|
||||
string Description() const; // Outputs card characteristics - value, color, suit
|
||||
// Hint: use base class Description method to generate part of
|
||||
// the description and append the suit information at the end
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
BIN
CPE212/Project_02/heart.o
Normal file
BIN
CPE212/Project_02/heart.o
Normal file
Binary file not shown.
148
CPE212/Project_02/main.cpp
Normal file
148
CPE212/Project_02/main.cpp
Normal file
@ -0,0 +1,148 @@
|
||||
//
|
||||
// main.cpp -- Project02, CPE212 Fall 2010 -- Classes
|
||||
//
|
||||
// Driver program for Card program which is used to test each
|
||||
// class member function.
|
||||
//
|
||||
// DO NOT MODIFY OR SUBMIT THIS FILE
|
||||
//
|
||||
|
||||
// List of allowed include files appear below
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include "card.h"
|
||||
#include "heart.h"
|
||||
#include "diamond.h"
|
||||
#include "club.h"
|
||||
#include "spade.h"
|
||||
|
||||
|
||||
using namespace std; // Global using declaration
|
||||
|
||||
void Bar(); // Prototype for Bar function
|
||||
void Print(Card* someCard); // Prototype for Print function
|
||||
|
||||
|
||||
|
||||
// Start of main() function
|
||||
|
||||
int main (int argc, char * const argv[]) // Command-line arguments (more on this later)
|
||||
{
|
||||
ifstream inputs; // Input file stream variable for test file
|
||||
char op, ch; // Hold operation and optional char input from test file
|
||||
string comment; // Holds comment string input from test file
|
||||
Card* ptr = NULL; // Pointer to the current card
|
||||
int v; // Holds card value input from test file
|
||||
|
||||
|
||||
// Output usage message if test input file name is not provided
|
||||
if (argc != 2)
|
||||
{
|
||||
cout << "Usage:\n project02 <inputfile>\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Attempt to open test input file -- terminate if file does not open
|
||||
inputs.open(argv[1]);
|
||||
if (!inputs)
|
||||
{
|
||||
cout << "Error - unable to open input file" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Process comment line from input file
|
||||
getline(inputs, comment); // Input file header comment
|
||||
cout << endl << comment << endl << endl; // Output file header comment
|
||||
|
||||
|
||||
// Below is the primary loop that processes each operation appearing within the test file.
|
||||
// Starts with an initial priming read of first operation
|
||||
|
||||
inputs >> op; // Attempt to input first test operation from file
|
||||
|
||||
while (inputs) // While Not-EOF
|
||||
{
|
||||
switch (op) // Process operation input from test file
|
||||
{
|
||||
case '#': // Test file comment
|
||||
getline(inputs, comment); // Input and echo the comment appearing in the test file
|
||||
cout << '#' << comment << endl;
|
||||
break;
|
||||
|
||||
case 'p': // Print Card
|
||||
Print(ptr);
|
||||
cout << endl;
|
||||
break;
|
||||
|
||||
case 'b': // Print Bar
|
||||
Bar(); // Function definition appears at the end of this file
|
||||
break;
|
||||
|
||||
case '+': // Constructor
|
||||
inputs >> op; // Input card type into op
|
||||
|
||||
try
|
||||
{
|
||||
switch (op) // Invoke requested constructor with argument as required
|
||||
{
|
||||
case 'h': inputs >> v; cout << "Heart(" << v << ") -- "; ptr = new Heart(v); break;
|
||||
case 'd': inputs >> v; cout << "Diamond(" << v << ") -- "; ptr = new Diamond(v); break;
|
||||
case 'c': inputs >> v; cout << "Club(" << v << ") -- "; ptr = new Club(v); break;
|
||||
case 's': inputs >> v; cout << "Spade(" << v << ") -- "; ptr = new Spade(v); break;
|
||||
case 'b': inputs >> v; cout << "BlackCard(" << v << ") -- "; ptr = new BlackCard(v); break;
|
||||
case 'r': inputs >> v; cout << "RedCard(" << v << ") -- "; ptr = new RedCard(v); break;
|
||||
case 'x': inputs >> v; cout << "Card(" << v << ") -- "; ptr = new Card(v); break;
|
||||
case 'z': cout << "Card() -- "; ptr = new Card; break;
|
||||
default: cout << "Error: Unknown Card Type"; ptr = NULL; break;
|
||||
}
|
||||
cout << "Successful";
|
||||
}
|
||||
catch ( ... ) // Catch any exception thrown above
|
||||
{
|
||||
cout << "Failed";
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
break;
|
||||
|
||||
case '-': // Destructor
|
||||
delete ptr; // Deallocate card
|
||||
ptr = NULL; // Make sure that ptr is not a dangling pointer
|
||||
break;
|
||||
|
||||
default: // Error
|
||||
cout << "Error - unrecognized operation '" << op << "'" << endl;
|
||||
cout << "Terminating now..." << endl;
|
||||
return 1;
|
||||
break;
|
||||
}
|
||||
//cout << endl;
|
||||
|
||||
inputs >> op; // Attempt to input next command
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/************** Implementation of Print() and Bar() functions ********************/
|
||||
|
||||
// DO NOT MODIFY THIS CODE
|
||||
|
||||
void Bar()
|
||||
// Bar() -- prints horizontal bar
|
||||
{
|
||||
cout << "#################################################################" << endl;
|
||||
} // End Bar()
|
||||
|
||||
|
||||
void Print(Card* someCard)
|
||||
// Writes description of card to stdout
|
||||
{
|
||||
cout << someCard->Description(); // Hint: Polymorphic function
|
||||
}
|
||||
|
||||
/************** End of main.cpp ***************/
|
||||
|
||||
|
BIN
CPE212/Project_02/main.o
Normal file
BIN
CPE212/Project_02/main.o
Normal file
Binary file not shown.
43
CPE212/Project_02/makefile
Normal file
43
CPE212/Project_02/makefile
Normal file
@ -0,0 +1,43 @@
|
||||
# Project02 Makefile -- CPE 212-01, Fall 2010
|
||||
|
||||
project02: main.o card.o redcard.o blackcard.o heart.o diamond.o club.o spade.o
|
||||
g++ main.o card.o redcard.o blackcard.o heart.o diamond.o club.o spade.o -o project02
|
||||
|
||||
|
||||
main.o: main.cpp card.h redcard.h blackcard.h heart.h diamond.h club.h spade.h
|
||||
g++ -c main.cpp
|
||||
|
||||
|
||||
card.o: card.cpp card.h
|
||||
g++ -c card.cpp
|
||||
|
||||
|
||||
redcard.o: redcard.cpp redcard.h card.h
|
||||
g++ -c redcard.cpp
|
||||
|
||||
|
||||
blackcard.o: blackcard.cpp blackcard.h card.h
|
||||
g++ -c blackcard.cpp
|
||||
|
||||
|
||||
heart.o: heart.cpp heart.h redcard.h card.h
|
||||
g++ -c heart.cpp
|
||||
|
||||
|
||||
diamond.o: diamond.cpp diamond.h redcard.h card.h
|
||||
g++ -c diamond.cpp
|
||||
|
||||
|
||||
club.o: club.cpp club.h blackcard.h card.h
|
||||
g++ -c club.cpp
|
||||
|
||||
|
||||
spade.o: spade.cpp spade.h blackcard.h card.h
|
||||
g++ -c spade.cpp
|
||||
|
||||
|
||||
# Remove executable and all object files if they exist
|
||||
clean:
|
||||
rm *.o project02
|
||||
|
||||
|
67
CPE212/Project_02/p02input1.txt
Normal file
67
CPE212/Project_02/p02input1.txt
Normal file
@ -0,0 +1,67 @@
|
||||
# p02input1.txt - Test Card Class
|
||||
|
||||
b
|
||||
|
||||
# Test of default constructor
|
||||
+ z
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ x 2
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ x 9
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ x 10
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ x 11
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ x 12
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ x 13
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ x 14
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ x 15
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
67
CPE212/Project_02/p02input2.txt
Normal file
67
CPE212/Project_02/p02input2.txt
Normal file
@ -0,0 +1,67 @@
|
||||
# p02input2.txt - Test RedCard Class
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ r 1
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ r 2
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ r 9
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ r 10
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ r 11
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ r 12
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ r 13
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ r 14
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ r 15
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
68
CPE212/Project_02/p02input3.txt
Normal file
68
CPE212/Project_02/p02input3.txt
Normal file
@ -0,0 +1,68 @@
|
||||
# p02input3.txt - Test BlackCard Class
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ b 1
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ b 2
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ b 9
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ b 10
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ b 11
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ b 12
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ b 13
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ b 14
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ b 15
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
|
141
CPE212/Project_02/p02input4.txt
Normal file
141
CPE212/Project_02/p02input4.txt
Normal file
@ -0,0 +1,141 @@
|
||||
# p02input4.txt - Test Heart and Diamond Classes
|
||||
|
||||
b
|
||||
|
||||
# Test of Heart Class
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ h 1
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ h 2
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ h 9
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ h 10
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ h 11
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ h 12
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ h 13
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ h 14
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ h 15
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
b
|
||||
|
||||
|
||||
# Test of Diamond Class
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ d 1
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ d 2
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ d 9
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ d 10
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ d 11
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ d 12
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ d 13
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ d 14
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ d 15
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
|
141
CPE212/Project_02/p02input5.txt
Normal file
141
CPE212/Project_02/p02input5.txt
Normal file
@ -0,0 +1,141 @@
|
||||
# p02input5.txt - Test Club and Spade Classes
|
||||
|
||||
b
|
||||
|
||||
# Test of Club Class
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ c 1
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ c 2
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ c 9
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ c 10
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ c 11
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ c 12
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ c 13
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ c 14
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ c 15
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
b
|
||||
|
||||
|
||||
# Test of Spade Class
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ s 1
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ s 2
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ s 9
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ s 10
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ s 11
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ s 12
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ s 13
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ s 14
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
# Test of parameterized constructor
|
||||
+ s 15
|
||||
p
|
||||
-
|
||||
|
||||
b
|
||||
|
||||
|
BIN
CPE212/Project_02/project02
Normal file
BIN
CPE212/Project_02/project02
Normal file
Binary file not shown.
40
CPE212/Project_02/redcard.cpp
Normal file
40
CPE212/Project_02/redcard.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
// redcard inherits from card
|
||||
#include "redcard.h"
|
||||
|
||||
RedCard::RedCard(int v) : Card::Card(v) // Parameterized constructor that creates a red card with value v and unknown suit
|
||||
{
|
||||
Card::SetColor("red");
|
||||
}
|
||||
|
||||
|
||||
|
||||
string RedCard::Description() const // Outputs card characteristics - value and color as a string
|
||||
{
|
||||
int Rval = Card::GetValue();
|
||||
string Rcol = Card::GetColor();
|
||||
string d = "Value = "; // temporary variable used to accumulate result
|
||||
|
||||
switch (Rval) // Append card value to variable's value
|
||||
{
|
||||
case 2: d = d + "2"; break; // Number cards
|
||||
case 3: d = d + "3"; break;
|
||||
case 4: d = d + "4"; break;
|
||||
case 5: d = d + "5"; break;
|
||||
case 6: d = d + "6"; break;
|
||||
case 7: d = d + "7"; break;
|
||||
case 8: d = d + "8"; break;
|
||||
case 9: d = d + "9"; break;
|
||||
case 10: d = d + "10"; break;
|
||||
case 11: d = d + "J"; break; // Face cards
|
||||
case 12: d = d + "Q"; break;
|
||||
case 13: d = d + "K"; break;
|
||||
case 14: d = d + "A"; break;
|
||||
|
||||
default: d = d + "?"; break; // Unknown card
|
||||
}
|
||||
d = d + ", Color = "; // adds color to output string
|
||||
if (Rcol=="black") d = d + "black";
|
||||
if (Rcol=="red") d = d + "red";
|
||||
else d=+ "unknown";
|
||||
return d; // Return string describing card value
|
||||
}
|
27
CPE212/Project_02/redcard.h
Normal file
27
CPE212/Project_02/redcard.h
Normal file
@ -0,0 +1,27 @@
|
||||
//
|
||||
// redcards.h -- CPE 212-01, Fall 2010 -- Project02 -- Classes
|
||||
//
|
||||
// DO NOT MODIFY OR SUBMIT THIS FILE!!!
|
||||
//
|
||||
|
||||
#ifndef REDCARD_H
|
||||
#define REDCARD_H
|
||||
|
||||
#include "card.h"
|
||||
|
||||
class RedCard : public Card
|
||||
{
|
||||
private:
|
||||
// No additional private members
|
||||
|
||||
public:
|
||||
// Constructors
|
||||
RedCard(int v); // Creates a red card with value v and unknown suit
|
||||
|
||||
string Description() const; // Outputs card characteristics - value and color as a string
|
||||
// Hint: use base class Description method to generate part of
|
||||
// the description and append the color information at the end
|
||||
};
|
||||
|
||||
#endif
|
||||
|
BIN
CPE212/Project_02/redcard.o
Normal file
BIN
CPE212/Project_02/redcard.o
Normal file
Binary file not shown.
52
CPE212/Project_02/spade.cpp
Normal file
52
CPE212/Project_02/spade.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
// spade inherits from blackcard
|
||||
#include "spade.h"
|
||||
|
||||
Spade::Spade(int v) : BlackCard::BlackCard(v) // Parameterized constructor that creates a black card with value v and unknown suit
|
||||
{
|
||||
Card::SetSuit('S'); // sets suit to S
|
||||
|
||||
}
|
||||
Spade::Card sp; // allows access to functions in Card
|
||||
|
||||
string Spade::Description() const // Outputs card characteristics - value and color and suit as a string
|
||||
{
|
||||
int Sval = Card::GetValue();
|
||||
string Scol = Card::GetColor();
|
||||
char Sst = Card::GetSuit();
|
||||
string d = "Value = "; // temporary variable used to accumulate result
|
||||
|
||||
switch (Sval) // Append card value to variable's value
|
||||
{
|
||||
case 2: d = d + "2"; break; // Number cards
|
||||
case 3: d = d + "3"; break;
|
||||
case 4: d = d + "4"; break;
|
||||
case 5: d = d + "5"; break;
|
||||
case 6: d = d + "6"; break;
|
||||
case 7: d = d + "7"; break;
|
||||
case 8: d = d + "8"; break;
|
||||
case 9: d = d + "9"; break;
|
||||
case 10: d = d + "10"; break;
|
||||
|
||||
case 11: d = d + "J"; break; // Face cards
|
||||
case 12: d = d + "Q"; break;
|
||||
case 13: d = d + "K"; break;
|
||||
case 14: d = d + "A"; break;
|
||||
|
||||
default: d = d + "?"; break; // Unknown card
|
||||
}
|
||||
d = d + ", Color = "; // adds color to output string
|
||||
if (Scol=="black") d = d + "black";
|
||||
if (Scol=="red") d = d + "red";
|
||||
else d=+ "unknown";
|
||||
// appends suit to output string
|
||||
d =+ ", Suit = ";
|
||||
switch (Sst)
|
||||
{
|
||||
case 'H': d =+ "H"; break;
|
||||
case 'C': d =+ 'C'; break;
|
||||
case 'D': d =+ 'D'; break;
|
||||
case 'U': d =+ 'U'; break;
|
||||
}
|
||||
|
||||
return d; // Return string describing card value
|
||||
}
|
26
CPE212/Project_02/spade.h
Normal file
26
CPE212/Project_02/spade.h
Normal file
@ -0,0 +1,26 @@
|
||||
//
|
||||
// spade.h -- CPE 212-01, Fall 2010 -- Project02 -- Classes
|
||||
//
|
||||
// DO NOT MODIFY OR SUBMIT THIS FILE!!!
|
||||
//
|
||||
|
||||
#ifndef SPADE_H
|
||||
#define SPADE_H
|
||||
|
||||
#include "blackcard.h"
|
||||
|
||||
class Spade : public BlackCard
|
||||
{
|
||||
private:
|
||||
// No additional private members
|
||||
|
||||
public:
|
||||
// Constructors
|
||||
Spade(int v); // Creates a black spade card with value v
|
||||
|
||||
string Description() const; // Outputs card characteristics - value, color, suit
|
||||
// Hint: use base class Description method to generate part of
|
||||
// the description and append the suit information at the end
|
||||
};
|
||||
|
||||
#endif
|
BIN
CPE212/Project_02/spade.o
Normal file
BIN
CPE212/Project_02/spade.o
Normal file
Binary file not shown.
Reference in New Issue
Block a user