Concept explainers
For Exercises 4.13—4.16, perform each of these steps:
a) Read the problem statement.
b) Formulate the
c) Write a C++
d)Test, debug and execute the C++ program.
4.13(Gas Mileage) Drivers are concerned with the mileage obtained by their automobiles. Onedriver has kept track of several trips by recording miles driven and gallons used for each trip. Develop a C++ program that uses a while statement to input the miles driven and gallons used for each trip. The program should calculate and display the miles per gallon obtained for each trip and print the combined miles per gallon obtained for all tankfuls up to this point.
Enter wiles driven (-1 to quit): 287 |
Enter gallons used: 13
MPG this trip: 22.076923
Total MPC: 22.076923
Enter wiles driven (-1 to quit): 200
Enter gallons used: 10
MPC this trip: 20.000000
Total MPC:21.173913
Enter the miles driven (-1 to quit): 120
Enter gallons used: 5
MPC this trip: 24.000000
Total MPC: 21.678571
Enter the miles used (-1 to quit): -1
4.14 (Credit Limit?) Develop a 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:
- Account number (an integer)
- Balance at the beginning of the month
- Total of all items charged by this customer this month
- Total of all credits applied to this customer's account this month
- Allowed credit limit
The program should use a whilestatement to input each of these facts, calculate the new balance (= beginning balance + 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.”
Enter account number (or -1 to quit): 100 Enter beginning balance: 5394.78 Enter total charges: 1000.00 Enter total credits: 500.00 Enter credit limit: 5500.00 New balance is 5894.78 Account: 100 Credit limit: 5500.00 Balance: 5894.78 Credit Limit Exceeded. |
Enter Account Number (or -1 to quit): 200
Enter beginning balance: 1000.00
Enter total charges: 123.45
Enter total credits: 321.00
Enter credit limit: 1500.00
New balance is 802.45
Enter Account Number (or -1 to quit): -1
4.15 (Sales-Commission Calculator) A large company pays its salespeople on a commission basis. The salespeople each receive $200 per week plus 9% of their gross sales for that week. For example, a salesperson who sells $5000 worth of chemicals in a week receives $200 plus 9% of $5000, or a total of $650. Develop a C++ program that uses a while statement to input each salesperson’s gross sales for last week and calculates and displays that salesperson’s earnings. Process one salesperson’s figures at a time.
Enter sales in dollars (-1 to end): 5000.00 |
Salary is: $650.00
Enter sales in dollars (-1 to end): 6000.00
Salary is: $740.00
Enter sales in dollars (-1 to end): 7000.00
Salary is: $830.00
Enter sales in dollars (-1 to end): -1
4.16(Salary Calculator) Develop a C++ program that uses a while statement to determine the gross pay for each of several employees. The company pays “straight time” for the first 40 hours worked by each employee and pays “time-and-a-half’ for all hours worked in excess of 40 hours. You are given a list of the employees of the company, the number of hours each employee worked last week and the hourly rate of each employee. Your program should input this information for each employee and should determine and display the employee’s gross pay.
Enter hours worked (- 1 to end): 39 Enter hourly rate of the employee ($00.00): 10.00 Salary is $390.00 |
Enter hours worked (-1 to end): 40
Enter hourly rate of the employee ($00.00): 10.00
Salary is $400.00
Enter hours worked (-1 to end): 41
Enter hourly rale of the employee ($00.00): 10.00
Salary is $415.00
Enter hours worked (-1 to end): -1
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
C++ How to Program (10th Edition)
Additional Engineering Textbook Solutions
Using MIS (10th Edition)
Java: An Introduction to Problem Solving and Programming (7th Edition)
Concepts of Programming Languages (11th Edition)
C Programming Language
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
- (Conversion) a. Write a C++ program to convert meters to feet. The program should request the starting meter value, the number of conversions to be made, and the increment between metric values. The display should have appropriate headings and list the meters and the corresponding feet value. If the number of iterations is greater than 10, have your program substitute a default increment of 10. Use the relationship that 1 meter = 3.281 feet. b. Run the program written in Exercise 6a on a computer. Verify that your program begins at the correct starting meter value and contains the exact number of conversions specified in your input data. c. Modify the program written in Exercise 6a to request the starting meter value, the ending meter value, and the increment. Instead of the condition checking for a fixed count, the condition checks for the ending meter value. If the number of iterations is greater than 20, have your program substitute a default increment of (ending value - starting value) / 19.arrow_forward15. Write a program to implement and test the algorithm that you designed for Exercise 15 of Chapter 1. (You may assume that the value of . In your program, declare a named constant PI to store this value.)arrow_forward25. Repeat Programming Exercise 24, but the wire is to be bent in the form of a circle. In this case, the user specifies the length of the wire and the program outputs the radius and area of the circle. (You may assume that . Also declare it as a named constant.)arrow_forward
- (Numerical analysis) a. The following is an approximate conversion formula for converting Fahrenheit to Celsius temperatures: Celsius=(Fahrenheit30)/2 Using this formula, and starting with a Fahrenheit temperature of 0 degrees, write a C++ program that determines when the approximate equivalent Celsius temperature differs from the exact equivalent value by more than 4 degrees. (Hint: Use a while loop that terminates when the difference between approximate and exact Celsius equivalents exceeds 4 degrees.) b. Using the approximate Celsius conversion formula given in Exercise 8a, write a C++ program that produces a table of Fahrenheit temperatures, exact Celsius equivalent temperatures, approximate Celsius equivalent temperatures, and the difference between the exact and approximate equivalent Celsius values. The table should begin at 0 degrees Fahrenheit, use 2-degree Fahrenheit increments, and terminate when the difference between exact and approximate values is more than 4 degrees.arrow_forwardHow to fix?arrow_forwardEXERCISE No. 3 (Problem Involving Iteration) Jonathan was given an assignment in his programming course that requires creating an algorithm and flowchart of ten input numbers then displaying its sum. 1. What is required in the problem given? 2. What is/are input item/s? 3. What islare the processing item/s? 4. What is/are the output/s of the problem? ALGORITHM NARRATIVE PSEUDOCODEarrow_forward
- 8 To find out fastest of two cars (if their respective distance travelled and time taken isgiven) should consist of algorithms, flowcharts, program design and code.arrow_forwardUsing loops write a C# program to print the following patternarrow_forwardMACHINE PROBLEM 2 Numerical Methods WRITE A COMPUTER PROGRAM USING ANY LANGUAGE OF YOUR CHOICE THAT WILL IMPLEMENT BAIRSTOWS METHOD FOR FINDING THE ROOTS OF A GIVEN POLYNOMIAL FUNCTION. PROGRAM INPUT - the program should input the following: a) degree of the polynomial function b) coefficients of the polynomial function PROGRAM OUTPUT - the program should consist of the following: a) echo print of the input data b) Bairstow's table for each Quadratic factor Print only · FIRST TABLE • MIDDLE TABLE • FINAL TABLE x² + Ugx + Vk Iteration condition |bn|and | bn-1| < 0.001 TEST DATA: 1. x* – 2x3 + 3x² + 4x + 4 = 0 | 2. x6 – 8x5 + 25x4 – 32x3 – x² + 40x – 25 = 0 3. x8 – x7 – 39xo + 37x5 + 446x* – 180x³ – 1928x² – 256x + 1920 = 0 (answer: -2, -2, -2, 4, 4, 1, 3, -5) 4. x8 – 7x7 – 11x6 + 41x5 – 183x* + 231x3 + 21x² – 265x + 150 = 0 %3Darrow_forward
- Q1. Solve problem using 5-steps of Engineering Problem Solving Methodology (including algorithm) Q2. Draw flowchart diagram Q3. Write c++ program Problem Statement:An election is a formal group decision-making process by which a population chooses a candidate by castingvotes. Each candidate is assigned name and a specific symbol. A ballot paper is used to cast the vote. Eachballot paper contains symbols of the candidate. A person can vote a candidate by stamping on a specific symbol.The ballot paper should be considered as a spoilt ballot if a person does not stamp or stamp on more than onesymbol. Finally ballot paper has to be dropped in a ballot box.Write a C++ program that reads the information from the user to enter the name of the candidate, the totalnumber of received votes, and the spoilt votes in a local election. The total number of participants (candidates)are 5. If the user mistakenly enters any negative value, the program should consider that value as a positiveinteger.…arrow_forwardProblem 2: Multiple stages There are only two rest days in the Tour de France. You will now write a program to calculate the remaining distance before the rest day after each stage. Riders will rest after they finish the fifth stage.Your program will read five distances AS INTEGERS, one for each stage in order. After, you will read the total time of all five days. You will then print how many kilometres are left after each stage and the rider's average speed (in km/h) after all inputed stages, according to the example below.InputYou will read from the use the following (in order):• 5 distances one of each stage• The rider's total time across all stagesOutputEnd of first stage, {distance}km left until rest dayEnd of second stage, {distance}km left until rest dayEnd of third stage, {distance}km left until rest dayEnd of fourth stage, {distance}km left until rest day--REST--Average speed across the five days: {speed} km/hExample:Input Output…arrow_forwardLanguage C++arrow_forward
- C++ 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