ABSOLUTE C++ -TEXT
ABSOLUTE C++ -TEXT
6th Edition
ISBN: 2810017515514
Author: SAVITCH
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 2, Problem 1PP

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 program to gauge the expected cost of an item in a specified number of years. The program asks for the cost of the item, the number of years from now that the item will be purchased, and the rate of inflation. The program then outputs the estimated cost of the item after the specified period. Have the user enter the inflation rate as a percentage, such as 5.6 (percent). Your program should then convert the percentage to a decimal fraction, such as 0.056, and should use a loop to estimate the price adjusted for inflation. (Hint: Use a loop.)

Expert Solution & Answer
Check Mark
Program Plan Intro

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?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
04:24
Students have asked these similar questions
Imagine you are working for a lumber company, and your employer would like a program that calculates the cost of lumber for a customer order. The company sells pine, fir, cedar, maple, and oak lumber. The 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: Pine 0.89 Fir 1.09 Cedar 2.26 Maple 4.50 Oak 3.10 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).   Create a blank c++ Give the customer instructions and then ask the user (customer) to identify the items they wish to purchase by inputting the type of wood, the length, width, & heights of the board, and the number of boards they desire. Allow the user to…
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 last
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.

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Constants, Variables, Data types, Keywords in C Programming Language Tutorial; Author: LearningLad;https://www.youtube.com/watch?v=d7tdL-ZEWdE;License: Standard YouTube License, CC-BY