convert a c++ program to class diagram

October 15, 2010 at 20:41:35
Specs: Windows XP
How do I convert a C++ program code of the card game War into a class diagram. Here is my code Implemented using C++. Any help would be greatly appreciated. Thanks

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>

using namespace std;

int main(int argc, char** argv)
{
string SUITS_T[4] = {"Clubs", "Diamonds", "Hearts", "Spades"};

int values[52];
string suits[52];
for(int i = 0; i < 4; ++i)
{
for(int j = 0; j < 13; ++j)
{
values[ i * 13 + j ] = j + 1;
suits[ i * 13 + j ] = SUITS_T[i];
}
}

int player = 0;
int computer = 0;
int ties = 0;

int player_rand, computer_rand;
int player_val, computer_val;
string player_suit, computer_suit;

int deck_size = 52;
srand((unsigned)time(0));
for(int i = 0; i < 26; ++i)
{
player_rand = rand() % deck_size;
player_val = values[player_rand];
player_suit = suits[player_rand];
for(int j = player_rand; j < deck_size - 1; ++j)
{
values[j] = values[j + 1];
suits[j] = suits[j + 1];
}
deck_size--;

computer_rand = rand() % deck_size;
computer_val = values[computer_rand];
computer_suit = suits[computer_rand];
for(int j = computer_rand; j < deck_size - 1; ++j)
{
values[j] = values[j + 1];
suits[j] = suits[j + 1];
}
deck_size--;

cout << " Player card is the ";
switch(player_val)
{
case 1:
cout << "Ace ";
break;
case 11:
cout << "Jack ";
break;
case 12:
cout << "Queen ";
break;
case 13:
cout << "King ";
break;
default:
cout << player_val << " ";
}
cout << "of " << player_suit << endl;

cout << " Computer card is the ";
switch(computer_val)
{
case 1:
cout << "Ace ";
break;
case 11:
cout << "Jack ";
break;
case 12:
cout << "Queen ";
break;
case 13:
cout << "King ";
break;
default:
cout << computer_val << " ";
}
cout << "of " << computer_suit << endl;
if(player_val > computer_val)
{
cout << "Player Won!" << endl;
player++;
}
else if(player_val < computer_val)
{
cout << "Computer Won!" << endl;
computer++;
}
else
{
cout << "Tie game!" << endl;
ties++;
}
}
cout << "The player won " << player << " games" << endl;
cout << "The computer won " << computer << " games" << endl;
cout << "There were " << ties << " tie games" << endl;
}


See More: convert a c++ program to class diagram

Report •


#1
October 16, 2010 at 05:12:34
To make a class diagram, you'd need classes. You don't have any classes (or functions), so there's nothing to diagram.

How To Ask Questions The Smart Way


Report •
Related Solutions


Ask Question