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

C++ The purpose of this lab is to develop the habit of understanding the situati

ID: 3818068 • Letter: C

Question

C++ The purpose of this lab is to develop the habit of understanding the situation before you write code. You will do the analysis for a program, then develop a class hierarchy to document the requirements you identify. This is only design. You will not write any code. You will design a program to play a simplified version of war, using dice instead of cards. There will be only one user, but 2 “players” for the game. The user will indicate the number of rounds to play. The user will also specify for each “player” the number of sides on the dice used and if that player is using regular or loaded dice. For example, one player could have a loaded 10-sided die while the other has a 4-sided die. No one said it had to be fair! To play the game, for each round, you roll a die of the appropriate type for each player. The higher result wins. If the results are equal, it is a draw. The winner of the game is the player who won the most rounds. Your program will print out which player won to the user. You will design 2 classes, Die and LoadedDie. You will use inheritance. You will create a class hierarchy to show that LoadedDie is derived from Die. You will also design a Game class. Your program will use the Game class to run the game. The Game class will need to keep track of the type of dice for each of the 2 players, the number of rounds to play, and some way to maintain the score. The Game class will not be part of an “is-a” relation, but a “has-a” relation. Therefore, you should have at least 3 classes for this lab. Do you NEED a player class? Think about it. In your design, you should list your requirements. You should clearly indicate which nouns are classes, which nouns are data members for which classes, and which activities are members of which classes. You should describe any actions required. You should include an outline of the design for your main program, indicating how it will use the Game and Die classes. You also need to include a class hierarchy diagram displaying the organization and/or relationship of the different classes. Clearly indicate any “is-a” and “has-a” relations. The box for each class should separate name, data, and function members. An example is included at the end of this file. If you do not want to struggle with a drawing program, please draw it neatly by hand and scan it. Notice that it is not detailed. The goal is to better understand the problem. At last, you will also create a draft test plan. Thinking about testing while doing your design can help spot problems. For the test plan: what options are available to the user? What results would you expect for each option or combination of options?

Explanation / Answer

#include <iostream>
#include <iomanip>
#include <ctime>
#include <cstdlib>

using namespace std;


void greeting();
void greeting2();
int die1();
int die2();
int dice (int, int);
int results (int);


int main ()
{
  
int count;
char secondStart;

greeting ();
int firstdie = die1();
greeting2 ();
int secondie = die2();
int total = dice(firstdie, secondie);
results (total);

cout << total << endl;


system ("PAUSE");
return 0;
  
  
}


void greeting ()
{
char starter;

cout << "Please press X and then ENTER to roll the die." << endl;
cin >> starter;
}


void greeting2 ()
{
char starter2;

cout << "Please press X again to roll the second die." << endl;
cin >> starter2;
}


int die1()
{
for (int count = 0; count < 2; count++)
{
srand(time(NULL));
for (int i = 0; i <6; i++)
{
cout << rand()% 6+1 << endl;
return rand()%6+1;
}
}
}


int die2()
{
for (int count = 0; count < 2; count++)
{
srand(time(NULL));
for (int i = 0; i < 6; i++)
{
cout << rand()% 6+1 << endl;
return rand()%6+1;
}
}
}


int dice (int fdie, int sdie)
{
  
int total = fdie + sdie;
cout << "Your total so far is: " << total << endl;
return total;
}

int results (int total)
{
if (total = 7 && 11)
{
cout << "You won! Congratulations!" << endl;
}
else if (total = 2 && 3 && 12)
{
cout << "You lose. Try again." << endl;
}
else
{
cout << "You may continue to roll." << endl;
greeting ();
int firstdie = die1();
greeting2 ();
int secondie = die2();
int total = dice(firstdie, secondie);
}


cout << total << endl;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote