Project #1 Briscas Objectives: To write a program that implements the following
ID: 3829799 • Letter: P
Question
Project #1 Briscas
Objectives: To write a program that implements the following C++ concepts
1. Data Encapsulation
2. Composition Class
3. Instantiate classes
4. Static Memory (arrays)
1. Make a class call Brisca with his methods. The methods should include constructors, getters and setters. Make an operator overloading of <<, >>. Private attributes are: a. char cardType // (‘O’ – oro, ‘E’ – espada, ‘C’ – copa, ‘B’ – basto b. int card // (1..7, 10, 11, 12) c. int value // (1 = 11, 3 = 10, 10 = 2, 11 = 3, 12 = 4, the rest = 0)
2. Make a class call Deck that would be a composition of class Brisca. The methods should include default and copy constructor, getters and setters where this last will not receive arguments just initialize the suit. The private attribute is deck[40] of type Brisca. Make an operator overloading of [ ], <<, >>. Make a method void shuffle(), that will shuffle all the cards of the deck. Brisca Deck 3. Make a program with the following menu: MENU 1. Display every 10 cards 2. Shuffle deck
3. Reset deck 4. Exit Your choice:
Explanation / Answer
1 Answer:)
#include<iostream>
using namespace std;
class Brisca
{
private:
int card; // (1,2,....12);
char cardtype; //(O=oro,E=espada,C=copa,B=basto
int value; //1=11,3=10,10=2,12=4 so no
public:
//Constructor
deck():cardtype(4),value(12),char(12){
}
void getcardtype()
{
cout<<"O=olo, E=espada,C=colo,B=basto");
cout<<"1=11,2=10,3=12,0=rest....");
cut<<"card=1,2,3,4,5,6,7,8,9,10,11,12");
}
};
int main()
{
deck a1;
a1.getcardtype;
return 0;
}
2 Answer):
#ifdef DECK_H
#define DECK_H
#include "Brisca.h"
#include<iostream.h>
#include<string>
#include<ctime>
using namespace std;
class Deck
{
private:
static const string Rank[3],suits[4];
int size;
Brisca cards[40];
void build();
public:
Deck();
~Deck();
void shuffle();
Brisca drawCard();
int getDeckSize() const{return size;}
friend ostream& operatr<<(stream&,cnst Deck&);
};
#endif
Deck.cpp
#include "Deck.h"
const string Deck::Ranks[3]={"A","2","3"};
const string Deck::Suits[4]={"H" ,"D","c","s"};
Deck::Deck():size(0){build();}
Deck::~Deck(){}
void Deck::build()
{
srand((unsigned int)time(NULL));
string card;
bool isScameCard;
while (size<52)
{
isSameCard=false;
card=Ranks[rand()%3]+Suits[rand()%4];
for(int i=0;i<size;i++)
{
if(cards[i].getCard()==card);
size++;
}
}
}
void Deck::shuffle()
{
build();
srand((unsigned int)time(NULL));
for(int i=0;i<size;i++)
{
int j=rand()%52;
swap(cards[i],cards[j]);
}
}
Brisca Deck::drawCard()
{
if(size==0)
{
cerr<<"ERROR *** DECK EMPTY";
Brisca card;
return card;
}
size--;
return cards[size];
}
ostream& peratr<<(osteam &ut,const Deck &aDeck)
{
for(int i=a.Deck.size-1;i>=0;i--)
cout<<*((aDeck.cards)+i)<<endl;
return out;
}
3Answer)
#include<iostream>
using namespace std;
int main()
{
int option;
do
{
cout<<"1)display every 10 cards"<<endl;
cout<<"2) shuffle cards"<<endl;
cout<<"3)reset deck"<<endl;
cout<<"4) exit"<<endl;
cout<<"Please select an option";
cin>>option;
if(option==1)
{
cout<<"1,2,3,4,5,6,7,8,9,10"<<endl;
}
else if(option==2);
{
cout<"2,4,3,5,6.1,7,9,8,10"<<endl;
}
else if(option==3)
{
cout<<"1,2,3,4,5,6,7,8,9,10"<<endl;
}
else if(option=4)
{
cout<terminate program"<<endl;
}
else
{
cout<<"invalid option entered"<<endl;
}
}
while(optin!=4);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.