Question: I need help coding a program in C + + using File I / O , delimeters, accessing the data from cards.csv file specifically, open,

I need help coding a program in C++ using File I/O, delimeters, accessing the data from cards.csv file specifically, open, reading, closing files, and etc with the code ive provided.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). cards.csv:
Hearts?Diamonds?Clubs?Spades
A?2?3?4?5?6?7?8?9?10?J?Q?K
main file
CardWars.cpp
#include
#include "Console.h"
#include "Input.h"
#include "WarGame.h"
#include "Tester.h"
int main()
{
Tester cardWarsTest;
Console::ResizeWindow(150,30);
int menuSelection =0;
std::vector menuOptions{"1. Show Cards", "2. Show High Scores", "3. Play Card Wars", "4. Exit" };
std::string highScoreFile = "HighScores.csv";
std::string cardsFile = "cards.csv";
WarGame war(cardsFile);
do
{
Console::Clear();
menuSelection = Input::GetMenuSelection(menuOptions);
Console::Clear();
switch (menuSelection)
{
case 1:
{
/*
After creating the ShowCards method to the WarGame class, call the method here.
*/
break;
}
case 2:
{
/*
After creating the ShowHighScores method to the HighScore class, call the method here passing the highScores vector.
*/
break;
}
case 3:
{
/*
After creating the PlayGame method to the WarGame class, call the method here passing the highScoreFile string and the highScores vector.
*/
break;
}
default:
break;
}
Input::PressEnter();
} while (menuSelection != menuOptions.size());
}
WarGame.h:
#pragma once
#include
#include
#include "Card.h"
class WarGame
{
public:
WarGame(std::string cardsFile);
private:
static std::vector _cards;
static void shuffle();
};
WarGame.cpp
#include "WarGame.h"
#include
#include
#include
#include
#include
#include "Input.h"
#include "Card.h"
std::vector WarGame::_cards;
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;
}
}
Card.h:
#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 _face;
int getCardValue(std::string face);
};
Card.cpp:
#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_

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 Programming Questions!