我在前两个函数'input'和'genWindows'中收到错误。我从来没有遇到过这个错误,似乎无法弄清楚是什么原因造成的,也不知道为什么这个班级被认为是不合格的。
#include <iostream>
#include <string>
#include <fstream>
#include <stdlib.h>
#include "Queue.h"
#include "window.h"
#include "sim.h"
using namespace std;
string fileInput;
ifstream file;
string line;
window* windows;
Queue<int>* queue = new Queue<int>;
Queue<int>* timeQueue = new Queue<int>;
Queue<int>* numStudent = new Queue<int>;
int simTime;
int numWindows;
int count;
bool check;
int numWinIdle;
int winIdle;
sim::void input()
{
cout << "Please enter a file name: " << endl;
cin >> fileInput;
}
sim::void genWindows()
{
file.open(fileInput.c_str());
if(file.good())
{
getline(file, line);
numWindows = atoi(line.c_str());
windows = new window[numWindows];
}
file.close();
}
sim::void placeStudent(int n)
{
for(int i = 0; i < numWindows; ++i)
{
if(windows[i].isEmpty())
{
numWinIdle++;
winIdle += windows[i].idleTime;
windows[i].idleTime = 0;
windows[i].sTime = n;
break;
}
}
}
sim::void removeStudent()
{
for(int i = 0; i < numWindows; ++i)
{
if(windows[i].sTime <= simTime)
{
windows[i].sTime = 0;
}
}
}
sim::void setIdleTime()
{
for(int i = 0; i < numWindows;++i)
{
if(windows[i].isEmpty())
{
windows[i].idleTime += (simTime - windows[i].idleTime);
}
}
}
sim::void getIdleTime()
{
for(int i = 0; i < numWindows;++i)
{
if(windows[i].idleTime != 0)
{
numWinIdle++;
winIdle += windows[i].idleTime;
}
}
}
sim::void genQueue()
{
file.open(fileInput.c_str());
int numStudents;
check = true;
getline(file,line);
while(file >> line)
{
if(numStudents > 0)
{
queue->pushOn(atoi(line.c_str()));
--numStudents;
}
else if(check)
{
timeQueue->pushOn(atoi(line.c_str()));
check = false;
}
else
{
numStudent->pushOn(atoi(line.c_str()));
numStudents = atoi(line.c_str());
check = true;
}
}
file.close();
}
sim::bool checkWindows()
{
for(int i = 0; i < numWindows; ++i)
{
if(windows[i].isEmpty())
{
return true;
}
else
return false;
}
}
sim::int numWinOpen()
{
int count;
for(int i = 0; i < numWindows; ++i)
{
if(windows[i].isEmpty())
{
count++;
}
}
return count;
}
sim::void simulationTime()
{
if(timeQueue->isEmpty())
{
simTime++;
}
else
{
simTime = timeQueue->getFront();
timeQueue->popOff();
}
}
sim::void runSim()
{
if(checkWindows() && queue->isEmpty())
{
cout<<winIdle<<endl;
cout<<numWinIdle<<endl;
double mean = winIdle/double(numWinIdle);
cout<<"Registrar cleared"<<endl;
}
else
{
simulationTime();
removeStudent();
while(numWinOpen() > 0)
{
if(queue->isEmpty())
{
break;
}
else if(numStudent->isEmpty())
{
if(numWinOpen() > 0 && queue->isEmpty() == false)
placeStudent(queue->getFront() + simTime);
queue->popOff();
}
else if(numStudent->getFront() > numWinOpen())
{
for(int i = 0; i < numWinOpen();++i)
{
if(numWinOpen() > 0 && queue->isEmpty() == false)
placeStudent(queue->getFront() + simTime);
queue->popOff();
}
numStudent->popOff();
}
else if(numStudent->getFront() <= numWinOpen())
{
for(int i = 0; i < numStudent->getFront();++i)
{
if(numWinOpen() > 0 && queue->isEmpty() == false)
placeStudent(queue->getFront() + simTime);
queue->popOff();
}
numStudent->popOff();
}
}
setIdleTime();
runSim();
}
}
答案 0 :(得分:1)
sim::void
是无稽之谈。你的意思是void
。
如果函数是在命名空间中声明的,那么它需要符合条件的函数名称而不是返回类型:
void sim::input()
答案 1 :(得分:1)
这没有任何意义:
sim::void input()
我认为你的意思是:
void sim::input()