Question

In: Computer Science

In C++, the concept of a "bag" may be represented as (click all that apply): a...

In C++, the concept of a "bag" may be represented as (click all that apply):

a vector of pointers of a specific object type
a vector of objects
a vector of generic pointers
an array of whole numbers

The C++ keywords used to implement the principle of least privilege are (click all that apply):

public
#include
const
struct
ifndef
class

If a class Employee has a data member Date hireDate , and Employee's member functions need to access private data members of Date ... (click all that apply)

..Date has to declare the class Employee as its friend, or...
...Employee has to declare Date as its friend, or...
...trick question -- private members are accessible only by other members of the same class. That's the whole point of making members private.

What is the output from the code block below:

int i = 8;
cout << i++ << " ";
cout << ++i << endl;
8 10
9 10
9 9
8 9

Solutions

Expert Solution

1. A,B,D are correct
Explaination: Here, Bag is a container class which can contain int, float, char or any object or even a pointer. But, all elements in a Bag container should be of same type.

Here, option A is a vector of pointers of a specific object type which implies all pointers are of the same type as mentioned in option itself

Option B is a vector of objects which implies the objects are of same type
Because when declaring vector, object or data type is mentioned in the declaration itself

e.g. vector<int> v1;

Option C is a vector of generic pointers i.e. all pointers are of different datatypes

So, a vector of different datatypes can't be elements of a bag as bag contains elements of same datatype

Option D is an array of whole numbers which are all of same datatype i.e. the elements can go from 0 to any positive integer which can either be int or long int

But, while declaring an array, we need to mention the datatype. So, all elements are of same datatype i.e. short int or int or long int or long long int

2. const

Explaination: Here, const is the keyword in C++ which is used to implement the principle of least privilege. When const is used with a variable of any datatype, it makes that variable's value fixed. Any attempt to change its value while running program, is marked as error. No method has any privilege to change its value.

3. Date has to declare the class Employee as its friend

Explaination: For Employee's member functions to access private members of Date class, Date class will have to declare Employee class as its friend as follows:

class Date { 
private: 
    int x; 
    

    friend class Employee;
}; 

4. 8 10

Explaination: Here, initial value of i is 8

In the line `cout<<i++<<" ";

i is post-incremented, i.e. first value of i is printed, then it is increased by 1

So, 8 is printed and value of i becomes 9

Then, i is pre-incremented, i.e. first value is incremented, then printed

So, the value becomes 10 and is printed


Related Solutions

In C++, the concept of a "bag" may be represented as (click all that apply): a...
In C++, the concept of a "bag" may be represented as (click all that apply): a vector of pointers of a specific object type a vector of objects a vector of generic pointers an array of whole numbers The C++ keywords used to implement the principle of least privilege are (click all that apply): public #include const struct ifndef class If a class Employee has a data member Date hireDate , and Employee's member functions need to access private data...
Discuss the concept of the risk-return trade-off and how it may apply in different circumstances.
  Discuss the concept of the risk-return trade-off and how it may apply in different circumstances.
1. Discuss the concept of the risk-return trade-off and how it may apply in different circumstances.
1. Discuss the concept of the risk-return trade-off and how it may apply in different circumstances. 2. Outline the risk-reduction benefits of diversification of an investment portfolio. In your answer, briefly discuss how portfolio diversification works in principle to minimise overall investment risk.
Why is ethical relativism a good concept to adopt? (Select all that apply.) A. We should...
Why is ethical relativism a good concept to adopt? (Select all that apply.) A. We should use different standards for different contexts B. Friends and family should be treated differently than coworkers C. Our reputation could increase D. One does not want an inconsistent outcome
Select all the answers that apply to modular design: 1. A module may not refer to...
Select all the answers that apply to modular design: 1. A module may not refer to other modules. 2. Modular design is an important part of procedural programming. 3. Modular design identifies the components of a program that can be developed independently. 4. Each module consists of a set of logical constructs that are related to one another. ///////////////////// Place the following parts of a function header into their correct order:       -       1.       2....
Provide a detailed explanation of concept of a Value Chain and apply the concept to a...
Provide a detailed explanation of concept of a Value Chain and apply the concept to a company of your choice
explain the democratic concept or principle represented in the Declaration of Independence and/or the Constitution.
explain the democratic concept or principle represented in the Declaration of Independence and/or the Constitution.
How does the going concern concept, consistency concept and accrual concept apply to the bankruptcy of...
How does the going concern concept, consistency concept and accrual concept apply to the bankruptcy of JC Penny due to the recent pandemic, COVID-19?
1. An inducer may affect gene expression by binding: (Select all that apply) A. Directly to...
1. An inducer may affect gene expression by binding: (Select all that apply) A. Directly to a consensus sequence on DNA B. An activator protein to remove it from the DNA C. A repressor protein to remove it from the DNA D. A corepressor E. An activator protein to help it bind DNA F. A repressor protein to help it bind DNA 2.What is the main difference between structural genes and control sequences in bacteria? Cite examples for both. 3.How...
1) Creation of an agency relationship may be by (choose all that apply) consensual agreement necessity...
1) Creation of an agency relationship may be by (choose all that apply) consensual agreement necessity operation of law conduct of the parties merger express contract estoppel ratification of an unauthorized act judgment 2) State and federal government statutes, doctrines and practices that affect many aspects of employment law include, but are not limited to, (choose all that apply) Civil Rights Act of 1964 Pregnancy Discrimination Act Occupational Safety and Health Act Equal Employment Opportunity Act Fair Labor Standards Act...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT