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
Select the properties and typical applications for the high carbon steels.
yanalaym [24]

Answer:

<u>Option-(A)</u>

Explanation:

<u>Typical applications for the high carbon steels includes the following;</u>

It is heat treatable, relatively large combinations of mechanical characteristics. Typical applications: railway wheels and tracks, gears, crankshafts, and machine parts.

3 0
3 years ago
Refrigerant-134a enters the expansion valve of a refrigeration system at 120 psia as a saturated liquid and leaves at 20 psia. D
Shkiper50 [21]

Solution :

$P_1 = 120 \ psia$

$P_2 = 20 \ psia$

Using the data table for refrigerant-134a at P = 120 psia

$h_1=h_f=40.8365 \ Btu/lbm$

$u_1=u_f=40.5485 \ Btu/lbm$

$T_{sat}=87.745^\circ  F$

∴ $h_2=h_1=40.8365 \ Btu/lbm$

For pressure, P = 20 psia

$h_{2f} = 11.445 \ Btu/lbm$

$h_{2g} = 102.73 \ Btu/lbm$

$u_{2f} = 11.401 \ Btu/lbm$

$u_{2g} = 94.3 \ Btu/lbm$

$T_2=T_{sat}=-2.43^\circ  F$

Change in temperature, $\Delta T = T_2-T_1$

                                         $\Delta T = -2.43-87.745$

                                           $\Delta T=-90.175^\circ  F$

Now we find the quality,

$h_2=h_f+x_2(h_g-h_f)$

$40.8365=11.445+x_2(91.282)$

$x_2=0.32198$

The final energy,

$u_2=u_f+x_2.u_{fg}$

   $=11.401+0.32198(82.898)$

   $=38.09297 \ Btu/lbm$

Change in internal energy  

$\Delta u= u_2-u_1$

   = 38.09297-40.5485

  = -2.4556        

5 0
2 years ago
The mean of 10 numbers is 9, then the sum (total) of these numbers will be​
qwelly [4]

Answer:

90

Explanation:

mean is basically taking the sum of all numbers and then dividing the sum with the number of all given numbers..

here, the mean is 9, total numbers are 10.. so the sum will be 9 multiplied by 10, that is 90.

5 0
2 years ago
Read 2 more answers
In the circuit given below, R1 = 17 kΩ, R2 = 74 kΩ, and R3 = 5 MΩ. Calculate the gain 1formula58.mml when the switch is in posit
Elenna [48]

Answer:a

a) Vo/Vi = - 3.4

b) Vo/Vi = - 14.8

c) Vo/Vi = - 1000

Explanation:

a)

R1 = 17kΩ

for ideal op-amp

Va≈Vb=0 so Va=0

(Va - Vi)/5kΩ + (Va -Vo)/17kΩ = 0

sin we know Va≈Vb=0

so

-Vi/5kΩ + -Vo/17kΩ = 0

Vo/Vi = - 17k/5k

Vo/Vi = -3.4

║Vo/Vi ║ = 3.4    ( negative sign phase inversion)

b)

R2 = 74kΩ

for ideal op-amp

Va≈Vb=0 so Va=0

so

(Va-Vi)/5kΩ + (Va-Vo)74kΩ = 0

-Vi/5kΩ + -Vo/74kΩ = 0

Vo/Vi = - 74kΩ/5kΩ

Vo/Vi = - 14.8

║Vo/Vi ║ = 14.8  ( negative sign phase inversion)

c)

Also for ideal op-amp

Va≈Vb=0 so Va=0

Now for position 3 we apply nodal analysis we got at position 1

(Va - Vi)/5kΩ + (Va - Vo)/5000kΩ = 0           ( 5MΩ = 5000kΩ )

so

-Vi/5kΩ + -Vo/5000kΩ = 0

Vo/Vi = - 5000kΩ/5kΩ

Vo/Vi = - 1000

║Vo/Vi ║ = 1000  ( negative sign phase inversion)

3 0
3 years ago
An incandescent light bulb can be regarded as a resistor. If its power output is 100W, calculate the resistance of the light bul
stira [4]

Answer:121\ \Omega

0.909\ A

Explanation:

Given

Power P=100\ W

Voltage applied V=110\ V

Resistance of the bulb is given by

P=\frac{V^2}{R}

100=\frac{110^2}{R}

R=\frac{12100}{100}

R=121\ \Omega

Current drawn by the Power source is given by

P=V\cdot I

I=\frac{P}{V}

I=\frac{100}{110}

I=0.909\ A

8 0
3 years ago
Other questions:
  • Signal generator‘s internal impedance is purely resistive and has an open-circuit voltage of 3.5 V. When the generator is loaded
    11·1 answer
  • A large well-mixed tank of unknown volume, open to the atmosphere initially, contains pure water. The initial height of the solu
    12·1 answer
  • Determine displacement (in) of a 1.37 in diameter steel bar, which is 50 ft long under a force of 27,865 lb if elasticity modulu
    5·1 answer
  • A composite wall is composed of 20 cm of concrete block with k = 0.5 W/m-K and 5 cm of foam insulation with k = 0.03 W/m-K. The
    13·1 answer
  • What gage pressure does a skin diver experience when they dive to 35 ft in the ocean with a water temperature of 55 °F? Report y
    9·1 answer
  • Three consequences of unbalanced wheels on a motor vehicle​
    11·1 answer
  • Difference between theory and practice?​
    10·1 answer
  • Principals of Construction intro
    11·1 answer
  • Which organization would provide business and leadership training to a high school hospitality student?
    6·1 answer
  • when a unit load is secured to a pallet, it is more difficult for pilferage to take place. true false
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!