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
There are three seating categories at a stadium . For a softball game, Class A seats cost$15, Class B seats cost $12, and Class C seats cost $9. Write a program that asks howmany tickets for each class of seats were sold, then displays the amount of incomegenerated from ticket sales. Format your dollar amount in a fixed-point notation withtwo decimal points and make sure the decimal point is always displayed.
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
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…

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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
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