1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
yarga [219]
3 years ago
7

C++ - Green Crud Fibonacci programThe following program is to be written with a loop. You are to write this program three times

and each time with a different loop control structure (for loop, while and do-while).The Fibonacci numbers Fn are define as follows. F0 is 1, F1 is 1, and Fi+2 = Fi + Fi+1 for i = 0, 1, 2, 3, ... In other words, each number is the sum of the previous two integer numbers. The first few Fibonacci numbers are 1, 1, 2, 3, 5, and 8. One place that these numbers occur is as certain population growth rates. If a population has no deaths, then the series shows the size of the population after each time period. It takes an organism two time periods to mature to reproducing age, and then the organism reproduces once every time period (thus the reason for two 1's before you start adding). The formula applies most straightforwardly to a sexual reproduction at a rate of one offspring per time period.Assume that the green crud population grows at this rate and has a time period of 10 days. Hence, if a green crud population starts out as 5 pounds of crud, then in 10 days there is still 5 pounds of crud; at the end of the next 10 days there is 10 pounds of crud; in 20 days 10 pounds (the sum of the previous two 10 day periods). Write a program that takes both the initial size of green crud population (in pounds) and a number of days as input, and output the number of pounds of green crud after that many days of growth. Assume that the population size is the same for 9 days and then increases every tenth day.Input to the crud program: start with 5 pounds of green crude and display the how much crude we have after 200 days. Run each of the three versions of the program with 200 days. You can NOT use arrays for this program.Now, what happens when you run the program for 225 days when you use the simple data type ‘int’? (Not long int or double ect.)
Engineering
1 answer:
Fynjy0 [20]3 years ago
7 0

Answer:

Below is the required code:

Explanation:

Using for loop

#include <iostream>

using namespace std;

int main()

{

    //Initial crud size

    int init = 0;

    int newCrud;

    int next=0;

    //Number of days to simulate

    int no_days;

    int day;

    cout << "Enter initial amount of green crud: ";

    cin >> newCrud;

    cout << "Enter number of days to simulate: ";

    cin >> no_days;

    for (day = 10; day<=no_days; day++)

    {

         if (day % 10 == 0)

         {

             next = newCrud + init;

         }

             newCrud = init;

             init = next;

    }

    if (no_days < 5)

    cout << "\nCrud reproduce only after 5 days minimum.Hence the current amount is "

    << newCrud << " pounds.";

    else

    cout << "On day " << no_days << " you have " << init

    << " pounds of green crud." << endl;

    cout << "\nWould you like to continue? (y or n): ";

    cin >> ans;

         return 0;

}

Output:

         Enter initial amount of green crud: 5

         Enter number of days to simulate: 220

    On day 220 you have 10485760 pounds of green crud.

Using while loop

Program:

#include <iostream>

using namespace std;

int main()

{

    char ans='y';

    while (ans == 'Y' || ans == 'y')

    {

         //Initial crud size

         int init = 0;

         int newCrud;

         int next=0;

         //Number of days to simulate

         int no_days;

         int day;

         cout << "Enter initial amount of green crud:

         ";

         cin >> newCrud;

         cout << "Enter number of days to simulate:

         ";

         cin >> no_days;

         for (day = 10; day<=no_days; day++)

         {

             if (day % 10 == 0)

             {

                  next = newCrud + init;

             }

                  newCrud = init;

                  init = next;

         }

         if (no_days < 5)

         cout << "\nCrud reproduce only after 5 days

         minimum.Hence the current amount is "

         << newCrud << " pounds.";

         else

         cout << "On day " << no_days << " you have "

         << init

         << " pounds of green crud." << endl;

         cout << "\nWould you like to continue? (y or

         n): ";

         cin >> ans;

    }

    return 0;

}

Output:

Enter initial amount of green crud: 5

Enter number of days to simulate: 220

On day 220 you have 10485760 pounds of green crud.

Would you like to continue? (y or n): y

Enter initial amount of green crud: 5

Enter number of days to simulate: 225

On day 225 you have 10485760 pounds of green crud.

Using do while loop

Program:

#include <iostream>

using namespace std;

int main()

{

    char ans;

    do

    {

         //Initial crud size

         int init = 0;

         int newCrud;

         int next=0;

         //Number of days to simulate

         int no_days;

         int day;

         cout << "Enter initial amount of green crud: ";

         cin >> newCrud;

         cout << "Enter number of days to simulate: ";

         cin >> no_days;

         for (day = 10; day<=no_days; day++)

         {

             if (day % 10 == 0)

             {

                  next = newCrud + init;

             }

                  newCrud = init;

                  init = next;

         }

         if (no_days < 5)

         cout << "\nCrud reproduce only after 5 days

         minimum.Hence the current amount is "

         << newCrud << " pounds.";

         else

         

         cout << "On day " << no_days << " you have " <<

         init << " pounds of green crud." << endl;

         cout << "\nWould you like to continue? (y or n):

         ";

         cin >> ans;

    } while (ans == 'Y' || ans == 'y');

    return 0;

}

