Chapter 4: Problem 22
include
Short Answer
Step by step solution
Key Concepts
These are the key concepts you need to understand to accurately answer the question.
Chapter 4: Problem 22
include
These are the key concepts you need to understand to accurately answer the question.
All the tools & learning materials you need for study success - in one app.
Get started for free\((\text { Multiples of } 2\) with an Infinite Loop) Write a program that prints the powers of the integer \(2,\) namely \(2,4,8,16,32,64,\) etc. Your while loop should not terminate (i.e., you should create an infinite loop). To do this, simply use the keyword true as the expression for the while statement. What happens when you run this program?
(Checkerboard Pattern of Asterisks) Write a program that displays the following checkerboard pattern. Your program must use only three output statements, one of each of the following forms: cout << "* "; cout << ' '; cout << endl;
\(4.26 \quad\) forward. For example, each of the following five-digit integers is a palindrome: 12321,55555 45554 and \(11611 .\) Write a program that reads in a five-digit integer and determines whether it's a palindrome. [Hint: Use the division and modulus operators to separate the number into its individual digits.
Perform each of these steps: a) Read the problem statement. b) Formulate the algorithm using pseudocode and top-down, stepwise refinement. c) Write a \(\mathrm{C}_{++}\) program. d) Test, debug and execute the \(\mathrm{C}_{++}\) program. (Credit Limits) Develop a \(\mathrm{C}++\) program that will determine whether a department-store customer has exceeded the credit limit on a charge account. For each customer, the following facts are available: a) Account number (an integer) b) Balance at the beginning of the month c) Total of all items charged by this customer this month d) Total of all credits applied to this customer's account this month e) Allowed credit limit The program should use a while statement to input each of these facts, calculate the new balance \((=\text { beginning balance }+\text { charges }-\) credits ) and determine whether the new balance exceeds the customer's credit limit. For those customers whose credit limit is exceeded, the program should display the customer's account number, credit limit, new balance and the message "Credit limit Exceeded."
(Factorial) The factorial of a nonnegative integer \(n\) is written \(n !\) (pronounced "n factorial") and is defined as follows: \(n !=n \cdot(n-1) \cdot(n-2) \cdot \ldots \cdot 1 \quad(\text { for values of } n \text { greater than } 1)\) and \\[ n !=1 \quad(\text { for } n=0 \text { or } n=1) \\] For example, \(5 !=5 \cdot 4 \cdot 3 \cdot 2 \cdot 1,\) which is \(120 .\) Use while statements in each of the following: a) Write a program that reads a nonnegative integer and computes and prints its factorial. b) Write a program that estimates the value of the mathematical constant \(e\) by using the formula: \\[ e=1+\frac{1}{1 !}+\frac{1}{2 !}+\frac{1}{3 !}+\ldots \\] Prompt the user for the desired accuracy of \(e\) (i.e., the number of terms in the summation) c) Write a program that computes the value of \(e^{x}\) by using the formula \\[ e^{x}=1+\frac{x}{1 !}+\frac{x^{2}}{2 !}+\frac{x^{3}}{3 !}+\ldots \\] Prompt the user for the desired accuracy of \(e\) (i.e., the number of terms in the summation).
What do you think about this solution?
We value your feedback to improve our textbook solutions.