Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #include #include using namespace std; #include #include #include #include #define INFILE "dvc_schedule.txt" #define NLINES 97342

bool readFile(vector &v, int len, int &c) {

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 names;

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:

image text in transcribed
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=64000

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions