I have a c++ code here.
(我在这里有一个C ++代码。)
This code is to calculate data inside some files.(该代码用于计算某些文件中的数据。)
#include<stdio.h>
#include<iostream>
#include <fstream>
using namespace std;
int main(){
//initiate file variable
ifstream inFile;
//other variable
int count, limit=30, time, remain, flag=0, time_quantum, arrival_time=30, var, total_process[30], data;
int wait_time=0, turnaround_time=0, rt[30], num_of_interrupts=0, num_of_jobs=0;
cout<<"Your job list :
";
for(var = 1; var <= limit; var++){
//the purpose is the check weither looping is okay or not
cout<<""<<var;
//preparing array for the file
char nambuf[30];
std::snprintf(nambuf, sizeof(nambuf), "job%d.txt", var);
std::ifstream inFile;
//open file
inFile.open(nambuf);
//check file
if (!inFile) {
cout << " Unable to open file";
exit(1); // terminate with error
}
//read data from file .txt
while (inFile >> data) {
//calculate total process from data
total_process[var] += data;
++data;
}
//close file
inFile.close();
//print total process
cout << " Sum = " << total_process[var] << endl;
}
return 0;
}
(})
The code was run as it supposed.
(该代码按预期运行。)
But the problem occur after performing total process calculation.(但是,在执行总过程计算后会出现问题。)
Example of output :(输出示例:)
Sorry if the code was not good in design.
(抱歉,如果代码设计不好。)
I'm still new in programming.(我仍然是编程新手。)
ask by azrin translate from so