Question
Please help me fix my code: #include #include #include using namespace std; #include #include #include #include #define INFILE dvc_schedule.txt #define NLINES 97342 bool readFile(vector &v,
Please help me fix my code:
#include
bool readFile(vector
string tmp; ifstream inFile(INFILE);
if (inFile.fail()) {
cout
return (false);
}
while (getline(inFile, tmp)) {
if (++c == len) {
inFile.close();
return (true); } if (inFile.eof())
break;
v.push_back(tmp); }
inFile.close();
return (false);
}
int main() {
srand(time(0));
rand(); int n = 8000; string bigOh = "O(n)"; vector
int c = 0;
cout.setf(ios::fixed);
cout.precision(4);
double elapsedSecondsNorm = 0;
double expectedSeconds = 0; if (readFile(names, NLINES, c) == false) {
cerr
return (-1);
}
for (int cycle = 0; cycle
clock_t startTime = clock();
clock_t endTime = clock();
double elapsedSeconds = (double)
(endTime - startTime) / CLOCKS_PER_SEC;
double factor = pow(2.0, double(cycle));
if (cycle == 0)
elapsedSecondsNorm = elapsedSeconds;
else if (bigOh == "O(n)")
expectedSeconds = factor * elapsedSecondsNorm;
else if (bigOh == "O(n log n)")
expectedSeconds = factor *
log(double(n)) / log(n / factor) *
elapsedSecondsNorm;
else if (bigOh == "O(n squared)")
expectedSeconds = factor * factor * elapsedSecondsNorm;
cout
if (cycle == 0) cout
else cout
cout
}
}
What the program should output:
1.436 (expected 0(n)) for n=8000 2.742 (expected 2.872) for n=16000 5.442 (expected 5.744) for n=32000 10.828 (expected 11.488) for n=64000Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started