Please help perform maintenance to this pseudo code so it is written to match th
ID: 3764952 • Letter: P
Question
Please help perform maintenance to this pseudo code so it is written to match the comments behind the //, [chapter 5-01 maintenance] Programming Logic and design Introductory Joyce Farrell
// The QuickCopy company currently makes 60,000 copies per year
// at 15 cents each.
// They expect to increase the number of copies produced
// by 4 percent per year each year for the next 10 years,
// starting with this year.
// They also expect the price of each copy to increase
// by 3 cents per year, starting with this year.
// This program displays the company's expected
// income for each of the next 10 years.
// Modify it to be more efficient.
start
Declarations
num year = 1
num copies = 60000
num price = 0.15
num total = 0
num COPIES_INCREASE = 0.04
num PRICE_INCREASE = 0.03
copies = copies + copies * COPIES_INCREASE
price = price + price * PRICE_INCREASE
total = total + copies * price
output year, total
year = year + 1
copies = copies + copies * COPIES_INCREASE
price = price + price * PRICE_INCREASE
total = total + copies * price
output year, total
year = year + 1
copies = copies + copies * COPIES_INCREASE
price = price + price * PRICE_INCREASE
total = total + copies * price
output year, total
year = year + 1
copies = copies + copies * COPIES_INCREASE
price = price + price * PRICE_INCREASE
total = total + copies * price
output year, total
year = year + 1
copies = copies + copies * COPIES_INCREASE
price = price + price * PRICE_INCREASE
total = total + copies * price
output year, total
year = year + 1
copies = copies + copies * COPIES_INCREASE
price = price + price * PRICE_INCREASE
total = total + copies * price
output year, total
year = year + 1
copies = copies + copies * COPIES_INCREASE
price = price + price * PRICE_INCREASE
total = total + copies * price
output year, total
year = year + 1
copies = copies + copies * COPIES_INCREASE
price = price + price * PRICE_INCREASE
total = total + copies * price
output year, total
year = year + 1
copies = copies + copies * COPIES_INCREASE
price = price + price * PRICE_INCREASE
total = total + copies * price
output year, total
year = year + 1
copies = copies + copies * COPIES_INCREASE
price = price + price * PRICE_INCREASE
total = total + copies * price
output year, total
stop
Explanation / Answer
This below c++ script will optimise the given program logic by using control loop statement
called for..all the four computations logic part is moved to inside for loop so it is reduced
the number of lines of code .. see the below script you can easily understand.
#include <iostream>
using namespace std;
int main()
{
int year = 1, copies = 60000,i = 0,j;
double price = 0.15, total = 0, COPIES_INCREASE = 0.04, PRICE_INCREASE = 0.03;
double price_array[5], total_array[5];
for(year = 1; year <=5; year++)
{
copies = copies + copies * COPIES_INCREASE;
price = price + price * PRICE_INCREASE;
total = total + copies * price;
price_array[i] = price;
total_array[i] = total;
i++;
}
cout<<"Price toatl :"<<endl;
for(i = 0; i<5;i++)
{
cout<<price_array[i]<<" "<<total_array[i]<<endl;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.