Output:

Enter initial amount of green crud: 5

Enter number of days to simulate: 220

On day 220 you have 10485760 pounds of green crud.

Would you like to continue? (y or n): y

Enter initial amount of green crud: 5

Enter number of days to simulate: 225

On day 225 you have 10485760 pounds of green crud.

You might be interested in
A gas stream contains 4.0 mol % NH3 and its ammonia content is reduced to 0.5 mol % in a packed absorption tower at 293 K and 10
bagirrra123 [75]

Answer:

Explanation:

Step by step solved solution is given in the attached document.

8 0
3 years ago
Your local hospital is considering the following solution options to address the issues of congestion and equipment failures at
kiruha [24]
Jsjhjrhwjdbwjwjrueiworuuwud
4 0
2 years ago
Steam enters a steady-flow adiabatic nozzle with a low inlet velocity (assume ~0 m/s) as a saturated vapor at 6 MPa and expands
Sergio [31]
Yea bro I don’t really know
7 0
3 years ago
A structural component in the form of a wide plate is to be fabricated from a steel alloy that has a plane-strain fracture tough
jeyben [28]

Complete question:

A structural component in the form of a wide plate is to be fabricated from a steel alloy that has a plane strain fracture toughness of 98.9 MPa root m (90 ksi root in.) and a yield strength of 860 MPa (125,000 psi). The flaw size resolution limit of the flaw detection apparatus is 3.0 mm (0.12 in.). If the design stress is one-half of the yield strength and the value of Y is 1.0, determine whether or not a critical flaw for this plate is subject to detection.

Answer:

Since the flaw 17mm is greater than 3 mm the critical flaw for this plate is subject to detection

so that critical flow is subject to detection  

Explanation:

We are given:

Plane strain fracture toughness K = 98.9 MPa \sqrt{m}

Yield strength Y = 860 MPa

Flaw detection apparatus = 3.0mm (12in)

y = 1.0

Let's use the expression:

oc = \frac{K}{Y \sqrt{pi * a}}

We already know

K= design

a = length of surface creak

Since we are to find the length of surface creak, we will make "a" subject of the formula in the expression above.

Therefore

a= \frac{1}{pi} * [\frac{k}{y*a}]^2

Substituting figures in the expression above, we have:

= \frac{1}{pi} * [\frac{98.9 MPa \sqrt{m}} {10 * \frac{860MPa}{2}}]^2

= 0.0168 m

= 17mm

Therefore, since the flaw 17mm > 3 mm the critical flow is subject to detection  

3 0
3 years ago
Read 2 more answers
Discuss 7 habits of highly effective people and how important are ethics in today's society​
kompoz [17]

Answer:

Explanation:

The 7 Habits of Highly Effective People, is a book written and first published in 1989. It is a business and self-help book that was written by Stephen Covey. The seven habits include

Being proactive

Starting anything with the end in mind

First things first

Always thinking towards a win-win situation

Seeking initially to understand, then going on to want to be understood

Synergize, and lastly

Growing

7 0
3 years ago
Other questions:
  • 2.11 Consider a 400 mm × 400 mm window in an aircraft. For a temperature difference of 90°C from the inner to the outer surface
    13·1 answer
  • What is 29*69+98-78/36=
    9·2 answers
  • A car is traveling at 36 km/h on an acceleration lane to a freeway. What acceleration is required to obtain a speed of 72 km/h i
    12·1 answer
  • Consider a step pn junction made of GaAs at T = 300 K. At zero bias, only 20% of the total depletion region width is in the p-si
    11·1 answer
  • HI! If you love the art that is good. My teacher Mrs. Armstrong is the best paintings ever year. Come to Mountain View Elementar
    10·2 answers
  • Would be much appreciated if someone could help with this will give brainiest.
    6·1 answer
  • 1. In a series circuit the sum of all voltage drops produced by the loads in the circuit
    7·1 answer
  • Mention verious medium level and higher level human resources related to engineering​
    6·1 answer
  • An engine jack is used to lift a 265-lb engine 6'. How much work, in ft-lb, is performed?
    11·1 answer
  • How wold you classify the earliest examples of S.T.E.M discoveries provided in this lesson?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!