Concept explainers
It is difficult to make a budget that spans several years, because prices are not stable. If your company needs 200 pencils per year, you cannot simply use this year’s price as the cost of pencils two years from now. Because of inflation the cost is likely to be higher than it is today. Write a
List of variables:
- cost: Store the cost of the product.
- time_in_years: Store the time in years.
- inflation_rate: Store the rate of inflation.
- Inflated_rate: Store the expected cost of the item.
List of functions used:
- cout.setf(): To display the floats with a fixed number of decimals.
- cout.precision(2): Sets this number to be two.
- cin(): To take input from input streams like keyboard, files, etc.
- cout(): To display the output.
Summary Introduction:
Program will use the Main () method to prompt the user to enter the cost, time and inflation rate. The loop will find the expected cost of the given number of years for the given amount.
Program Description:
The purpose of the program is to find the expected cost of an item in a specified number of years.
Explanation of Solution
Program:
Following is the C++ program to find the expected cost of an item in a specified number of years.
/* * Program: The program asks the user to provide the value of the cost of the product, time in years and inflation rate to calculate the expected cost of the product. */ #include <iostream> usingnamespacestd; intmain(){ cout.setf(ios::showpoint); cout.precision(2); cout.setf(ios::fixed); // Variable declaration float cost; cout<<"\nEnter the cost of the product: "; //Variable declaration cin>> cost; // Variable declaration inttime_in_years; cout<<"\nEnter the time in years after which the product is purchased: "; cin>>time_in_years; floatinflation_rate; cout<<"\nEnter the inflation rate: "; cin>>inflation_rate; floatinflated_rate= cost; for(inti=1;i<=time_in_years;i++){ inflated_rate=inflated_rate+((inflation_rate/100)*inflated_rate); } cout<<"\nThe expected cost of the product is: "<<inflated_rate<<endl; return0; }
Explanation:
In the above program, a loop is used to find the expected cost of the product. Then cout() function is used to show the output of the program.
Sample Output:
Following is the sample output for the given program:
Enter the cost of the product: 100 Enter the time in years after which the product is purchased: 2 Enter the inflation rate: 5.6 The expected cost of the product is: 111.51
Want to see more full solutions like this?
Chapter 2 Solutions
Absolute C++
Additional Engineering Textbook Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Problem Solving with C++ (10th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Database Concepts (8th Edition)
Starting Out with Python (4th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
- Given a certain temperature in Fahrenheit and a maximum wind velocity (speed) in Miles Per Hour, calculate and display a series of wind chill factors from a wind velocity of 1 MPH to the maximum wind velocity in a table. The user is allowed to specify a maximum wind velocity of up to 50 MPH.Here are the programming instructions for this project: •You must use coding techniques from only Chapter 1 through Section 5.1 in our textbook. You may not use any other coding techniques from any other sources. • Create a project and class in BlueJ named Project2 • In main(), do the following: -Prompt the user to enter the current temperature and use a Scanner object to store it in a double variable.oCall a method named getVelocity that returns an integer and has a Scanner parameter. This method must use a either a while loop or a do-while loop to prompt the user to enter the maximum wind velocity (speed) and return it. A valid value for the maximum wind velocity is between 2 and 50…arrow_forwardA teacher at Leva Primary School needs to divide her class in different group sizes according to the activity they have to do. This will help her to prepare workstations for each group. For example, for art projects the class has to be divided in groups of 6; for science projects the class has to be divided in groups of 4. She asked you to write a program to determine the number of groups as well as the number of pupils who are left to form a smaller group. There are 56 pupils in the class.The program has the following structure:• Declare three int variables nrPupils, nrGroups, and nrLeft. nrPupils represents the number of pupils in a class, nrGroups represents the number of groups the class is divided into, and nrLeft represents the number of pupils, if any, who are in the remaining smaller group.• Assign the value 56 to nrPupils.• Declare an int variable groupSize that is used by a cin statement to input a value from the keyboard and store the size of the groups the teacher…arrow_forwardYou found an exciting summer job for five weeks. It pays a per hour rate (which will be input to the program), and you will work the same number of hours each week (also input). Suppose that the total tax you pay on your summer job income is 14%. After paying the taxes, you spend 10% of your net (after tax) income to buy new clothes, accessories, and school supplies. After subtracting those items from your budget, you use 25% of the remaining money buy savings bonds. In addition, your parents buy additional savings bonds for you at 50% of the amount that you buy. Write a program that prompts the user to enter the pay rate per hour and the number of hours you will work each week. The program then outputs the following:• Your income before and after taxes for your summer job.• The money you spend on clothes, accessories, and supplies.• The money you spend to buy savings bonds.• The money your parents spend to buy additional savings bonds for you.Your input for this program should be only…arrow_forward
- You are asked to write a program for a company that allows the manager to enter the salaries of 8 employees. The program should then output the number of salaries that are greater than or equal 2000 and the number of salaries that are less than 2000 in a chart style. Your program should be well designed and clear. Sample run Enter Salary for employee 1: 1500 Enter Salary for employee 2: 2200 Enter Salary for employee 3: 1950 Enter Salary for employee 4: 1400 Enter Salary for employee 5: 2600 Enter Salary for employee 6: 2450 Enter Salary for employee 7: 1200 Enter Salary for employee 8: 1230 3 salaries greater than or equal 2000: $$S 5 salaries less than 2000: $$$$Sarrow_forwardYou are working for a lumber company, and your employer would like a program that calculates the cost of lumber for an order. The company sells pine, fir, cedar, maple, and oak lumber. Lumber is priced by board feet. One board foot equals one square foot that is one inch thick. The price per board foot is given in the following table: The lumber is sold in different dimensions (specified in inches of width and height, and feet of length) that need to be converted to board feet. For example, a 2 x 4 x 8 piece is 2 inches wide, 4 inches high, and 8 feet long, and is equivalent to 5.333 board feet (2 * 4 * 8 = 64, which when divided by 12 = 5.333 board feet). An entry from the user will be in the form of a letter and four integer numbers. The integers are the number of pieces, width, height, and length. The letter will be one of P, F, C, M, O (corresponding to the five kinds of wood) or T, meaning total. When the letter is T, there are no integers following it on the line. The program…arrow_forwardthere are three seating categories at a stadium. for a softball game, class A seats are $30, Class B seats are $20 and Class C seats are $15. Write a program that asks how many tickets for each class of seats were sold and then displays the amount of income generated from ticket sales. answer using C++arrow_forward
- Write a program to calculate the total cost of the vehicle by adding basic cost with: i.excise duty(15%)ii.sales taxiii.octroi(5%)iv.road tax(1%) input the basic costarrow_forwardLangauge is C.arrow_forwardAirline companies apply baggage restrictions for their passengers. An airline company has decided to apply a 10kg limitation for passengers' hand luggage and 20kg for their normal baggage. When passengers arrive, they enter their hand and normal luggage weight from the keyboard. If passengers exceed their normal baggage allowance of 10 dollars per gram, they pay 12 dollars per kg. Accordingly, write the program that calculates the baggage price of the airline they will go to according to the baggage values entered by the arriving passenger and keeps this from closing the program for each passenger. Note: If hand and normal baggage allowances are stretched below the maximum value, the payment amount will be considered not negative. An example printout is given on the right. Geri bildirim gönderarrow_forward
- When you borrow money to buy a house, a car, or for some other purpose, you repay the loan by making periodic payments over a certain period of time. Of course, the lending company will charge interest on the loan. Every periodic payment consists of the interest on the loan and the payment toward the principal amount. To be specific, suppose that you borrow $1,000 at an interest rate of 7.2% per year and the payments are monthly. Suppose that your monthly payment is $25. Now, the interest is 7.2% per year and the payments are monthly, so the interest rate per month is 7.2/12 = 0.6%. The first months interest on $1,000 is 1000 0.006 = 6. Because the payment is $25 and the interest for the first month is $6, the payment toward the principal amount is 25 6 = 19. This means after making the first payment, the loan amount is 1,000 19 = 981. For the second payment, the interest is calculated on $981. So the interest for the second month is 981 0.006 = 5.886, that is, approximately $5.89. This implies that the payment toward the principal is 25 5.89 = 19.11 and the remaining balance after the second payment is 981 19.11 = 961.89. This process is repeated until the loan is paid. Write a program that accepts as input the loan amount, the interest rate per year, and the monthly payment. (Enter the interest rate as a percentage. For example, if the interest rate is 7.2% per year, then enter 7.2.) The program then outputs the number of months it would take to repay the loan. (Note that if the monthly payment is less than the first months interest, then after each payment, the loan amount will increase. In this case, the program must warn the borrower that the monthly payment is too low, and with this monthly payment, the loan amount could not be repaid.)arrow_forward(Program) Write a program to simulate the rolling of two dice. If the total of the two dice is 7 or 11, you win; otherwise, you lose. Embellish this program as much as you like with betting, different odds, different combinations for win or lose, stopping play when you have no money left or reach the house limit, displaying the dice, and so forth. (Hint: Calculate the dots showing on each die with theexpressiondots=(int)(6.0randomnumber+1), where random number is between 0 and 1.)arrow_forwardTransient PopulationPopulations are affected by the birth and death rate, as well as the number of people who move in and out each year. The birth rate is the percentage increase of the population due to births and the death rate is the percentage decrease of the population due to deaths. Write a program that displays the size of a population for any number of years. The program should ask for the following data: The starting size of a population P The annual birth rate (as a percentage of the population expressed as a fraction in decimal form)B The annual death rate (as a percentage of the population expressed as a fraction in decimal form)D The average annual number of people who have arrived A The average annual number of people who have moved away M The number of years to display nYears Write a function that calculates the size of the population after a year. To calculate the new population after one year, this function should use the formulaN = P + BP - DP + A - Mwhere N is the…arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr