我不确定我的标题是否用词正确,所以我将在这里详细说明。
我需要做的是让我的向量从先前构建的 Array 中获取信息,对其进行洗牌,然后将其吐回。我想我可以做的,因为我有一个 for 循环来显示卡片组的信息是在 main 函数中有向量,但同时我觉得我需要创建一个单独的函数。但是,我不确定哪种方法最有效。到目前为止,我所拥有的是这个。
#include <iostream>
#include <string>
#include "prototypes.h"
using std::string;
using std::endl;
using std::cout;
const string CARDS[] =
{
"2C", "3C", "4C", "5C", "6C", "7C", "8C", "9C", "TC", "JC", "QC", "KC", "AC",
"2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D", "TD", "JD", "QD", "KD", "AD",
"2H", "3H", "4H", "5H", "6H", "7H", "8H", "9H", "TH", "JH", "QH", "KH", "AH",
"2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S", "TS", "JS", "QS", "KS", "AS"
};
unsigned const DECK_SIZE = sizeof(CARDS) / sizeof(string);
int const SHUFFLE_COMMAND = 1;
int const SHOW_COMMAND = 2;
int const QUIT_COMMAND = 3;
const char MENU[] = "\nShowing Cards Program:\n1 -- Shuffle Cards\n2 -- Show Deck\n3 -- Quit\n: ";
const char IM_OUTTA_HERE[] = "Buh-bye!";
int main()
{
int command = 0;
do
{
command = askForInt(MENU, QUIT_COMMAND, SHUFFLE_COMMAND);
switch(command)
{
case SHUFFLE_COMMAND:
break;
case SHOW_COMMAND:
for(int i = 0; i < DECK_SIZE; i++)
{
cout << CARDS[i] << " ";
if(i == 12 || i == 25 || i == 38)
{
cout << endl;
}
}
break;
case QUIT_COMMAND:
break;
}
}while(command != QUIT_COMMAND);
cout << IM_OUTTA_HERE << endl;
return 0;
}
askForInt 在另一个名为 Functions 的文件中,它所做的只是接收用户输入(1、2 或 3)
编辑:还必须注意,我需要使用指针来执行此操作,因为这是我目前正在尝试学习的内容。