Advertisement
Guest User

C++ project

a guest
Feb 24th, 2020
953
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. void deckSort (vector<Card> & deck) {
  2. /* In this function add the code for answering the Question 1 in the assignment.
  3. The sorted deck of cards should be present in the parameter deck passed to this function.
  4. */
  5.  
  6. }
  7.  
  8. void inverseDeckSort (vector<Card> & deck) {
  9. /* In this function add the code for answering the Question 3 in the assignment.
  10. The sorted deck of cards should be present in the parameter deck passed to this function.
  11. */
  12.  
  13. }
  14.  
  15. void deckSort2 (vector<Card> & deck) {
  16. /* In this function add the code for answering the Question 2 in the assignment.
  17. The sorted deck of cards should be present in the parameter deck passed to this function.
  18. */
  19.  
  20. }
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32. Question 1
  33.  
  34. You have been given a shuffled deck of cards. Your job is to write a program that puts a deck of cards in order by suit (in the order spades, hearts, clubs, diamonds). Further, within each suit the cards should be organized by rank from 1 to 13. The only operation you are allowed to perform on the cards is to look at the value of two cards at a time and exchange them. You can't look at the value of more than two cards at a time. You can do this operation as many times as you like.
  35.  
  36. The code for this program should be written in the function deckSort in the file main.cpp. The function takes a single argument deck. deck is a vector that contains objects of type Card. The function does not return anything so the sorted deck should be present in the variable deck after the function completes.
  37.  
  38. Question 2
  39.  
  40. Write a program to solve the problem described in Question 1 by overloading the greater than operator in the class Card.
  41.  
  42. For this program you will have to declare an overloaded greater than operator in the file Card.h and provide its implementation in the file card.cpp. In addition, you have to write code for sorting in the function deckSort2 in the file main.cpp. The API of the function is similar to the API of the deckSort so follow the same rules regarding returning results.
  43.  
  44. Question 3
  45.  
  46. Modify the program you wrote in Question 1 such that the final ordered deck contains cards in the same order by suit (in the order spades, hearts, clubs, diamonds). But, within each suit, the cards are organized by rank from 13 to 1.
  47.  
  48. The code for this program should be written in the function inverseDeckSort in the file main.cpp. The API of the function is similar to the API of the deckSort so follow the same rules regarding returning results.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement