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 Visual C# (4th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Introduction To Programming Using Visual Basic (11th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
Artificial Intelligence: A Modern Approach
Database Concepts (7th Edition)
- Write a program that will read an executive's job number, level number, and basic pay and then compute the net salary after withholding income tax. Problem analysis: Gross salary = basic pay + house rent allowance + perks Net salary = Gross salary - income tax. The computation of perks depends on the level, while the income tax depends on the gross salary. The major steps are: 1. Read data. 2. Decide level number and calculate perks. 3. Calculate gross salary. 4. Calculate income tax. 5. Compute net salary. 6. Print the results. Program: A program and the results of the test data are given in statement should be an executable statement. That is, the label stop: cannot be the last line. Fig. 5.15. Note that the lastarrow_forwardThe Research team led by Bernadette Wolowitz at Cal-tech University has discovered a new Amoeba that grows in the order of a Fibonacci series every month. They are exhibiting this amoeba in a national. conference. They want to know the size of the amoeba at a particular time instant. If a particular month's index is given, write a program to display the amoeba's size. For Example, the size of the amoeba on month 1, 2, 3, 4, 5, 6,... will be 0, 1, 1, 2, 3, 5, 8.... respectively.arrow_forwardYour team was asked to program a self-driving car that reaches its destination with minimum travel time. Write an algorithm for this car to choose from two possible road trips. You will calculate the travel time of each trip based on the car current speed and the distance to the target destination. Assume that both distances and car speed are given. Answer:arrow_forward
- An oil slick occurs when an underwater refinery pipe ruptures, pumping oil into the water. The spilled oil sits on top of the water and causes a natural disaster. For simplicity, suppose that the oil sits on top of the water in the form of a circle. Write a program that prompts the user to enter the rate at which the ruptured pipe pumps oil (in gallons) per minute, the thickness of the oil on top of the water, and the number of days for which the area is covered by the spilled oil. The program outputs the spilled area (in kilometer) and the volume of oil (in gallons) on top of the water after each day.arrow_forwardWrite a program to find out the grade of a student based on the marks obtained in three subjects. The grade is calculated as: If average is 80 or greater than 80, grade is ‘A’. If average is less than 80 and greater then 50, grade is ‘B’. If average is less than 50 and greater then 33, grade is ‘C’. If average is less than 33, grade is ‘F’arrow_forwardGiven 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_forward
- write a program in python that asks for the number of credits you have earned to date (may be zero for freshman). Then ask for the number of credits you are taking this semesterarrow_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_forwardA supermarket is doing a sales promotion for soft drinks. If one day you buy soft drinks and bring the empty bottles the next day, they exchange each set of K empty bottles for a full one. A customer wants to make the most of this offer and therefore bought several bottles on the first day of the promotion. Now he wants to know how many bottles he will have at the end of the second day of the promotion if he use it to the fullest. Make a program to calculate this. Input The first input line contains integer T (1 ≤ T ≤ 10000), which indicates the number of test cases. In each of the following T lines come two integers N and K (1 ≤ K, N ≤ 10000), respectively the number of soft drinks bought and the number of empty bottles to gain a full. Output For each test case print the number of bottles that the customer will have on the second day, if he makes the most of the offer.arrow_forward
- Write a program that computes taxes for the following schedule. If your status is Single and if the taxable income is over but not over $0 $8,000 $32,000 If your status is Married and if the taxable income is over $0 $16,000 $64,000 $8,000 $32,000 but not over $16,000 $64,000 the tax is 10% $800 + 15% $4,400 + 25% the tax is 10% $1,600 + 15% $8,800 + 25% of the amount over $0 $8,000 $32,000 of the amount over $0 $16,000 $64,000arrow_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_forwardTeachers in most school districts are paid on a schedule that provides a salary based on their number of years of teaching experience. For example, a beginning teacher in the Lexington School District might be paid $30,000 the first year. For each year of experience after this first year, up to 10 years, the teacher receives a 2% increase over the preceding value. Write a program that displays a salary schedule, in tabular format, for teachers in a school district. The inputs are: 1. Starting salary 2. Annual percentage increase 3. Number of years for which to print the schedule Each row in the schedule should contain the year number and the salary for that year An example of the program input and output is shown below: Enter the starting salary: $30000 Enter the annual % increase: 2 Enter the number of years: 10 Year Salary 1 30000.00 2 30600.00 3 31212.00 4 31836.24 5 32472.96 6 33122.42 7 33784.87 8…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