-1

我的代码中不断出现各种错误,有人可以通过他们的编译器运行它并帮助我解决它们吗?我修复了一些,我现在得到的一个是没有匹配的函数来调用 'classRooms::ClassRooms(std::string&, int&, .....

//classRoom.h

#ifndef CLASSROOMS_H
#define CLASSROOMS_H

#include <iostream>
#include <string>
#include "ClassRooms.h"

using namespace std;

class ClassRooms
{
public:

    ClassRooms(int nRooms=100)
        : numRooms(0), rooms(new ClassRooms[nRooms]) { }
    ~ClassRooms()
    {
        delete [] rooms;
    }
    void addRoom(const ClassRooms& cr)
    {
        rooms[numRooms++] = cr;
    }
    string findRoom(int seats)const;
    int getSeats();
    double getAreaPerSeat();
   string getRoomNumber();
private:
    int numRooms;
    ClassRooms *rooms;
    int numSeats;
    double length, width;

};

#endif //CLASSROOMS_H

//教室.h

#ifndef CLASSROOMS_H
#define CLASSROOMS_H

#include <iostream>
#include <string>
#include "classRoom.h"

using namespace std;

class ClassRooms
{
public:
    ClassRooms(int nRooms=100)
        : numRooms(0), rooms(new ClassRooms[nRooms]) { }
    ~ClassRooms()
    {
        delete [] rooms;
    }
   void addRoom(const ClassRooms& cr)
    {
        rooms[numRooms++] = cr;
    }
    string findRoom(int seats)const;
private:
    int numRooms;
    ClassRooms *rooms;
};

#endif //CLASSROOMS_H

//main.cpp

#include <iostream>
#include <fstream>
#include "ClassRooms.h"

using namespace std;

int main()
{
    ifstream fin("rooms.txt");
    if (!fin)
    {
        cout << "Cannot open file\n";
        return 1;
    }
    string roomNum;
    int seats;
    double len, wid;
    ClassRooms classRooms;

    while (fin >> roomNum >> seats >> len >> wid)
        classRooms.addRoom(ClassRooms(roomNum, seats, len, wid));
    fin.close();

    while (seats > 0)
    {
        cout << "Enter MAX capacity: ";
        cin >> seats;
        cout << "Your best room is " << classRooms.findRoom(seats) << endl;
    }
}

//教室.cpp

#include "classRoom.h"

string ClassRooms::findRoom(int seats)const
{
    int maxIndex = 0;
    while (maxIndex < numRooms && rooms[maxIndex].getSeats() < seats)
        ++maxIndex;
    if (maxIndex == numRooms) return "";

    for (int i = 0; i < numRooms; ++i)
        if (rooms[i].getSeats() >= seats
                && rooms[i].getAreaPerSeat() > rooms[maxIndex].getAreaPerSeat())
            maxIndex = i;
    return rooms[maxIndex].getRoomNumber();
}
4

1 回答 1

0

您没有Classrooms采用 a 的构造函数,(string, int, double, double)因此,这ClassRooms(roomNum, seats, len, wid)是一个错误。您可以轻松地添加适当的构造函数Classrooms

ClassRooms(string roomNum, int seats, double len, double wid){
    //do something
}
于 2013-11-10T19:03:16.277 回答