Question: Can you recode this program and get it to randomly generate x and y coordinates without using rand(). You may use uniform_int_distribution. #include #include #include

Can you recode this program and get it to randomly generate x and y coordinates without using rand(). You may use uniform_int_distribution.

#include #include #include #include

using namespace std;

class Disc { // private data members private: int x, y; double radius;

// public member function public: // constructor Disc(double r) { radius = r; }

void throwDisc() { // randomly generate x and y coordinates for center of Disc // between 0 to 10 x = rand() % 11; y = rand() % 11; }

// accessors for data members int getX() { return x; } int getY() { return y; } int getRadius() { return radius; }

bool isOverlapping(Disc d2) { // compute if the discs overlap return sqrt(pow(this->x - d2.getX(), 2) + pow(this->y - d2.getY(), 2)) < (this->radius + d2.getRadius());

}

};

// main function int main() { // input the radius of 2 discs int r1, r2; string choice; cout << "Enter radius of disc 1: "; cin >> r1; cout << "Enter radius of disc 2: "; cin >> r2;

// create objects of disc Disc d1(r1); Disc d2(r2);

// ask to throw discs cout << "Throw discs? (Y/N): "; cin >> choice; if (choice[0] == 'Y' || choice[0] == 'y') { srand(time(NULL)); d1.throwDisc(); d2.throwDisc();

// check for overlapping if (d1.isOverlapping(d2)) cout << "You won!" << endl; else cout << "You lost." << endl;

// print centers of discs cout << "Disc 1 is at (" << d1.getX() << ", " << d1.getY() << ")" << endl; cout << "Disc 2 is at (" << d2.getX() << ", " << d2.getY() << ")" << endl; }

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!