0
time_t start;
time_t no_infection;
bool time_already_set = 0;
bool infected_or_not = 0;
int not_infected_t = 0;
我在結構中有這個變量,我想標記對象的起點和終點,比計算差異。如何使用ctime標記程序的開始和結束點?
void bacteria::set_no_infection() {
if (infected_or_not == 0)
no_infection = clock();
}
對於一開始我有
void bacteria::set_time() {
if (infected_or_not == 1 && time_already_set!=1) {
start = clock();
time_already_set = 1;
}
}
看來,時間變量的程序我使用GET功能
double bacteria::get_time() {
if (infected_or_not == 1)
return ((clock() - start)/CLOCKS_PER_SEC);
else
return -1;
}
int bacteria::get_no_infection() {
if (infected_or_not = 0)
return ((clock() - no_infection)/CLOCKS_PER_SEC);
else
return -1;
}
在主程序我測試它像測試過程中不改變此:
while (1) {
for (int i = 0; i < b.size() - 1; i++) {
bactpop[i].set_no_infection();
bactpop[i].inf(phagepop[i], bactpop[i], p);
bactpop[i].kill_the_bacteria(b, i);
cout << " " << b[i].start << " " << b[i].no_infection << endl;
}
cout << p.size() << " " << b.size() << endl;
}
我測試這樣的: 而(1){ \t \t對(INT I = 0; I