Starting Out With C++: Early Objects (10th Edition)
Starting Out With C++: Early Objects (10th Edition)
10th Edition
ISBN: 9780135235003
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
bartleby

Concept explainers

Expert Solution & Answer
Book Icon
Chapter 3.5, Problem 3.17CP

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...

Blurred answer
Students have asked these similar questions
Given the following variable declaration, choose the option that describes them              $num1='18';  $num2=18; a. Variable $num1 is incorrect while Variable $num2 is correct. b. Both the variables have the same data type. c. Variable $num1 has a string data type while variable $num2 is an integer. d. Both the variables are incorrect.
java a. Write the complete statement needed to declare and initialize a new constant to represent the number of weeks in a year, which is  52. Name it "weeks in year" using correct style for a constant. Note: The Java style guide states that one space is used on either side of binary operators. b. Write a simple expression using a relational operator that returns true if the integer variable count is at least 12. Do not use any parentheses or place it in a complete statement.
Assume that speed = 10 and miles = 5. What is the value of each of the following expressions? A. speed + 12 - miles * 2 B. speed + miles * 3 C. (speed + miles) * 3 D. speed + speed * miles + miles E. (10 - speed) + miles / miles

Chapter 3 Solutions

Starting Out With C++: Early Objects (10th Edition)

Ch. 3.2 - Prob. 3.11CPCh. 3.2 - Study the following program code and then complete...Ch. 3.2 - Complete the following program skeleton so that it...Ch. 3.3 - Assume the following variable definitions: int a =...Ch. 3.3 - What will the following program code display if a...Ch. 3.3 - What will the following program code display? int...Ch. 3.5 - Prob. 3.17CPCh. 3.5 - Complete the following program code segment so...Ch. 3.6 - Write a multiple assignment statement that assigns...Ch. 3.6 - Write statements using combined assignment...Ch. 3.6 - What will the following program segment display?...Ch. 3.7 - Write cout statements with stream manipulators...Ch. 3.7 - The following program segment converts an angle in...Ch. 3.8 - Will the following string literal fit in the space...Ch. 3.8 - If a program contains the definition string name;...Ch. 3.8 - Prob. 3.26CPCh. 3.10 - Use a mathematical library function with a cout...Ch. 3.10 - Assume the variables angle1 and angle2 hold angles...Ch. 3.10 - To find the cube root (the third root) of a...Ch. 3.10 - Write a statement that produces a random number...Ch. 3 - Prob. 1RQECh. 3 - Prob. 2RQECh. 3 - Prob. 3RQECh. 3 - Assume the following variables are defined: int...Ch. 3 - What header files must be included in the...Ch. 3 - Write C++ expressions for the following algebraic...Ch. 3 - Assume a program has the following variable...Ch. 3 - Prob. 11RQECh. 3 - Write a multiple assignment statement that can be...Ch. 3 - Write a pair of multiple assignment statements...Ch. 3 - Is the following code legal? Why or why not? const...Ch. 3 - Write a cout statement that uses stream...Ch. 3 - Write a cout statement that uses stream...Ch. 3 - What header file must be included A) to perform...Ch. 3 - Pet World offers a 15 percent discount to senior...Ch. 3 - A bowling alley is offering a prize to the bowler...Ch. 3 - A retail store grants its customers a maximum...Ch. 3 - Little Italy Pizza charges 14.95 for a 12-inch...Ch. 3 - A) (Assume the user enters George Washington.)...Ch. 3 - Each of the following program segments has some...Ch. 3 - A) const int number1, number2, product; cout ...Ch. 3 - Soft Skills Often programmers work in teams with...Ch. 3 - Miles per Gallon Write a program that calculates a...Ch. 3 - Stadium Seating There are three searing categories...Ch. 3 - How Much Insurance? Many financial experts advise...Ch. 3 - Test Average Write a program that asks for five...Ch. 3 - Average Rainfall Write a program that calculates...Ch. 3 - Male and Female Percentages Write a program that...Ch. 3 - Vacation Days Write a program that prompts the...Ch. 3 - How Many Widgets? The Yukon Widget Company...Ch. 3 - How many Calories? A bag of cookies holds 30...Ch. 3 - Ingredients Adjuster A cookie recipe calls for the...Ch. 3 - Celsius to Fahrenheit Write a program that...Ch. 3 - Monthly Sales Tax A retail company muse file a...Ch. 3 - Property Tax Madison County collects property...Ch. 3 - Senior Citizen Property Tax Madison County...Ch. 3 - Math Tutor Write a program that can be used as a...Ch. 3 - Interest Earned Assuming there are no deposits...Ch. 3 - Monthly Payments The monthly payment on a loan may...Ch. 3 - Pizza Slices Joe's Pizza Palace needs a program to...Ch. 3 - How Many Pizzas? Modify the program you wrote in...Ch. 3 - Angle Calculator Write a program that asks the...
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage