Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/147.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;洗牌器错误_C++ - Fatal编程技术网

C++ C++;洗牌器错误

C++ C++;洗牌器错误,c++,C++,说明如下: 创建一个洗牌和发牌程序。该程序应包括等级卡、等级卡和驾驶员程序 课程卡应提供: a) 数据成员面和int型套装。 b) 一种构造函数,它接收表示脸和衣服的两个整数,并使用它们初始化数据成员 卡类应包含: a) 两个名为deck的卡对象,用于存储两张卡。 b) 一种构造函数,它不接受任何参数并初始化牌组中的两张牌。 你可以给这两张牌一个随机的面值和花色值,但要确保它们不一样。 c) 打印两张卡的printCards函数 驱动程序应该创建一个DeckOfCards对象,并打印该对象拥有的

说明如下:

创建一个洗牌和发牌程序。该程序应包括等级卡、等级卡和驾驶员程序

课程卡应提供: a) 数据成员面和int型套装。 b) 一种构造函数,它接收表示脸和衣服的两个整数,并使用它们初始化数据成员

卡类应包含: a) 两个名为deck的卡对象,用于存储两张卡。 b) 一种构造函数,它不接受任何参数并初始化牌组中的两张牌。 你可以给这两张牌一个随机的面值和花色值,但要确保它们不一样。 c) 打印两张卡的printCards函数

驱动程序应该创建一个DeckOfCards对象,并打印该对象拥有的卡

此项目中需要有5个文件:card.hpp、card.cpp、deckofcards.hpp、deckofcards.cpp、main.cpp

我得到的错误是:

  • DeckOfCards.h第15行中缺少显式类型(“假定为int”)
  • 没有合适的构造函数将main.cpp第8行中的“DeckOfCards*”转换为“DeckOfCards”
  • 缺少类型说明符-DeckOfCards.h第15行中假定为int
  • “正在初始化”:无法在main.cpp第8行中从“DeckOfCards*”转换为“DeckOfCards”
  • 缺少类型说明符-DeckOfCards.h第15行中假定为int
  • 缺少类型说明符-DeckOfCards.cpp第18行中假定为int
  • 卡片h:

    #ifndef Card_H
    #define Card_H
    #include <string>
    
    using namespace std;
    
    
    string suits[4] = { "Hearts", "Diamonds", "Spades", "Clubs" };
    string faces[12] = { "Ace", "2", "3", "4", "5", "6", "7", "8", "9", "Jack", "Queen", "King" };
    
    class Card {
    public:
        int face;
        int suit;
        Card(int face, int suit);
        string toString();
    };
    
    #endif
    
    \ifndef卡
    #定义卡片
    #包括
    使用名称空间std;
    弦乐套装[4]={“红心”、“钻石”、“黑桃”、“梅花”};
    弦面[12]={“A”、“2”、“3”、“4”、“5”、“6”、“7”、“8”、“9”、“杰克”、“女王”、“国王”};
    班级卡{
    公众:
    内面;
    内服;
    卡片(内面、内套);
    字符串toString();
    };
    #恩迪夫
    
    Card.cpp:

    #include "Card.h"
    #include <iostream>
    
    using namespace std;
    
    Card::Card(int face, int suit) {
        this->face = face;
        this->suit = suit;
    }
    
    string Card::toString() {
        string suitname = suits[suit];
        string facename = faces[face];
    
        return facename + " of " + suitname;
    }
    
    #包括“Card.h”
    #包括
    使用名称空间std;
    卡片::卡片(整型面,整型套装){
    这个->面=面;
    这个->套装=套装;
    }
    字符串卡::toString(){
    字符串suitname=suits[suit];
    字符串facename=面[面];
    返回facename+“of”+suitname;
    }
    
    DeckOfCards.h:

    #ifndef DeckOfCards_H
    #define DeckOfCards_H
    #include "Card.h"
    #include <vector>
    
    using namespace std;
    
    
    class DeckOfCards {
    public:
        vector<Card> deck;
    
    public:
        DeckOfCards();
        printCards();
    };
    
    #endif
    
    \ifndef DeckOfCards\u H
    #定义卡盘
    #包括“Card.h”
    #包括
    使用名称空间std;
    甲板类{
    公众:
    向量甲板;
    公众:
    纸牌;
    打印卡();
    };
    #恩迪夫
    
    DeckOfCards.cpp:

    #include "DeckofCards.h"
    #include "Card.h"
    #include <iostream>
    
    using std::cin;
    using std::cout;
    using std::string;
    
    
    DeckOfCards::DeckOfCards() {
    
        for (int i = 0; i<2; i++) {
            Card card(i + 3, i + 5);
            deck.push_back(card);
        }
    }
    
    DeckOfCards::printCards() {
        for (int i = 0; i<2; i++) {
            cout << deck[i].toString();
        }
    }
    
    #包括“DeckofCards.h”
    #包括“Card.h”
    #包括
    使用std::cin;
    使用std::cout;
    使用std::string;
    DeckOfCards::DeckOfCards(){
    
    对于(inti=0;i要使用std::string类,必须包含头文件字符串,因此要将其导入到相应的hpp文件,需要编写以下代码

    #include <string>
    

    在编写类程序之前,以及您不了解“Card.hpp中的未知类型名称‘string’in Card.hpp”错误消息的确切部分是什么?为什么您的牌组只有48张牌?可能是
    #include <string>
    
    using std::string;