QUIZ 9
QUESTION 1
An enumeration contains enumerators that represent
a. |
the functions for the enumeration |
|
b. |
the constants for the enumeration |
|
c. |
the operators for the enumeration |
|
d. |
the variables for the enumeration |
1 points
QUESTION 2
Which of the following problems is not a problem with using unscoped enumerations?
a. |
The code for using them is more complex. |
|
b. |
They allow you to accidentally convert an enumerator to an integer type. |
|
c. |
They can lead to name collisions. |
|
d. |
They allow you to compare an enumerator to an integer using relational operators. |
1 points
QUESTION 3
Given the following enumeration:
enum class Terms {
net_30_days,
net_60_days,
net_90_days
};
Which statement would you use to assign the value of the
net_30_days enumerator to a variable named terms?
a. |
Terms terms = Terms.net_30_days; |
|
b. |
Terms terms = Terms::net_30_days; |
|
c. |
Terms terms = Terms(net_30_days); |
1 points
QUESTION 4
Given the following Product structure:
struct Product {
string name;
double price;
int quantity;
bool equals(const Product&);
};
how would you define the equals function so two products are equal
if their names and prices are equal?
a. |
bool equals(const Product& to_compare) { |
|
b. |
bool equals(const Product& to_compare) { |
|
c. |
bool Product::equals(const Product& to_compare)
{ |
|
d. |
bool Product::equals(const Product& to_compare)
{ |
1 points
QUESTION 5
If you don’t initialize a structure or set default values for its data members in the structure definition,
a. |
the data members will contain whatever values happen to be at the memory location where they’re created |
|
b. |
you have to assign values to the data members before you can use the structure |
|
c. |
all of the members will contain 0 or null depending on the data type |
1 points
QUESTION 6
The advantage of returning a structure type from a function when compared to returning a fundamental type is that
a. |
the function can return multiple values |
|
b. |
the function can return an object |
|
c. |
the function doesn’t need to include a return statement |
|
d. |
all of the above |
|
e. |
a and b only |
1 points
QUESTION 7
How would you modify the following enumeration to change the
underlying enumerator type to char?
enum class Suit {
diamonds = 'd',
hearts = 'h',
clubs = 'c',
spades = 's'
};
a. |
enum class Suit : char { |
|
b. |
enum class Suit { |
|
c. |
enum class : char Suit { |
|
d. |
enum class Suit char { |
1 points
QUESTION 8
Code Example 9-1
struct Product {
string name;
double price;
int quantity;
};
(Refer to Code Example 9-1.) What happens if
you try to compare two Product objects using the following
code?
Product p1 = { "hammer", 14.99, 15 };
Product p2 = { "hammer", 16.29, 12 };
if (p1 == p2) {
cout << "The products are equal.";
}
else {
cout << "The products are not
equal.";
}
a. |
It displays a message that the products are not equal because they have different prices and quantities. |
|
b. |
It displays a message that the products are equal because the have the same name. |
|
c. |
A compile-time error occurs because there is no equality operator for the Product structure. |
1 points
QUESTION 9
Given the following Product structure:
struct Product {
string name;
double price;
int quantity;
bool operator==(const Product& to_compare)
{
return (name ==
to_compare.name && price == to_compare.price);
}
};
what statement would you use to test if two Product objects named
p1 and p2 are equal?
a. |
bool duplicate = p1.==(p2); |
|
b. |
bool duplicate = (p1 == p2); |
|
c. |
bool duplicate = p1.operator==(p2); |
|
d. |
bool duplicate = (p1 operator== p2); |
1 points
QUESTION 10
If you don’t specify the values of the enumerators in an enumeration, they are stored as
a. |
sequential char values starting at 'a' |
|
b. |
sequential int values starting at 1 |
|
c. |
sequential int values starting at 0 |
|
d. |
sequential char values starting at 'A' |
1. b) the constants for the enumeration
Explanation:
Enumeration (or enum) is a user defined data type in C. It is mainly used to assign names to integral constants, the names make a program easy to read and maintain.
2. They allow you to compare an enumerator to an integer using relational operators.
3. Terms terms = Terms.net_30_days;
4.
bool Product::equals(const Product& to_compare) {
return (name == to_compare.name && price
== to_compare.price);
}
NOTE: As per Chegg policy, I am allowed to answer only 3 questions (including sub-parts) on a single post. I have gone ahead and answered 4. Kindly post the remaining questions separately and I will try to answer them. Sorry for the inconvenience caused.
QUIZ 9 QUESTION 1 An enumeration contains enumerators that represent a. the functions for the enumeration...
Using C++: 1. Array and Struct in Card applications: In card game design, card suit and face values can be defined with enumeration values. Declare suit values - – hearts, clubs, diamonds, spades using enum, declare face values of 2 – 10, Jack, Queen, King, Ace using enum Declare a structure called Card, and it includes two data members, whose data types are the above two defined enumerations suit and face typedef an array called Deck, and it includes all...
C++ Your solution should for this assignment should consist of five (5) files: Card.h (class specification file) Card.cpp (class implementation file) DeckOfCards.h (class specification file) DeckOfCards.cpp (class implementation file) 200_assign6.cpp (application program) NU eelLS Seven UT Diamonds Nine of Hearts Six of Diamonds For your sixth programming assignment you will be writing a program to shuffle and deal a deck of cards. The program should consist of class Card, class DeckOfCards and an application program. Class Card should provide: a....
//main.cpp #include <iostream> #include <iomanip> #include "deck-of-cards.hpp" void RunAllTests() { int count; std::cin >> count; DeckOfCards myDeckOfCards; for (int i = 0; myDeckOfCards.moreCards() && i < count; ++i) { std::cout << std::left << std::setw(19) << myDeckOfCards.dealCard().toString(); if (i % 4 == 3) std::cout << std::endl; } } int main() { RunAllTests(); return 0; } //card.hpp #ifndef CARD_HPP_ #define CARD_HPP_ #include <string> class Card { public: static const int totalFaces = 13; static const int totalSuits = 4; Card(int cardFace, int...
urgent help with python. can somone code this please and show output QUESTION: There are a variety of games possible with a deck of cards. A deck of cards has four different suits, i.e. spades (*), clubs (*), diamonds (), hearts (), and thirteen values for each suit. Now write a function that uses list comprehension to create a deck of cards. Each element in the list will be a card, which is represented by a list containing the suit...
void card:: setNum(int n) { assert(n >= 1 && n <= 13); num = n; } void card::setSuit(char s) { assert(s == 'C' || s == 'D' || s == 'H' || s == 'S'); suit = s; } int card::getNum() { assert(num >= 1 && num <= 13); return num; } char card::getSuit() { assert(suit == 'C' || suit == 'D' || suit == 'H' || suit == 'S'); return suit; } string card:: read() { string output=""; if...
Please follow the instructions below to create a code. The instructions are broken down into a few steps. Create the following functions along with a driver for each one confirming it works. The driver needs to test the function with at least 5 different inputs, although more is always better. Be sure to use the function display_startup_banner( ) in all of your drivers. Please create separate files for each code. That is, if you're creating a function called learning_online_is_a_trip( )...
7.12 (Card Shuffling and Dealing) Modify the program in Fig. 7.24 so that the card-dealing function deals a five-card poker hand. Then write the following additional functions: a) Determine whether the hand contains a pair. b) Determinewhetherthehandcontainstwopairs. c) Determine whether the hand contains three of a kind (e.g., three jacks). d) Determinewhetherthehandcontainsfourofakind(e.g.,fouraces). e) Determine whether the hand contains a flush (i.e., all five cards of the same suit). f) Determine whether the hand contains a straight (i.e., five cards of...
Java Write a complete program that implements the functionality of a deck of cards. In writing your program, use the provided DeckDriver and Card classes shown below. Write your own Deck class so that it works in conjunction with the two given classes. Use anonymous objects where appropriate. Deck class details: Use an ArrayList to store Card objects. Deck constructor: The Deck constructor should initialize your ArrayList with the 52 cards found in a standard deck. Each card is a...
(Card Shuffling and Dealing) Modify the program below so that the card-dealing function deals a five-card poker hand. Then write the following additional functions: a) Determine whether the hand contains two pairs b) Determine whether the hand contains a full house (i.e., three of a kind with pair). c) Determinewhetherthehandcontainsastraight flush (i.e.,fivecardsofconsecutivefacevalues). d) Determine whether the hand contains a flush (i.e., five of the same suit) #include <stdio.h> #include <stdlib.h> #include <time.h> #define SUITS 4 #define FACES 13 #define CARDS...
I'm currently writing a program based on stub poker and trying to deal cards to the players, show their hands, and determine the winner, and lastly ask them to if they want to play another hand. I'm probably going to have to write a method to compare hands but i really need to just deal the cards and store in their hands Any help or suggestions? Here are my current classes. public class PlayingCard { private final Suit suit;...