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
4. Which type of duct undergoes more rigorous testing before it's labeled?
Alenkasestr [34]

Answer:

Flexible duct

Explanation:

it is flexible duct due to current flow

7 0
3 years ago
Who wants fight with me
vladimir1956 [14]
Yea, ‘Who wants to fight with me’
3 0
3 years ago
Ductility (increases/decreases/does not change) with temperature.
PSYCHO15rus [73]

Answer:

Increases

Explanation:

Ductility:

    Ductility is the property of material to go permanent deformation due to tensile load.In other words the ability of material to deform in wire by the help of tensile load.

When temperature is increase then ductility will also increases.And when temperature decreases then the ductility will also decreases.As we know that at very low temperature material become brittle and this is know as ductile brittle transition.

8 0
3 years ago
The heavier an atomic nucleus gets, the less energy the star is able to extract from it through nuclear fusion. When it gets to
Slav-nsk [51]

Answer:

Iron

Explanation:

Once a star starts fusing iron in its core it gives off very large amounts of energy. Also helium, hydrogen, carbon, oxygen, and silicon still exist in the star in different shells while fusin is taking place at different parts of the star. Right at the surface, hydrogen continues to fuse to helium, as e go further down helium is fusing to carbon and oxygen; right inside the core we have silicon that is fusing with iron. At this point, Iron being of stable atomic structure and quite heavier will no longer be fused into anything because of the quite large amounts of energy and force required to fuse iron atoms. The process comes to a standstill at this point.

6 0
3 years ago
Compute the fundamental natural frequency of the transverse vibration of a uniform beam of rectanqular cross section, with one e
marshall27 [118]

Answer:

The natural angular frequency of the rod is 53.56 rad/sec

Explanation:

Since the beam is free at one end and fixed at the other hence the beam is a cantilevered beam as shown in the attached figure

We know that when a unit force is placed at the end of a cantilever the displacement of the free end is given by

\Delta x=\frac{PL^3}{3EI}

Hence we can write

P=\frac{3EI\cdot \Delta x}{L^3}

Comparing with the standard spring equation F=kx we find the cantilever analogous to spring with k=\frac{3EI}{L^3}

Now the angular frequency of a spring is given by

\omega =\sqrt{\frac{k}{m}}

where

'm' is the mass of the load

Thus applying values we get

\omega _{beam}=\sqrt{\frac{\frac{3EI}{L^{3}}}{Area\times density}}

\omega _{beam}=\sqrt{\frac{\frac{3\times 20.5\times 10^{10}\times \frac{0.1\times 0.3^3}{12}}{5.9^{3}}}{0.3\times 0.1 \times 7830}}=53.56rad/sec

8 0
3 years ago
Read 2 more answers
Other questions:
  • Both 1042 steel and 4340 steel are used commercially to make quenched round bars of about the same diameter, such as 1 in. Often
    11·1 answer
  • Definition of permanent, semi permanent and temporary heat setting
    5·1 answer
  • Draw and label a typical true stress-strain curve for a ductile material.
    8·1 answer
  • 8. Air at 25C, 100 kPa and air at 50C, 200 kPa at 1 to 1 volume ratio are mixed inside an adiabatic compressor to 55C, 500 kPa a
    15·1 answer
  • ______________ help protect the lower legs and feet from heat hazards like molten metal and welding sparks. A) Safety shoesB) Le
    7·1 answer
  • View the picture below and then correctly answer the questions using the following words: Temperate Zone, Tropical Zone, Polar Z
    6·2 answers
  • Question 10: What is a K-turn?
    5·1 answer
  • A 4 stroke over-square single cylinder engine with an over square ratio of 1.1,the displacement volume of the engine is 245cc .T
    10·1 answer
  • What are the horizontal structures beneath a slab that help transfer the load from the slab to the columns?
    14·2 answers
  • What part connect to the tie rod that helps the brake chamber out that deals with slack adjuster
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!