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
What are the major threats of using the internet? How do you use it? How do children use it? How canwe secure it? Provide four references with your answer. Two of the refernces can be from an article and the other two from websites.
Assume that a string of name & surname is saved in S. The alphabetical characters in S can be in lowercase and/or uppercase letters. Name and surname are assumed to be separated by a space character and the string ends with a full stop "." character. Write an assembly language program that will copy the name to NAME in lowercase and the surname to SNAME in uppercase letters. Assume that name and/or surname cannot exceed 20 characters. The program should be general and work with every possible string with name & surname. However, you can consider the data segment definition given below in your program. .DATA S DB 'Mahmoud Obaid." NAME DB 20 DUP(?) SNAME DB 20 DUP(?) Hint: Uppercase characters are ordered between 'A' (41H) and 'Z' (5AH) and lowercase characters are ordered between 'a' (61H) and 'z' (7AH) in the in the ASCII Code table. For lowercase letters, bit 5 (d5) of the ASCII code is 1 where for uppercase letters it is 0. For example, Letter 'h' Binary ASCII 01101000 68H 'H'…
What did you find most interesting or surprising about the scientist Lavoiser?

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
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
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