Question

In: Computer Science

(1)Discuss the syntax for combining the definition and declaration of an enumeration type into one statement....

(1)Discuss the syntax for combining the definition and declaration of an enumeration type into one statement. Provide some examples.

(2) Describe the syntax of a namespace statement. Discuss the syntax for accessing a namespace member. Also, review the syntax for the using namespace statement and discuss how this simplifies the process of accessing namespace members.

Solutions

Expert Solution

1). ANSWER :

GIVENTHAT :

To Discuss the syntax for combining the definition and declaration of an enumeration type into one statement. Provide some examples

 An enumeration type is declared and defined using enum keyword using the following syntax:

        enum NAME { val1, val2, ... } ENUM_VAR;

    Here, NAME is the name of the enumeration, val1, val2, etc are values of the enum NAME, and
    ENUM_VAR is an enum variable of type NAME declared with definition of the enum.
    The default value of val1 is 0, val2 is 1, and so on.
    To change default values of enum, we could use the following syntax:

        enum NAME { val1 = 1, val2 = 3, ... } ENUM_VAR;

    Here, val1 is 1 and val2 is 3.

    Some examples:

        enum Fruit { apple, orange, guava } HealthyFruit;

        enum Color { red = 1, green = 2, blue = 3 } ShirtColor;

2).To Describe the syntax of a namespace statement. Discuss the syntax for accessing a namespace member. Also, review the syntax for the using namespace statement and discuss how this simplifies the process of accessing namespace members.

    A namespace in C++ is declared using the following syntax:

        namespace NAME{
            identifier 1
            identifier 2
            ...
        }

    Here, NAME is the name of the namespace and identifier 1, identifier 2  are members of
    the namespace NAME.

    For example:

        namespace foo{
            int x, y;
        }

    Here, x and y are members of foo namespace.

    To access namespace members, we could use the following syntax:

        NAME::member_name;

    For example,

        // To access member x of namespace foo
        foo::x

    The using namespace statement is used to access a namespace's member without the need of explicitly
    mentioning namespace (along with scope resolution operator) everytime we access that member.

    Syntax for using namespace statement:

        using namespace foo;

    Now in order to access members of namespace foo, we can simply write x instead of foo::x.
    This simplyfies the process of accessing the namespace members by removing the need to write namespace
    name each and everytime. This is commonly used in case of C++'s std namespace by using namespace std; before the main function.

Related Solutions

1, Which one of the following statement explains the definition of Type I error: Pick one...
1, Which one of the following statement explains the definition of Type I error: Pick one Reject the null hypothesis when the null hypothesis is true Reject the null hypothesis when the null hypothesis is false Fail to reject the null hypothesis when the null hypothesis is true Fail to reject the null hypothesis when the null hypothesis is false none of the above 2, You test a hypothesis and you get a t-score = 2.87. If the p-value is...
Which is NOT a valid return type for a method declaration Select one: a. double b....
Which is NOT a valid return type for a method declaration Select one: a. double b. char c. null d. String e. boolean f. float g. int h. void Statements that allow a program to choose, based on a boolean expression, between alternative blocks of code are known as: Select one: a. Selection statements or Conditionals b. Declarations c. Methods d. Repetition Statements or Loops e. Composition
(1) Create three files to submit. ContactNode.h - Class declaration ContactNode.cpp - Class definition main.cpp -...
(1) Create three files to submit. ContactNode.h - Class declaration ContactNode.cpp - Class definition main.cpp - main() function (2) Build the ContactNode class per the following specifications: Parameterized constructor. Parameters are name followed by phone number. Public member functions InsertAfter() (2 pts) GetName() - Accessor (1 pt) GetPhoneNumber - Accessor (1 pt) GetNext() - Accessor (1 pt) PrintContactNode() Private data members string contactName string contactPhoneNum ContactNode* nextNodePtr Ex. of PrintContactNode() output: Name: Roxanne Hughes Phone number: 443-555-2864 (3) In main(),...
(1) Create three files to submit: ItemToPurchase.h - Class declaration ItemToPurchase.cpp - Class definition main.cpp -...
(1) Create three files to submit: ItemToPurchase.h - Class declaration ItemToPurchase.cpp - Class definition main.cpp - main() function Build the ItemToPurchase class with the following specifications: Default constructor Public class functions (mutators & accessors) SetName() & GetName() (2 pts) SetPrice() & GetPrice() (2 pts) SetQuantity() & GetQuantity() (2 pts) Private data members string itemName - Initialized in default constructor to "none" int itemPrice - Initialized in default constructor to 0 int itemQuantity - Initialized in default constructor to 0 (2)...
Discuss the pros and cons of each type of consolidation statement.
Discuss the pros and cons of each type of consolidation statement.
1. Give a complete, all-encompassing definition of a gene. Discuss each part of your definition. Is...
1. Give a complete, all-encompassing definition of a gene. Discuss each part of your definition. Is the definition of the gene as determined through complementation, recombination, and mutation for prokaryotes directly applicable to eukaryotes or must some additional considerations be taken into account? Explain.
1. Discuss one fringe benefit. Is it taxable? If so, how is it taxed? What type...
1. Discuss one fringe benefit. Is it taxable? If so, how is it taxed? What type of employee would get these benefits (i.e. CEO, CPA, Administrative Assistant)?
Part A. Match the letter of the definition/statement in Column 1 to the term in Column...
Part A. Match the letter of the definition/statement in Column 1 to the term in Column 2 to which the definition corresponds/that completes the statement. (15 points) Definitions/Statements Corresponding Term A. _____ is the transmission of a message from a sender to a receiver via a medium (or channel) of transmission. 1. Non-traditional media _____ B. ____ include family members, friends, classmates, fellow consumers. 2. Order presentation _____ C. One of the barriers to communication is clutter from competing communication...
1) Match the proper type of prevention strategy of confounding to its definition. A. Separates the...
1) Match the proper type of prevention strategy of confounding to its definition. A. Separates the sample into groups defined by the confounder during analysis. B. Uses statistical approaches to adjust for the confounder in a model. C. Attempts to control for confounding by pairing cases and control on the potential confounding variable. D. Attempts to prohibit variation of the confounder in the study sample. E. Attempts to ensure equal distributions of the confounding variable in each exposure category. 1....
Discuss the pathophysiology of type one and type two diabetes. Develop a nutritional education plan for...
Discuss the pathophysiology of type one and type two diabetes. Develop a nutritional education plan for either a type one or type two diabetic. Include in your plan the nutritional considerations for one oral medication and one type of insulin used in the treatment of the disorder.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT