subject
Computers and Technology, 11.10.2020 02:01 giovney

#include #include

using namespace std;

const string face[] = { "Ace", "2", "3", "4", "5", "6", "7",

"8", "9", "10", "Jack", "Queen", "King" };

const string suit[] = { "Clubs", "Diamonds", "Hearts", "Spades" };

string random_card(bool verbose=false) {

string card;

card = face[ rand()%13 ];

card += " of ";

card += suit[ rand()%4 ];

if (verbose)

cout << card << "\n";

return card;

}

int main(int argc, char *argv[])

{

bool verbose = false;

int seedvalue = 0;

for (int i=1; i
string option = argv[i];

if (option. compare(0,6,"-seed=") == 0) {

seedvalue = atoi(&argv[i][6]);

} else if (option. compare("-verbose") == 0) {

verbose = true;

} else

cout << "option " << argv[i] << " ignored\n";

}

srand(seedvalue);

// declare a table called deck that keeps track of

// card faces dealt for each suit -- initialize to 0

while (1) {string card = random_card(verbose);

// reverse engineer card suit and face

// break out of loop if stopping criteria met

}

// print formatted table contents to stdout

}

write the non-existent Prog2b. cpp code and have it keep track of the order in which a card rank is observed for each suit. You do this by inserting the cards at the back of linked lists, using one list for each suit. The exception applies: each time a rank is seen again, the card gets moved to the front of the list. When the stopping criterion from Prog2a is encountered, break the infinite-loop and print the contents of each linked list to stdout as shown below.

Add an array of linked lists: the length of the array is fixed at 4 like before, while the length of each linked list varies from suit to suit. Each new card is added to the appropriate list thru use of an insert() function. Declare a list class based on a single linked list. The list class needs to define a private node datatype, and it must include a constructor for properly initializing an empty list, a destructor for deallocating all the nodes in a list as well as the list itself, and the mentioned insert function which works as described next; no other list class functions are needed. Overload operator<<() used by ostream and have it print the contents of the list. Since access is needed to private data members, make the overloaded output operator a friend of the list class. See the code handouts for how to set this up.

The list::insert() function is where the fun work takes place. The function takes a single integer argument, namely, the rank index of a card where index refers to the position of the rank in the global rank string array. If the rank index is not held by any node in the linked list, a new node is created and added to the end of the list that stores the rank index value. However, if a node is found to already hold the present rank index argument, that node is moved to the front the linked list. That is, the node in question is unlinked from where it is and inserted after the head node.

Hint: You are using a single linked list which means you cannot go back once you have a match on the rank index. One option is to look ahead instead of advancing and then taking a look a the rank index. Another option is to maintain two pointers, namely, one pointing to previous node and one pointing to current node.

Hint: Write generic code that works under all circumstances rather than have several codes for special cases. For example, write the insert() function so that it can handle a rank match regardless of where the matching node resides in the list. Draw a sketch of the different scenarios that need to be handled and infer from it how to do it generically.

Prog2b example output

UNIX> ./prog2b
Clubs : 10 6 Queen King 9 Jack **
Diamonds : Jack 9 6 Ace 3 8
Hearts : 9 3 King 7 Jack
Spades : Queen Ace Jack
UNIX>
UNIX> ./prog2b -seed=140
Clubs : 10 Jack King 4 2 Ace 7 6 3 8
Diamonds : King 3 Ace 9 Queen 5 10 8 7 2 Jack **
Hearts : Jack 2 10 7 6 3 Ace 5 4
Spades : 6 5 Jack 4 9 Queen 2

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 17:00
The two main ways in which marketers address the competition with their strategies are by satisfying a need better than a competition and by
Answers: 2
question
Computers and Technology, 22.06.2019 19:30
When creating a presentation in libre office impress, where does the editing of slides take place?
Answers: 1
question
Computers and Technology, 22.06.2019 19:40
Solve the following javafx application: write a javafx application that analyzes a word. the user would type the word in a text field, and the application provides three buttons for the following: - one button, when clicked, displays the length of the word.- another button, when clicked, displays the number of vowels in the word.- another button, when clicked, displays the number of uppercase letters in the word(use the gridpane or hbox and vbox to organize the gui controls).
Answers: 1
question
Computers and Technology, 23.06.2019 20:10
Leo is a recruitment executive for a large company. he has identified new labor resource requirements in both the marketing and production departments. what should be his first step in recruiting candidates for the positions? a. conduct background checks of candidates b. make job offers c. arrange interviews d. conduct reference checks e. place job ads on job sites
Answers: 1
You know the right answer?
#include #include

using namespace std;

const string face[] = { "Ace", "2"...
Questions
question
Mathematics, 10.10.2020 22:01
question
Health, 10.10.2020 22:01
question
Mathematics, 10.10.2020 23:01
Questions on the website: 13722363