Question: I need help writing a program in C + + using File I / O , delimeters, and etc.I need help with the following: Part

I need help writing a program in C++ using File I/O, delimeters, and etc.I need help with the following:
Part A 1
Loading Cards
Add a static LoadCards method to the WarGame class.Declare your method in the WarGame.h file and define the method in the WarGame.cpp file.
It should have a string parameter for the file path.In the method, it should read the cards.csv file and split the data to get the suits and faces.
Use them to create
52 unique cards and store each card in the cards vector field of the class.
NAME RETURNS PARAMETERS
LoadCards nothing string
Call the LoadCards method from the WarGame constructor.
Part A 2
Showing Cards
Add a static ShowCards method to the WarGame class.Declare your method in the WarGame.h file and define the method in the WarGame.cpp file.
Loop over the vector and call the Print method on each card.Make sure each card appears on a new line.
NAME RETURNS PARAMETERS
ShowCards nothing none
In case 1 of the menu, call the ShowCards method from main(which is in the CardWars.cpp file).
Part A 3
HighScore class
Add a HighScore class with a name field and a score field both with getter
/setter methods.
Add a constructor that takes a name and score.
Part A 4
Player class
Add a Player class with a name field, a score field, a pile field which is a vector of cards, and a won field which is a vector of cards.Add getter/setter methods for the score and name fields.
Add the following methods : HasCards, PushCard, PopCard, and WonCards.
HasCards will return true if there are cards in the pile vector.
PushCard will take a card parameter and add it to the pile vector of cards.
PopCard will remove a card from the pile vector of cards and return the card.
WonCards will take a vector of cards and add it to the won vector of cards and update the score field.
#include "WarGame.h"
#include
#include
#include
#include
#include
#include "Input.h"
#include "Card.h"
std::vector WarGame::_cards;
WarGame::WarGame(string cardsFile){
LoadCards(cardsFile);
}
void WarGame::LoadCards(const string& filePath){
ifstream file(filePath);
string line;
}
void WarGame::shuffle()
{
int ndx1, ndx2;
srand((unsigned int)time(NULL));
for (size_t i =0; i <52; i++)
{
ndx1= rand()%52;
ndx2= rand()%52;
Card temp =_cards[ndx1];
_cards[ndx1]=_cards[ndx2];
_cards[ndx2]= temp;
}
}
#pragma once
#include
#include
#include "Card.h"
class WarGame
{
public:
WarGame(std::string cardsFile);
static void LoadCards(const string& filePath);
static void ShowCards();
private:
static std::vector _cards;
static void shuffle();
};
#include "Card.h"
#include
#include
#include
#include
#include
#include
void Card::print()
{
std::cout << std::setw(2)<<_face;
#if defined(_WIN32)|| defined(__MSDOS__)
_setmode(_fileno(stdout),_O_U16TEXT);
#endif
if(_suit=="Hearts")
std::wcout << HEART;
else if(_suit== "Diamonds")
std::wcout << DIAMOND;
else if (_suit == "Clubs")
std::wcout << CLUB;
else if (_suit == "Spades")
std::wcout << SPADE;
std::wcout.flush();
#if defined(_WIN32)|| defined(__MSDOS__)
_setmode(_fileno(stdout),_O_TEXT);
#endif
}
int Card::compare(Card& otherCard)
{
int pValue = getCardValue(_face);
int cValue = getCardValue(otherCard.GetFace());
if (pValue > cValue)
return 1;//player wins
else if (pValue < cValue)
return -1;//npc wins
return 0;
}
int Card::getCardValue(std::string face)
{
int value;
if (sizeof(face)==3)//10 card
value =10;
else
{
char first = face[0];
if (first =='A')
value =1;
else if (first =='J')
value =11;
else if (first =='Q')
value =12;
else if (first =='K')
value =13;
else
value = std::stoi(face);
}
return value;
//return (int)face;
}
#pragma once
#include
using namespace std;
#if defined(_WIN32)|| defined(__MSDOS__)
#define SPADE '\x06'
#define CLUB '\x05'
#define HEART '\x03'
#define DIAMOND '\x04'
#else
#define SPADE '\u2660'
#define CLUB '\u2663'
#define HEART '\u2665'
#define DIAMOND '\u2666'
#endif
//enum Suit
//{
// Hearts=1,
// Diamonds,
// Clubs,
// Spades
//};
//enum Face
//{
// Ace =1, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King
//};
class Card
{
public:
Card(std::string suit, std::string face)
{
_suit = suit;
_face = face;
}
std::string GetSuit() const { return _suit; }
void SetSuit(std::string suit){_suit = suit; }
std::string GetFace() const { return _face; }
void SetFace(std::string face){_face = face; }
void print();
int compare(Card& otherCard);
private:
std::string _suit;
std::string _

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!