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
Please help ill mark as brainlest
krek1111 [17]
I would help if It wasn’t so confusing.
4 0
3 years ago
To water his lawn, a homeowner uses two hoses. One connects to the faucet, the other to the end of the first hose to make the ho
Shtirlitz [24]

Answer: to be exact you need 28mm of tubing for that

Explanation:

When the election

8 0
3 years ago
If the load parameters are: Vln=600kV, Il=100A (resistive), calculate the source voltage and current when the line is 50Miles (s
Archy [21]

s 0Miles (short), 150 Miles(medium), and 300 Miles (long).

Explanation:

4 0
3 years ago
A beam has been fixed to the floor by the pin at B and the roller at A as shown in figure 1 below.​
ahrayia [7]
What figure below???
3 0
3 years ago
A 200‑m rigid vessel contains a saturated liquid‑vapor mixture with a vapor quality of 75%. The temperature of the vessel is mai
DerKrebs [107]

Answer:

Given,

Temperature;

T = 393;;K

Convert to Celcius;

T = (393-273) degrees

T = 120°C

Using Table A-4 (Saturated water - Temperature table), at T = 120 C;

vf = 0.001060 m³/kg

vg = 0.89133 m³/kg

Quality is given as;

75% = 0.75

Specific volume is given as;

v = vf + x (vg - vf) = 0.001060 + 0.75(0.89133 _ 0.001060)

v= 0.66876 m³/kg

We know;

v = V/m

0.66876  = 100/m

m = 149.53 kg

6 0
3 years ago
Other questions:
  • 9) A construction company employs 2 sales engineers. Engineer 1 does the work in estimating cost for 70% of jobs bid by the comp
    11·1 answer
  • The button on the _ valve should be held when pressure bleeding the brakes
    8·1 answer
  • A three-phase transformer bank consists of 3 single-phase transformers to handle 400 kVA witha 34.5kV/13.8kV voltage ratio. Find
    7·1 answer
  • What organization which fire codes
    13·2 answers
  • Explain why you chose the final design of your prototype and how it solved the identified need
    9·1 answer
  • Technician A says that in a worm gear steering system, most excessive steering free play is usually found in the gearbox. Techni
    13·1 answer
  • Which of the following technologies will the design and development of a bicycle stand be categorized under?
    15·1 answer
  • What is the name of the type of rocker arm stud that does not require a valve adjustment?
    12·1 answer
  • 3. Aqueous cleaners are
    11·1 answer
  • Can you help me with this task/homework.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!