Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 2.1, Problem 7STE
Program Plan Intro
Defining good variable name:
- In every
programming , variable names and other names should at least hint at the meaning or use of thing they are naming. - It is very useful to understand a program if the variables contains the meaningful names.
Rules for naming variable:
- Variable name cannot be a C++ keyboard. Example “int”, “double” cannot be a variable name because of, it is the keyword of C++.
- Variable name must begin with an alphabet that is upper case (“A” to “Z”) or lowercase (“a” to “z”).
- Variable name can contain an underscore (_) but can’t contain the other characters such as “!”, “@”, “&” etc.
- The name of the variable can be of any length however only first 31 characters are important.
- Variable name contains the combination of upper and lowercase letters.
Example:
The example for proper and improper usage of variable names is given below:
Proper usage of variable names: “mark”, “highestRank”, “first_place” etc.
Improper usage of variable names: “12mark”, “!high@3”, “*place*” etc.
Explanation of Solution
Variable to hold the pay rate for an hourly employee:
- The variable name to hold the pay rate for an hourly employee is “payrate”. Based on the description, the given variable needs to be declared in datatype of “double”...
Explanation of Solution
Variable to hold the highest score in an exam:
- The variable name to hold the highest score in an exam is “highestScore”. Based on the description, the given variable needs to be declared in datatype of “double”...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
In which scenarios would a programmer prefer using a constant over a variable?
A local variable can be accessed by all the functions in a program.True or False
The Problem: You need to increment a variable in the fastest possible way.
Chapter 2 Solutions
Problem Solving with C++ (10th Edition)
Ch. 2.1 - Give the declaration for two variables called feet...Ch. 2.1 - Give the declaration for two variables called...Ch. 2.1 - Give a C++ statement that will change the value of...Ch. 2.1 - Give a C++ statement that will increase the value...Ch. 2.1 - Give a C++ statement that will change the value of...Ch. 2.1 - Prob. 6STECh. 2.1 - Prob. 7STECh. 2.2 - Give an output statement that will produce the...Ch. 2.2 - Give an input statement that will fill the...Ch. 2.2 - Prob. 10STE
Ch. 2.2 - Write a complete C++ program that writes the...Ch. 2.2 - Write a complete C++ program that reads in two...Ch. 2.2 - Prob. 13STECh. 2.2 - Write a short program that declares and...Ch. 2.3 - Convert each of the following mathematical...Ch. 2.3 - Prob. 16STECh. 2.3 - What is the output of the following program lines...Ch. 2.3 - Write a complete C++ program that reads two whole...Ch. 2.3 - Given the following fragment that purports to...Ch. 2.3 - What is the output of the following program lines...Ch. 2.4 - Write an if-else statement that outputs the word...Ch. 2.4 - Suppose savings and expenses are variables of type...Ch. 2.4 - Write an if-else statement that outputs the word...Ch. 2.4 - Write an if-else statement that outputs the word...Ch. 2.4 - Consider a quadratic expression, say x2 x 2...Ch. 2.4 - Consider the quadratic expression x2 4x + 3...Ch. 2.4 - What is the output of the following cout...Ch. 2.4 - What is the output produced by the following (when...Ch. 2.4 - What output would be produced in the previous...Ch. 2.4 - What is the output produced by the following (when...Ch. 2.4 - What is the output produced by the following (when...Ch. 2.4 - What is the most important difference between a...Ch. 2.4 - What is the output produced by the following (when...Ch. 2.4 - Write a complete C++ program that outputs the...Ch. 2.5 - The following if-else statement will compile and...Ch. 2.5 - Prob. 36STECh. 2.5 - Write a complete C++ program that asks the user...Ch. 2 - A metric ton is 35,273.92 ounces. Write a program...Ch. 2 - The Babylonian algorithm to compute the square...Ch. 2 - Many treadmills output the speed of the treadmill...Ch. 2 - Write a program that plays the game of Mad Lib....Ch. 2 - The following is a short program that computes the...Ch. 2 - A government research lab has concluded that an...Ch. 2 - Workers at a particular company have won a 7.6%...Ch. 2 - Modify your program from Programming Project 2 so...Ch. 2 - Negotiating a consumer loan is not always...Ch. 2 - Write a program that determines whether a meeting...Ch. 2 - Prob. 6PPCh. 2 - It is difficult to make a budget that spans...Ch. 2 - You have just purchased a stereo system that cost...Ch. 2 - Write a program that reads in ten whole numbers...Ch. 2 - Modify your program from Programming Project 9 so...Ch. 2 - Sound travels through air as a result of...Ch. 2 - Prob. 12PPCh. 2 - The HarrisBenedict equation estimates the number...Ch. 2 - Write a program that calculates the total grade...Ch. 2 - It is important to consider the effect of thermal...Ch. 2 - Prob. 16PP
Knowledge Booster
Similar questions
- (Civil eng.) Write an assignment statement to determine the maximum bending moment, M, of a beam, given this formula: M=XW(LX)L X is the distance from the end of the beam that a weight, W, is placed. L is the length of the beam.arrow_forwardHow many accurate digits are stored in a float or double type variable?arrow_forwardWrite a Boolean expression that is true if and only if a student is a senior who is majoring in either Information Technology or Computer Science and has a GPA of at least 3.5 but not higher than 3.85. Assume that the student’s year in school is stored in the variable year, the student’s major is stored in the variable major, and the student's GPA is stored in the variable gpa. Use parentheses to indicate clearly the order in which the operations should be evaluated.arrow_forward
- In physics, an object that is in motion is said to have kinetic energy. The following formula can be used to determine a moving object’s kinetic energy: KE = 1⁄2 mv2 The variables in the formula are as follows: KE is the kinetic energy in joules, m is the object’s mass in kilograms, and v is the object’s velocity in meters per second.Write a function named kineticEnergy that accepts an object’s mass (in kilograms) and velocity (in meters per second) as arguments. The function should return the amount of kinetic energy that the object has. Demonstrate the function by calling it in a program that asks the user to enter values for mass and velocity.arrow_forwardFor the following wff, indicate which variables are free and which are bound (you can use ‘F’ for deee and ‘B’ for bound.) Either (i) draw a vertical line underneath each variable with the letters ‘F’ or ‘B’ at the bottom of each vertical line or (ii) color bound variables red and free variables green.arrow_forwardWhat is the standard practice for spelling out named constants in code?arrow_forward
- In physics, an object that is in motion is said to have kinetic energy. The following formula can be used to determine a moving object's kinetic energy: KE = ½ m v2 The variables in the formula are as follows: KE is the kinetic energy, m is the object's mass in kilograms, and v is the object's velocity, in meters per second. Write a function named kineticEnergy that accepts an object's mass (in kilograms) and velocity (in meters per second) as arguments. The function should return the amount of kinetic energy that the object has. Demonstrate the function by calling it in a program that asks the user to enter values for mass and velocity.arrow_forwardWritten in Carrow_forwardChoose the best data type for each of the following, so that no memory storage is wasted. Give an example of a typical value that would be held by the variable, and explain why you chose the type you did. the number of years of school you have completed your final grade in this class the population of China the number of passengers on an airline flight one players score in a Scrabble game the number of Electoral College votes received by a U.S. presidential candidate the number of days with below freezing temperatures in a winter in Miami, Florida one teams score in a Major League Baseball gamearrow_forward
- The following variable is ✔ .newUnits legal but not by convention not legal legal and by conventionarrow_forwardIn Python Text-based adventure game: Pretend you are creating a text-based adventure game. At different points in the game, you want the user to select to fight, run, or hide from certain enemies. The selection variable must be sent as an argument into the choice() function. The user should enter 1 to fight, 2 to run, or 3 to hide in the main(). The choice() function should print one of the three options. Add an if statement in the choice() function to make the correct selection.arrow_forwardThe following formula can be used to determine the distance an object falls due to gravity in a specific time period: d = 1⁄2 gt2The variables in the formula are as follows: d is the distance in meters, g is 9.8, and t is the time in seconds that the object has been falling. Write a function named fallingDistance that accepts an object’s falling time (in seconds) as an argument. The function should return the distance, in meters, that the object has fallen during that time interval. Write a program that demonstrates the function by calling it in a loop that passes the values 1 through 10 as arguments and displays the return value.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning