Absolute C++
Absolute C++
6th Edition
ISBN: 9780133970784
Author: Walter Savitch, Kenrick Mock
Publisher: Addison-Wesley
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
Write a program that calculates the change due a customer by denomination; that is, how many pennies, nickels, dimes, etc. are needed in change. The input is to be the purchase price and the size of the bill tendered by the customer ($100, $50, $20, $10, $5, $1)
Using Paython Write a program that asks a student for his grade (out of 100) in 3 exams and then print out his final grade (out of 100), given that the weight of the first exam is 30%, the second 30%, and the third 40%.Example Input:Exam1: 70Exam2: 80Exam3: 90Example Output:Total Grade = 81Explanation: 0.3 * 70 + 0.3 * 80 + 0.4 * 90 = 81
"Write a program that reads true positives and false positives for each model and prints \"Good model\" and the value of the precision if the precision is above 0.75 or \"Bad model\" and the value of the precision if the precision is below 75. Teste the two models with your program and determine which one (or both) are good or bad models."

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
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
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