我正在尝试将值从计算函数传递给文件函数。但是“到达”和“突发”值没有从“计算”函数中正确读取。它只返回通过计算输入的最后一个值。
float RR::calculate()
{
cout << "Enter the number of processes: ";
cin >> num_pr;
vector<RR*> all_processes;
for (int i=0; i<num_pr; i++)
{
cout << "What is the arrival time for process " << i << ": ";
cin >> arrival_in;
cout << "What is the burst time for process " << i << ": ";
cin >> burst_in;
}
...
file (num_pr, arrival_in, burst_in, quantum, avg);
}
void RR::file(int processes, float arrival, float burst, float quantum, float avg)
{
fstream newFile;
newFile.open ("results.txt",ios::in | ios::out | ios::app);
for (int i=0; i<processes; i++)
{
newFile << "Arrival time for process " << i << ": " << arrival << endl;
newFile << "Burst time for process " << i << ": " << burst << endl;
}
}
这是我的类定义:
class RR
{
public:
RR();
RR(float burst_set, float arrival_set);
int num_pr, pos;
float quantum, avg, burst_sum, time, burst_time, sleep_time, arrival_sum, total_avg, burst_in, arrival_in, calculate(), get_arrival(), get_burst(), get_avg(), get_initial_burst();
void set_avg(float avg_set);
void set_burst(float burst_time_set);
void write_file(int processes, float arrival, float burst, float quantum, float avg);
private:
float initial_burst, arrival_time, avg_time;
};