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++ MPL
- Question 02: To use variables in your C# programs, you must know how to create variable names. In C#, variable names must adhere to the following rules: The name can contain letters, digits, and the underscore character (_). The first character of the name must be a letter. The underscore is also a legal first character, but its use is not recommended at the beginning of a name. An underscore is often used with special commands, and it's sometimes hard to read. Case matters (that is, upper- and lowercase letters). C# is case-sensitive; thus, the names count and Count refer to two different variables. C# keywords can't be used as variable names. Recall that a keyword is a word that is part of the C# language. (A complete list of the C# keywords can be found in Appendix B, "C# Keywords.") Which of the following variables name are legal and illegal maxx yx5__wh3 gh*7 int inti _label checking#accoun 1max Sinxarrow_forwardWrite a statement that defines a named constant named SPEED. The constant's data type should be int, and its value should be 75. const int SPEED 75;arrow_forwardint my_num = 100.0; b- int $my_num = '10000': int myNum = 100%3B d- int my num 100000; a- 1) Which one is a valid variable declaration? C-arrow_forward
- For the following code: for ( a = 1, b = 5, c = 3; a < 4; a++, b++ ) { c = a * b + c; } Indicate what values for the following variable will be when the code endsa=b=c=arrow_forward= 1000; int myNum b- double my_num= 100; 4) а- Which one is NOT a valid variable declaration? c- int my_num = '10" d- int mynuml = 10 7/Parrow_forwardC++ Language code and explain Zodiac Sign Identifier - Ask the user's birth month and birth day and return the corresponding Zodiac Sign he/she belongs: Evaluate the user's birth month and day by checking the following: If born from, Mar 21 to Apr 19 - Aries Apr 20 to May 20 - Taurus May 21 to Jun 20 - Gemini Jun 21 to Jul 22 - Cancer Jul 23 to Aug 22 - Leo Aug 23 to Sep 22 - Virgo Sep 23 to Oct 22 - Libra Oct 23 to Nov 21 - Scorpio Nov 22 to Dec 21 - Sagittarius Dec 22 to Jan 19 - Capricorn Jan 20 to Feb 18 - Aquarius Feb 19 to Mar 20 - Pisces Example: What is your month of birth? 1 - January (31 days) 2 - February (27 days, if Leap Year 28 days) 3 - March (31 days) 4 - April (30 days) 5 - May (31 days) 6 - June (30 days) 7 - July (31 days) 8 - August (31 days) 9 - September (30 days) 10 - October (31 days) 11 - November (30 days) 12 - December (31 days) Please enter your birth month: 8 Please enter day of your birth: 16 Please enter your year of birth: 1997 Your birthday is every…arrow_forward
- WHAT IS THE DIFFERENCE BETWEEN DECLARING A VARIABLE AND DEFINING A VARIABLE?arrow_forwardWrite the declaration and assignment statement for an integer variable nums that is assigned the value 15arrow_forwardA(n) specifies a variable’s name and data type.a. assignmentb. variable specificationc. variable certificationd. variable declarationarrow_forward
- Assume a program has the following variable definitions int units; float mass; double weight;and the following statement:weight = mass * units;Which automatic data type conversions will take place?arrow_forwardIndicates the missing variable or operator: A + (B • C) = (A + B) • (A+___ )arrow_forwardPlease use C# for this. Thank you soo much!arrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning