You will get email Reply within few hours

Tuesday, 28 May 2013

Enum and String Functions

I.    Write C++ statements that do the following. 
a.    Define an enum type BookType, with the values MATH, COSC, ENGL, HIST, PHYS, PHIL
       
    b.    Declare a variable book of BookType
           
c.    Assign MATH to the variable book .
       
d.    Advance book to the next value in the list.
       
e.    Output the value of the variable book.
       

II.    Given:  enum CurrencyType { DOLLAR, PESO, EURO, YEN, YUAN };
          CurrencyType currency;

    determine if the following statements are valid or invalid?

    a.    currency = DOLLAR;                        valid    invalid
    b.    cin>> currency;                        valid    invalid
    c.    currency = static_cast<CurrencyType>(currency + 1);    valid    invalid

III.    Given:  enum CropType { WHEAT, CORN, RYE, BARLEY, OATS};
          CropType crop;

    determine if the following statements are true or false?

    a.    static_cast<int> (WHEAT) is zero                true    false
    b.    static_cast<CropType>(static_cast<int>(WHEAT) – 1 ) is WHEAT
                                        true    false
    c.    RYE > WHEAT                        true    false

IV.    Assume the following declarations:
string str1 = “Amusement Park”;
string str2 = “Going to”;
string str3 = “the”;

    determine the output of the following statements.

a.    cout << str1.length( ) << endl;        _________________
b.    cout << str1.find(‘e’) << endl;        _________________
c.    cout << str1.substr(1, 5) << endl;        _________________
d.    cout << str2.find(“to”) << endl;        _________________
e.    cout << str2.substr(4, 3) << endl;        _________________
f.    cout << str3.length( ) << endl;        _________________

OR
Click here to get solution