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
In various applications, you are often asked to compute the mean and standard deviation of data. The mean is simply the average of the numbers. The standard deviation is a statistic that tells you how tightly all the various data are clustered around the mean in a set of data. For example, what is the average age of the students in a class? How close are the ages? If all the students are the same age, the deviation is 0. Write a program that prompts the user to enter any number of values into a double array, and then calculates and displays the mean and standard deviations of these numbers using the following formulas: (z - mean) z+z3+ *** +zn deviation = mean = n-1 Required Methods You must write your program so that the following methods are defined/implemented and used (called): • /* Compute the deviation of double values */ public static double deviation (double[] x) • /* Compute the mean of an array of double values */ public static double mean (double[] x) Sample Run (user input…
In various applications, you are often asked to compute the mean and standard deviation of data. The mean is simply the average of the numbers. The standard deviation is a statistic that tells you how tightly all the various data are clustered around the mean in a set of data. For example, what is the average age of the students in a class? How close are the ages? If all the students are the same age, the deviation is 0. Write a program that prompts the user to enter any number of values into a double array, and then calculates and displays the mean and standard deviations of these numbers using the following formulas: mean)? 2i +x2 + .. + xn i=1 i=1 mean = deviation = п - 1
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)

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