Question

In: Computer Science

Using C++ If you have 2 plants (A and B) with the hight of plant A...

Using C++

If you have 2 plants (A and B) with the hight of plant A is less than the hight of plant B. However, the hight of plant A is growing faster than the hight of plant B (the hight is measured in centimetres and the hight growth rate is matured daily). Write a program that prompts the user to enter the hight and the hight growth rate of each plant. The program should check that the hight of plant A is less than the hight of plant B and that the growth rate of plant A is higher than the growth rate of plant B and it should not work otherwise. The program outputs after how many days the hight of plant A will be greater than or equal to the hight of plant B, and the hight of both plants at that time.

A sample input and output is as follows:

First Run:

Enter the hight of plan A (in centimetres): 26

Enter the hight growth rate of plant A: 0.04 Enter the hight of plant B: 25

Enter the hight growth rate of plant B: 0.02

Plant A hight should be less than plant B hight and plant A growth rate should be higher than plant B growth rate.

Second Run:

Enter the hight of plan A (in centimetres): 22

Enter the hight growth rate of plant A: 0.04

Enter the hight of plant B: 25

Enter the hight growth rate of plant B: 0.02

The hight of plant A will be greater than or equal to the hight of plant B after 7 days.

Plant A hight will become 28.9505

Plant B hight will become 28.7171

Solutions

Expert Solution

Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.

If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.

Thank You!
===========================================================================

#include<iostream>
#include<iomanip>

using namespace std;

int main(){
  
   double plantAHeight, plantBHeight;
   double plantAGrowth, plantBGrowth;
  
   cout<<"Enter the hight of plan A (in centimetres): ";
   cin >>    plantAHeight;
   cout<<"Enter the hight growth rate of plant A: ";
   cin >> plantAGrowth;
  
   cout<<"Enter the hight of plan B (in centimetres): ";
   cin >>    plantBHeight;
       cout<<"Enter the hight growth rate of plant B: ";
   cin >> plantBGrowth;
  
   if(plantAGrowth<plantBGrowth || plantAHeight>plantBHeight){
       cout<<"Plant A hight should be less than plant B hight and "
           <<"plant A growth rate should be higher than plant B growth rate.";
           return 1;
   }
  
   int day = 0;
   while(plantAHeight<plantBHeight){
       day+=1;
       plantAHeight+= plantAHeight*plantAGrowth;
       plantBHeight+= plantBHeight*plantBGrowth;
   }
  
   cout<<"The hight of plant A will be greater than or equal to the hight of plant B after "
       <<day<<" days.\n";
   cout<<"Plant A hight will become "<<plantAHeight<<endl;
   cout<<"Plant B hight will become "<<plantBHeight<<endl;

   return 0;
}

If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.

Thank You!


Related Solutions

A fashion & textile manufacturer currently has four manufacturing plants (Plant A, B, C, D) and...
A fashion & textile manufacturer currently has four manufacturing plants (Plant A, B, C, D) and two retail outlets (Outlet 1 and 2). Due to expected reduction in demand, the company is considering whether closing some of the plants would be possible. The details of the weekly forecasted demand at outlets, weekly supply at plants, and the unit cost to transport between plants and outlets are shown as follows. Outlet 1 Outlet 2 Supply Fixed Annual Operating Cost Plant A...
1) A book manufacturing company has two different production plants, plant A and plant B. 40%...
1) A book manufacturing company has two different production plants, plant A and plant B. 40% of books come from plant A. Of the books that come from plant A 30% are defective and 70% work as intended. Of the books from plant B 10% are defective and 90% work as intended. On top of this 10% of the defective books from plant A explode. A) Draw a tree diagram of this data. B) What is the probability of randomly...
A manufacturer of automotive gaskets has two plants, A and B. Plant A manufactures 65 %...
A manufacturer of automotive gaskets has two plants, A and B. Plant A manufactures 65 % of the gaskets and plant B manufactures 35 %. Because of a batch of faulty material from a company supplying both plants, 3% of the gaskets are of sub-standard quality from plant A and 5% are sub-standard from plant B. Despite your internal quality control procedures, you still had a sub-standard gasket returned from one of your customers. What is the probability it came...
a+b+c=(abc)^(1/2) show that (a(b+c))^(1/2)+(b(c+a))^(1/2)+(c(a+b))^(1/2)>36
a+b+c=(abc)^(1/2) show that (a(b+c))^(1/2)+(b(c+a))^(1/2)+(c(a+b))^(1/2)>36
Amazon ltd produces three products; A, B, C and D using the same processing plant. The...
Amazon ltd produces three products; A, B, C and D using the same processing plant. The following information relates to the company: Product                                  A                     B                     C                     D Units produced                      2,000               20,000             2,400               28,000 Material cost per unit (sh)    20                    20                    64                    68 Labour hours per unit                      2                      2                      8                      6 Machine hours per unit        1                      1                      4                      6 Labour cost per unit (sh)      12                    12                    48                    36 The cost accountant analysed the production overheads recorded under the...
Exercise 2. Two plants A firm has two plants, both with increasing marginal costs. Plant 1...
Exercise 2. Two plants A firm has two plants, both with increasing marginal costs. Plant 1 is more efficient than plant 2. Specifically, the cost function in plant 1 is c1(y1)=2y12, while the cost function in plant 2 is c2(y2)=3y22. Output produced in plant 1, y1, is identical to output produced in plant 2, y2. For any overall output level Y=y1+y2the firm wants to minimize costs. What is the marginal cost in plant 1? Find ∂c1/∂y1. What is the marginal...
1.) Angiosperm are seedless vascular plants (A. True B. False) 2.) Angiosperm are vascular plants that...
1.) Angiosperm are seedless vascular plants (A. True B. False) 2.) Angiosperm are vascular plants that enclose seeds within the ovary (A. True B. False) 3.)  Translation process in the eukaryotes takes place in the nucleus (A. True B. False)
Scenario #2: Bob's plant shop was trying to determine what was causing leaves on plants in...
Scenario #2: Bob's plant shop was trying to determine what was causing leaves on plants in their shop to change color related to temperature. What would be a design to study leaf color change related to temperature? Scenario #3: Jim was trying to determine which gasoline he uses in his car gets him the best mileage. He use four gasolines: Exxon, Shell, BP and Mobil. What design could be used with this design? 1. Write a "Hypothesis" for each of...
The genes for A, B, C and E assort independently. If a plant with the genotype...
The genes for A, B, C and E assort independently. If a plant with the genotype AaBBCcEe is crossed with plant with genotype aaBbccEe, what is the probability of progeny having the genotype aaBbCcee?
The genes for A, B, C and E assort independently. If a plant with the genotype...
The genes for A, B, C and E assort independently. If a plant with the genotype AaBBCcEe is crossed with a plant with the genotype aaBbccEe, what is the probability of progeny having the genotype aaBbCcee?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT