Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How to make this program work by changing the ouput and operator function ? #include #include #include using namespace std; unsigned int seed = (unsigned

How to make this program work by changing the ouput and operator function ?

#include

#include

#include

using namespace std;

unsigned int seed = (unsigned int)time(0);

const int SIZE = 10;

struct node

{

int integer;

double value;

};

double random(unsigned int &);

void initialize_vector(vector &);

void print_vector(const vector &);

ostream &operator << (ostream &, vector);

void output(ostream &, vector );

int main()

{

vector v(SIZE);

initialize_vector(v);

print_vector(v);

for (int i = 0; i < v.size(); ++i)

cout << v[i];

cout << endl;

return 0;

}

void initialize_vector(vector &v)

{

vector ::iterator it;

for (it = v.begin(); it < v.end(); ++it)

{

it -> integer = (int (10 * random(seed)));

it -> value =(10 * random(seed));

}

}

void print_vector(const vector &v)

{

cout << setprecision(5) << fixed;

for (int i = 0; i < v.size(); ++i)

cout << v.at(i).integer << setw(12) << v.at(i).value <

}

ostream &operator << (ostream &out, vector v)

{

output(out,v);

return(out);

}

void output(ostream &out, vector v)

{

cout << setprecision(5) << fixed << endl;

cout << "Overriding print: " << endl;

for(int i = 0; i < v.size(); ++i)

cout << v[i].integer << setw(12) << v[i].value << endl;

}

double random(unsigned int & seed)

{

const int MODULUS = 15749;

const int MULTIPLIER = 69069;

const int INCREMENT = 1;

seed = ((MULTIPLIER * seed) + INCREMENT) % MODULUS;

return double (seed) / double (MODULUS);

}

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

Beginning VB.NET Databases

Authors: Thearon Willis

1st Edition

1594864217, 978-1594864216

More Books

Students also viewed these Databases questions