Concept explainers
A)
Enumeration:
Enumeration is a user-defined data type which consists of enumerators; the enumerators are used to represent integer constants.
- An enumeration can be defined by using the keyword “enum”.
- By default, the values of enumeration type are filled with “0” to “n” sequentially and those default values can be changed when declaring the enumeration.
- In a sequence of enumerators, if the first enumerator is assigned with a “user-defined value” and the next enumerator is not assigned with any value, then by default the next enumerator will be filled by the value “user-defined value of previous enumerator plus 1”.
- The type name of an enumeration is optional; if name of the enumeration type is not given then it is referred as “anonymous”.
Syntax:
Syntax to declare an enumerated data type is as follows,
enum type_name {identifier_1, identifier_2, identifier_3, … identifier_n};
In the above syntax,
- “enum” is the keyword used to declare an enumerator.
- “type_name” refers the name of the type of the enumerator.
“identier_1” to “identifier_n” are refers the list of the identifiers declared in the enumerator.
Given statement:
enum Department {Purchasing, Manufacturing, Warehouse, Sales};
Department floor1, floor2;
int dNum = 2;
- Here, an “enum” is a keyword and “Department” is the variable name of an enumeration. “Purchasing”, “Manufacturing”, “Warehouse” and “Sales” are the values used in the enumeration.
- The variable name “floor1” and “floor2” of type “Department” is defined. These two variables can only store any one of the four values (Purchasing, Manufacturing, Warehouse, Sales).
- “Purchasing”, “Manufacturing”, “Warehouse” and “Sales” are treated as integers by complier.
- Once enumerators are defined, their value cannot be changed in program.
B)
Enumeration:
Enumeration is a user-defined data type which consists of enumerators; the enumerators are used to represent integer constants.
- An enumeration can be defined by using the keyword “enum”.
- By default, the values of enumeration type are filled with “0” to “n” sequentially and those default values can be changed when declaring the enumeration.
- In a sequence of enumerators, if the first enumerator is assigned with a “user-defined value” and the next enumerator is not assigned with any value, then by default the next enumerator will be filled by the value “user-defined value of previous enumerator plus 1”.
- The type name of an enumeration is optional; if name of the enumeration type is not given then it is referred as “anonymous”.
Syntax:
Syntax to declare an enumerated data type is as follows,
enum type_name {identifier_1, identifier_2, identifier_3, … identifier_n};
In the above syntax,
- “enum” is the keyword used to declare an enumerator.
- “type_name” refers the name of the type of the enumerator.
“identier_1” to “identifier_n” are refers the list of the identifiers declared in the enumerator.
Given statement:
enum Department {Purchasing, Manufacturing, Warehouse, Sales};
Department floor1, floor2;
int dNum = 2;
- Here, an “enum” is a keyword and “Department” is the variable name of an enumeration. “Purchasing”, “Manufacturing”, “Warehouse” and “Sales” are the values used in the enumeration.
- The variable name “floor1” and “floor2” of type “Department” is defined. These two variables can only store any one of the four values (Purchasing, Manufacturing, Warehouse, Sales).
- “Purchasing”, “Manufacturing”, “Warehouse” and “Sales” are treated as integers by complier.
- Once enumerators are defined, their value cannot be changed in program.
C)
Enumeration:
Enumeration is a user-defined data type which consists of enumerators; the enumerators are used to represent integer constants.
- An enumeration can be defined by using the keyword “enum”.
- By default, the values of enumeration type are filled with “0” to “n” sequentially and those default values can be changed when declaring the enumeration.
- In a sequence of enumerators, if the first enumerator is assigned with a “user-defined value” and the next enumerator is not assigned with any value, then by default the next enumerator will be filled by the value “user-defined value of previous enumerator plus 1”.
- The type name of an enumeration is optional; if name of the enumeration type is not given then it is referred as “anonymous”.
Syntax:
Syntax to declare an enumerated data type is as follows,
enum type_name {identifier_1, identifier_2, identifier_3, … identifier_n};
In the above syntax,
- “enum” is the keyword used to declare an enumerator.
- “type_name” refers the name of the type of the enumerator.
“identier_1” to “identifier_n” are refers the list of the identifiers declared in the enumerator.
Given statement:
enum Department {Purchasing, Manufacturing, Warehouse, Sales};
Department floor1, floor2;
int dNum = 2;
- Here, an “enum” is a keyword and “Department” is the variable name of an enumeration. “Purchasing”, “Manufacturing”, “Warehouse” and “Sales” are the values used in the enumeration.
- The variable name “floor1” and “floor2” of type “Department” is defined. These two variables can only store any one of the four values (Purchasing, Manufacturing, Warehouse, Sales).
- “Purchasing”, “Manufacturing”, “Warehouse” and “Sales” are treated as integers by complier.
- Once enumerators are defined, their value cannot be changed in program.
D)
Enumeration:
Enumeration is a user-defined data type which consists of enumerators; the enumerators are used to represent integer constants.
- An enumeration can be defined by using the keyword “enum”.
- By default, the values of enumeration type are filled with “0” to “n” sequentially and those default values can be changed when declaring the enumeration.
- In a sequence of enumerators, if the first enumerator is assigned with a “user-defined value” and the next enumerator is not assigned with any value, then by default the next enumerator will be filled by the value “user-defined value of previous enumerator plus 1”.
- The type name of an enumeration is optional; if name of the enumeration type is not given then it is referred as “anonymous”.
Syntax:
Syntax to declare an enumerated data type is as follows,
enum type_name {identifier_1, identifier_2, identifier_3, … identifier_n};
In the above syntax,
- “enum” is the keyword used to declare an enumerator.
- “type_name” refers the name of the type of the enumerator.
“identier_1” to “identifier_n” are refers the list of the identifiers declared in the enumerator.
Given statement:
enum Department {Purchasing, Manufacturing, Warehouse, Sales};
Department floor1, floor2;
int dNum = 2;
- Here, an “enum” is a keyword and “Department” is the variable name of an enumeration. “Purchasing”, “Manufacturing”, “Warehouse” and “Sales” are the values used in the enumeration.
- The variable name “floor1” and “floor2” of type “Department” is defined. These two variables can only store any one of the four values (Purchasing, Manufacturing, Warehouse, Sales).
- “Purchasing”, “Manufacturing”, “Warehouse” and “Sales” are treated as integers by complier.
- Once enumerators are defined, their value cannot be changed in program.
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Starting Out with C++: Early Objects (9th Edition)
- QUESTION 21 int x1=200; int y1=3003; int z1, z2, z3, z4; int d1, d2, d3; _asm{ mov EAX, x1; 200 mov EBX, y1; 300 mov z1, ESP; assume initial ESP: OFFF FFEA add EAX, x1; 400 push EAX; mov d1, EAX:400 mov z2, ESP; push EBX; SUB EBX, x1; 300-200=100 mov d2, EBX; mov 23, ESP; POP ECX; MOV d3, ECX; MOV z4, ESP; POP EDX; mov d4, EDX; What is z3 in Hexidecimal? O OFFF FFEA O OFFF FFE6 OFFF FFE2 OFFF FFEEarrow_forwardstruct namerec{ char last[15]; char first[15]; char middle[15]; }; struct payrecord{ int id; struct namerec name; float hours, rate; float regular, overtime; float gross, tax_withheld, net; }; Using C language. Given the above declaration, let payroll data record be stored in a structure called payrecord. Also define a type called payrecord for the structure data type that houses a payroll data record: typedef struct payrecord payrecord; This program reads data, computes payroll and prints it. Each data record is a structure, and the payroll is an array of structures. Overtime hours are 150% of the rate. (Note: Maximum regular hours for the week is 40.) Tax is withheld 15% if weekly pay is below 500, 28% if pay is below 1000, and 33% otherwise. A summary report prints the total gross pay and tax withheld. The following are the function prototypes: void readName(payrecord payroll[], int i); - reads a single name. void printName(payrecord payroll[], int i); - prints a single name. void…arrow_forwardDeclare three structs: Struct TravelInfo{ String name; Double weight; Double newWeight; Int planetChoice; Int speed; }; Struct TravelTimeCalc{ Int totalTravelTime; Int years; Int days; Int hours; }; Struct Planet{ String planetNames; Double distanceFromSun; Double gravity; }; Planets, distance from sun(millions of miles), surface gravity as a percent of earth’s gravity: Mercury 36 0.27 Venus 67 0.86 Earth 93 1.00 Mars 141 0.37 Jupiter 483 2.64 Saturn 886 1.17 Uranus 1782 0.92 Neptune 2793 1.44 Pass the arrays to the FillPlanetInfo function that will load the data into the three arrays. Start a do while loop in main Pass the function AskSpaceTravellerInfo a reference to the TravelerInfo struct variable and the array of planet names. Get the user’s name, Earth weight, the speed they want to travel and the planet they wish to visit. Provide a menu with the planet names and a way for the user to select the chosen destination. Pass the data you obtained…arrow_forward
- A Car structure is declared as follows: struct Car { string make, model; int year; double cost; Car(string mk, string md, int y, double c) { make = mk; model = md; year = y; cost = c; }};Write a definition statement that defines a Car structure variable initialized with the following information:Make: Ford Year: 2010Model: Mustang Cost: $22,495arrow_forward} BMI(struct Person* person) { person->BMI = person->weight / (person->height person->height); return person->BMI; } //Q10: Why is the return type char*? char* determineWeightCategory(struct Person* person) {//assumes BMI is known const double UNDERWEIGHT = 18.5; const double NORMALWEIGHT = 24.9; const double OVERWEIGHT = 29.9; } else { //Q11: If the value in person->BMI is equal to 18.5 and person is athletic, what will be //stored in p- //Q12: The first if statement validates against certain conditions. //What are the conditions it is validating against? //HINT: Think about what causes BMI to be less than 0. if (person->BMI weightCategory, "ERROR"); } else if (person->BMI weightCategory, "Underweight"); } else if (person->BMI weightCategory, "Normalweight"); } else if (person->BMI weightCategory, "Overweight"); strcpy(person->weightCategory, "Obese"); return person->weightCategory; //Q13: Why do we return person->weightCategory? } //Q14: Why is provider passed by value?arrow_forwardexplain answerarrow_forward
- Please answer it according to the code below #include #define MAX_EMP 5 struct Employee { int id; int age; float salary; }; int count = 0; struct Employee emp[MAX_EMP]; void display() { printf("\n---=== EMPLOYEE DATA ===---\n"); printf("EMP ID\tEMP AGE\tEMP SALARY\n"); printf("======\t=======\t==========\n"); for(int i = 0; i < count; i++) { printf("%d\t%d\t%.2f\n", emp[i].id, emp[i].age, emp[i].salary); } } void add() { if(count == MAX_EMP) { printf("\nERROR!!! Maximum Number of Employees Reached\n"); return; } printf("\nAdding Employee ===============\n"); printf("Enter Employee ID: "); scanf("%d", &emp[count].id); printf("Enter Employee Age: "); scanf("%d", &emp[count].age); printf("Enter Employee Salary: "); scanf("%f", &emp[count].salary); count++; } void update() { int id, found = 0; float newSalary; printf("\nUpdate Employee Salary…arrow_forward#include int days_in_month(int month,int is_leap){ int res=-1; switch(month){ case 1: res=31;break; case 2: if(is_leap) res=29; else res=28;break; case 3: res=31;break; case 4: res=30;break; case 5: res=31;break; case 6: res=30;break; case 7: res=31;break; case 8: res=31;break; case 9: res=30;break; case 10: res=31;break; case 11: res=30;break; case 12: res=31;break; } return res; } int main(){ int m,l; printf("Enter month: "); scanf("%d",&m); printf("Enter 1 for leap year 0 for non leap: "); scanf("%d",&l); int days=days_in_month(m,l); printf("Days %d",days); } Write in carrow_forwardPlease continue tthe code below --- #include <stdio.h> struct Employee { // declaring the members of the structure char emp_full_name[30]; int pos; float rate_per_hour; int hour_worked; float deduction; float gross_week_pay; float net_week_pay; }; int main() { struct Employee var; // declare the Employee variable struct Employee *ptr; // create a pointer variable (*ptr) ptr = &var ;// assigning the address of var to pointer type variable return 0; }arrow_forward
- Why might a programmer use an enumerated type (or "enum") in their code?arrow_forwarduse c code to develop a program In this program you will create a structure called class to hold the information of a class in Seneca college’s buildings. The information required for each class is as follows Campus name (like newham or Seneca@york) Building name (like Victor Phillip Dahdaleh Building) floor (like 1 2 3 4 5, …) class code (like DB2109) size of class (40 60 25) has projector (yes/no) has podium (yes/no) has whiteboard (yes/no) The following is the declaration of the structure Struct class{ Char campus[101]; Char building[101]; --- --- } Complete the above structure template based on the list of attributes provided Implement the followinggetClass function that receives a pointer to a vehicle and fills it up with user data. No user input validation is necessary. The user should be properly prompted for each field. Be careful with proper usage of . (dot) operator and -> (arrow) operator as this is the part of the code that gets the mark! void getClass…arrow_forwardProgramming language : c++ Question : Make a class Student with attributes StudentName, Enrollment, semester, section, course MarksObtained and Grade. Write appropriate constructors, get and set functions for data members. The data member grade is automatically calculated based on marks obtained out of 100 for each course.arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT