Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. The approximate value of Lieb\'s square ice constant is 1.53960. Show how to

ID: 3593078 • Letter: 1

Question

1.

The approximate value of Lieb's square ice constant is 1.53960.

Show how to define this as a constant named LIEBS using a pre-processor directive:

Show show to define this as a constant named LIEBS using a const declaration:

Write just the statements needed to do this.  Do not include an entire program.  

2.

Defining an enumeration type means that you are defining a new data type.

a)True

b)False

3.

Show the code to define an enumeration type called Days, with possible values SUN, MON, TUE, WED, THU, FRI, SAT.

4.

You are writing a program for a veterinarians office, and have defined the following:

enum Animal { RODENT, CAT, DOG, HAMSTER };

Show the code to declare a variable named patient of type Animal and initialize it to an appropriate value.

5.

Given the definition of Animal in the previous question, the following code would be legal to declare a CAT.

Animal patient = 1;

a)true

b)false

6.

Given the definition of Animal in the previous question, the following code is legal.

if (patient == RODENT)

{

//do something rodenty

}

a)True

b)false

Explanation / Answer

1. The approximate value of Lieb's square ice constant is 1.53960.

Show how to define this as a constant named LIEBS using a pre-processor directive:

Show to define this as a constant named LIEBS using a const declaration:

Write just the statements needed to do this.  Do not include an entire program.  

Answer:

using a pre-processor directive:

#define LIEBS 1.53960

LIEBS using a const declaration:

const double LIEBS = 1.53960;

2. Defining an enumeration type means that you are defining a new data type.

a)True

b)False

Answer: True

The basic definition of an enumeration is, it is an user defined type that contains some constants. So obviously defining an enumeration is define a new data type.

3. Show the code to define an enumeration type called Days, with possible values SUN, MON, TUE, WED, THU, FRI, SAT.

Answer:

enum Days { SUN , MON, TUE, WED, THU, FRI, SAT }

By using the above by default SUM will have the value 0, MON will be 1, TUE will be 2 and so on

4. You are writing a program for a veterinarians office, and have defined the following:

enum Animal { RODENT, CAT, DOG, HAMSTER };

Show the code to declare a variable named patient of type Animal and initialize it to an appropriate value.

Answer: Animal patient = RODENT;

By doing the above the value of patient will be 1

5. Given the definition of Animal in the previous question, the following code would be legal to declare a CAT.

Animal patient = 1;

a)true

b)false

Answer: false

If we want to declare CAT we should use, Animal patient = CAT

6. Given the definition of Animal in the previous question, the following code is legal.

if (patient == RODENT)

{

//do something rodenty

}

a)True

b)false

Answer: True

If we want to compare the value of enum type we can either use

if (patient == RODENT)

{

            //do something rodenty

}

or

if (patient == 0) //as the value for RODENT is 0

{

            //do something rodenty

}