1. The approximate value of Lieb\'s square ice constant is 1.53960. Show how to
ID: 3593079 • 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:
answer: #define LIEBS 1.53960
#define is to declare the preprocessor directives. LIEBS is declared value as 1.53960
Show show to define this as a constant named LIEBS using a const declaration:
answer: const float LIEBS 1.53960;
here declared as constant inside the main function. This value is constant , andit cannot be changed.
2.
Defining an enumeration type means that you are defining a new data type.
answer: True.
Defining enumeration is user defined data type. Integral value is assigned to the names.keyword 'enum' is used to define a new type wihtout a typedef statment.
3.
Show the code to define an enumeration type called Days, with possible values SUN, MON, TUE, WED, THU, FRI, SAT.
sample code.
#include<stdio.h>
enum Days{Mon, Tue, Wed, Thur, Fri, Sat, Sun}; ///Days defined
int main()
{
enum Days;
printf("%d %d %d ",mon, wed,fri);
return 0;
}
output:
0 2 4
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.
code:
#include<stdio.h>
enum Animal{RODENT, CAT, DOG, HAMSTER};
int main()
{
enum Animal patient; //declare the variable name patient
patient = DOG; //DOg is assigned
printf("%d ",patient); //prints the value
return 0;
}
output:
2
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: True.
#include<stdio.h>
enum Animal{RODENT, CAT, DOG, HAMSTER};
int main()
{
enum Animal patient =1; //declare the variable name patient =1, then patient is cat
if(patient == CAT)
printf("It is CAT");
else
printf("Not a CAT");
return 0;
}
output:
It is 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
#include<stdio.h>
enum Animal{RODENT, CAT, DOG, HAMSTER};
int main()
{
enum Animal patient =1; //declare the variable name patient =1, then patient is cat
if(patient == RODENT)
printf("It is CAT");
else
printf("Not a CAT");
return 0;
}
output:
Not a CAT
//for any clarification, please do comments
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.