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...
Can someone help me get this C program to work? I am trying to get a 2d array to work correctly. /* Deals a random hand of cards */ #include <stdio.h> #include <stdlib.h> #include <time.h> #define TRUE 1 #define FALSE 0 #define BOOL int #define NUM_SUITS 4 #define NUM_RANKS 13 int main() { BOOL in_hand[NUM_SUITS][NUM_RANKS] = {FALSE}; int num_cards = 13, rank, suit; const char rank_code[ 13 ][ 10 ] = {"Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"}; const char suit_code[ 4 ] [ 10 ]...
The question is to make the game of war using Python. The information on how the cards will be represented and how the game will be played along with 2 sample runs is below. Representation of the deck of cards: The deck of cards will be simulated with integers of values from 1 to 13, where 1 represents the Ace, 11 the Jack, 12 the Queen, and 13 the King – these integers also represent the face values of the...
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...
S12 Five Crowns – Part 2 This week you will continue your work on the Five Crowns program. 1. You will create a class Deck that consists of the following: a. The vector of 116 cards from last week’s program. b. a method to deal a card from the deck 2. Create overloaded operators: a. bool operator == that overloads the == operator to check if two cards are equal. b. bool operator < that overload the < operator and...
This needs to be done in c++11 and be compatible with g++ compiling Project description: Write a C++ program to simulate a simple card game between two players. The game proceeds as follows: The 52 cards in a deck of cards are shuffled and each player draws three cards from the top of the deck. Remaining cards are placed in a pile face-down between the two players. Players then select a card from the three in their hand. The player...
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( )...