我的代码中不断出现各种错误,有人可以通过他们的编译器运行它并帮助我解决它们吗?我修复了一些,我现在得到的一个是没有匹配的函数来调用 '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();
}