Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with this c++ I need a program that implements the Coin class, one p

ID: 3671329 • Letter: I

Question

I need help with this c++

I need a program that implements the Coin class, one person will implement the main program that uses it.

Make sure you test the program when the two parts are put together.

1. Design a class named Coin (use a UML diagram).

The Coin class should have the following member variable:
• A string named sideUp . The sideUp member variable will hold either “heads” or “tails” indicating the side of the coin that is facing up.
The Coin class should have the following member functions:
• A default constructor that randomly determines the side of the coin that is facing up (“heads” or “tails”) and initializes the sideUp member variable accordingly.
• A void member function named toss that simulates the tossing of the coin. When the toss member function is called, it randomly determines the side of the coin that is facing up (“heads” or “tails”) and sets the sideUp member variable accordingly.
• A member function named getSideUp that returns the value of the sideUp member variable.

Explanation / Answer

#include <iostream>
#include <string>
#include <stdlib.h>
#include <time.h>

using namespace std;

class coin
{
private:
    string sideUp;

public:
    coin();
    void toss();
    string getsideUp();
};

coin::coin()
{
if(rand()%2 == 0)
    sideUp = "heads";
else
    sideUp = "tails";
}

string coin::getsideUp()
{
return sideUp;
}

void coin::toss()
{
if(rand()%2 == 0)
    sideUp = "heads";
else
    sideUp = "tails";
}

int main()
{
srand(time(NULL));
coin obj;
int i;

for(i=0;i<10;i++)
{
    cout<<obj.getsideUp()<<endl;
    obj.toss();
}

}