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
Define Plastic vs elastic deformation.
Snowcat [4.5K]

Answer:

Plastic deformation, irreversible or permanent. Deformation mode in which the material does not return to its original shape after removing the applied load. This happens because, in plastic deformation, the material undergoes irreversible thermodynamic changes by acquiring greater elastic potential energy.

Elastic deformation, reversible or non-permanent. the body regains its original shape by removing the force that causes the deformation. In this type of deformation, the solid, by varying its tension state and increasing its internal energy in the form of elastic potential energy, only goes through reversible thermodynamic changes.

3 0
2 years ago
The Stefan-Boltzmann law can be employed to estimate the rate of radiation of energy H from a surface, as in
Mazyrski [523]

Explanation:

A.

H = Aeσ^4

Using the stefan Boltzmann law

When we differentiate

dH/dT = 4AeσT³

dH/dT = 4(0.15)(0.9)(5.67)(10^-8)(650)³

= 8.4085

Exact error = 8.4085x20

= 168.17

H(650) = 0.15(0.9)(5.67)(10^-8)(650)⁴

= 1366.376watts

B.

Verifying values

H(T+ΔT) = 0.15(0.9)(5.67)(10)^-8(670)⁴

= 1542.468

H(T+ΔT) = 0.15(0.9)(5.67)(10^-8)(630)⁴

= 1205.8104

Error = 1542.468-1205.8104/2

= 168.329

ΔT = 40

H(T+ΔT) = 0.15(0.9)(5.67)(10)^-8(690)⁴

= 1735.05

H(T-ΔT) = 0.15(0.9)(5.67)(10^-8)(610)⁴

= 1735.05-1059.83/2

= 675.22/2

= 337.61

5 0
3 years ago
Shortly after the introduction of a new​ coin, newspapers published articles claiming the coin is biased. The stories were based
garik1379 [7]

Answer:

(a) 0.12924

(b) Taking into consideration significance level of 0.05 yet the value of p is greater than 0.05, it suggests that the coin is fair hence the coin can be used at the beginning of any sport event.

Explanation:

(a)

n=200 for fair coin getting head, p= 0.5

Expectation = np =200*0.5=100

Variance = np(1 - p) = 100(1-0.5)=100*0.5=50

Standard deviation, s = \sqrt {variance}=\sqrt {50}= 7.071068

Z value for 108, z =\frac {108-100}{7.071068}= 1.131371

P( x ≥108) = P( z >1.13)= 0.12924

(b)

Taking into consideration significance level of 0.05 yet the value of p is greater than 0.05, it suggests that the coin is fair hence the coin can be used at the beginning of any sport event.

3 0
3 years ago
Metal and dirt are not considered contaminants to oll.<br> A) O True<br> B) O False
Likurg_2 [28]

Answer:

true

Explanation:

6 0
2 years ago
Read 2 more answers
The seers were of the opinion that_____ . *
AURORKA [14]

Answer:

✔️a healthy mind resides in a healthy body.

Explanation:

The seers were of the opinion that "a healthy mind resides in a healthy body."

Just like the English translation of a famous quotation from Thales, pre-Socratic Greek philosopher puts it "a sound mind in a sound body"; which tries to demonstrate the close connections that exists in bodily well-being and one's ability to enjoy life.

The seers were actually of the opinion that a healthy mind resides in a healthy body. It implies that there is connection between the body and the mind. When the body catches an illness, the mind and other parts of the body are affected. When our minds are not healthy, it affects the effective functioning of the body.

So, a healthy mind will definitely be found in a healthy body.

4 0
2 years ago
Other questions:
  • A tendon-operated robotic hand can be implemented using a pneumatic actuator. The actuator can be represented by
    15·1 answer
  • What is the capacity of the machine in batches?
    10·1 answer
  • A 0.4-mm-diameter glass tube is inserted into water at 20∘C in a cup. The surface tension of water at 20∘C is σs=0.073N/m. The c
    9·2 answers
  • The news media often report an earthquake's magnitude on the Richter scale. Which of the following items are characteristics of
    14·1 answer
  • When an output gear is larger than the input gear the greater ratio is greater than 1 T or F​
    9·1 answer
  • What is the difference between a natural and artificial diamond ​
    6·2 answers
  • Select the correct answer.
    8·1 answer
  • A spherical metal ball of radius r_0 is heated in an oven to a temperature of T_1 throughout and is then taken out of the oven a
    6·1 answer
  • Define Ancestor, Descendant, Siblings, Height, Depth, Root and Leaf for the
    9·1 answer
  • True or false for the 4 questions?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!