Concept explainers
Explanation of Solution
Named constants:
In C++, constants represent fixed values and typically, they remain unchanged during program execution.
- Constants should be initialized at the time of their creation.
- New values cannot be assigned to them later.
Syntax to define the named constant:
const data_type qualifier_name = value;
Example:
// Constant declaration
const double PI_Value = 3.14;
Explanation:
It is similar to a variable declaration; however, it needs a keyword “const” before the data type. This keyword tells the compiler that the variable value is constant.
Named constant for given “const” qualifier:
Value 1:
Consider the given Euler’s constant value “2.71828” and its equivalent named constant will be as follows:
// Declare the constant value with double data type
const double EULER = 2.71828;
Explanation:
In the above statement, “const” is a keyword, double is a data type of the “const” qualifier and “EULER” is a name of the “const” qualifier.
Value 2:
Consider the given constant value “5.256E5” for minutes of a year and its equivalent named constant will be as follows:
// Declare the constant value with double data type
const double MINUTES = 5.256E5;
Explanation:
In the above statement, “const” is a keyword, double is a data type of the “const” qualifier and “MINUTES” is a name of the “const” qualifier...
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Starting Out With C++: Early Objects, Student Value Edition (9th Edition)
- Assume that you have declared a variable as double salary =45000.00;. Which of the following will display $45,000? WriteLine(salary.ToString(c)); WriteLine(salary.ToString(c0)); WriteLine(salary); Two of thesearrow_forwardWhat is the standard practice for spelling out named constants in code?arrow_forwardThe declaration statement for a named constant requires . a. a data typeb. a name c. a value d. all of the abovearrow_forward
- assume that the following variables contain the values below numberBig = 100 numberMedium = 10 numberSmall = 1 wordBig = "Constitution" wordMedium = "Dance" wordSmall = "Toy" For each of the following Boolean expressions, decide whether the statement is True, False or illegal numberBig > numberSmall numberBig < numberMedium numberMedium = numberSmall numberBig = wordBig numberBig = "big" wordMedium > wordSmall wordSmall = "TOY" numberBig <= 5 * numberMedium + 50 numberBig >= 2000 numberBig > numberMedium + numberSmall numberBig > numbermedium AND numberbig < numberSmall numberBig = 100 or numberBig > numberSmall numberBig < 10 or numberSmall >10 numberBig = 300 AND numberMedium = 10 OR numberSmall = 1 wordSmall > wordBig wordSmall > wordMediumarrow_forwardCreate the following, in Python: You have a business that cleans floors in commercial space and offices. You charge customers $0.45 per square yard, and some customers require multiple cleanings every month. You need two custom functions for your business. The first function takes a floor's length and width in feet and returns the area in square yards. The second void function takes the area, charge per square yard, and number of monthly cleanings as arguments and prints the cleaning cost. This latter function uses selection (if...else) logic to print different output for single and multiple monthly cleanings (see Sample Outputs). Use a properly named constant for the charge per square yard, too.arrow_forwardIn python. Write a program that calculates the BMI (Body Mass Index) of a person, which is used to determine if the ratio of weight and height is appropriate. BMI can be calculated using the following formula: index = weight / height ^ 2 Where the weight must be given in kilograms and the height in meters. The following table shows how the different index ranges are classified: index range Description index <20 LOW WEIGHT 20 <= index <25 NORMAL 25 <= index <30 OVERWEIGHT 30 <= index <40 OBESITY index >= 40 MORBID OBESITYarrow_forward
- In C++, State if the following variable names are valid or invalid. If it's invalid, state why. Note: invalid here means creating a syntax error. a) 1wayTicket b) employee_pay c) #zombies d) R66Y e) STOP! f) Final Examarrow_forwardFor the following declaration statements, determine if the statement is valid or invalid, if invalid indicate why. a) int My Age; b) double double_1; c) double Income Tax; d) float gpa = 3.90; e) String Name = ‘Joe’; f) Char MI = M; g) Char Letter = “B”; h) double static; i) double Salary$ = 0.0; j) int _VarM;arrow_forwardWhat is the normal spelling convention for named constants?arrow_forward
- Write a variable declaration for an Integer variable named intUnitsSold.arrow_forwardAssuming the following code: int x = myfunction1(); /* arbitrary value */ int y = myfunction2(); /* arbitrary value */ int z = myfunction3(); /* arbitrary value */ //convert to double double dx = (double) x; double dy = (double) y; double dz = (double) z; unsigned ux = x; unsigned uy = y; The following statement always evaluates to 1 (True or False): (dx + dy) + dz == dx + (dy + dz) True Falsearrow_forwardWrite statements using the const qualifier to create named constants for the following literal values:arrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage