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
Consider a very long, slender rod. One end of the rod is attached to a base surface maintained at Tb, while the surface of the r
9966 [12]

Answer:

(a) Calculate the rod base temperature (°C). = 299.86°C

(b) Determine the rod length (mm) for the case where the ratio of the heat transfer from a finite length fin to the heat transfer from a very long fin under the same conditions is 99 percent.  = 0.4325m

Explanation:

see attached file below

3 0
3 years ago
The diameter of an extruder barrel = 85 mm and its length = 2.00 m. The screw rotates at 55 rev/min, its channel depth = 8.0 mm,
babunello [35]

Answer:

Qx = 9.109.10^5 \times 10^{-6} m³/s  

Explanation:

given data

diameter = 85 mm

length = 2 m

depth = 9mm

N = 60 rev/min

pressure p = 11 × 10^6 Pa

viscosity n = 100 Pas

angle = 18°

so  Qd will be

Qd = 0.5 × π² ×D²×dc × sinA × cosA   ..............1

put here value and we get

Qd = 0.5 × π² × ( 85 \times 10^{-3} )²× 9  \times 10^{-3}  × sin18 × cos18

Qd = 94.305 × 10^{-6} m³/s

and

Qb = p × π × D × dc³ × sin²A ÷  12  × n × L    ............2

Qb = 11 × 10^{6} × π × 85 \times 10^{-3}  × ( 9  \times 10^{-3} )³ × sin²18 ÷  12  × 100 × 2

Qb = 85.2 × 10^{-6} m³/s

so here

volume flow rate Qx = Qd - Qb   ..............3

Qx =  94.305 × 10^{-6}  - 85.2 × 10^{-6}  

Qx = 9.109.10^5 \times 10^{-6} m³/s  

8 0
3 years ago
1: asha started abusness with 30.000
svetoff [14.1K]

Answer:

Explanation:adrive with visual acutity of 20/30 can just decipher asing adistance 20ft from asing determine the maximum destance from the sing which drivers with the flowing visual acuities will able to see the same sing 20/15 20/50

4 0
3 years ago
Consider the expansion of a gas at a constant temperature in a water-cooled piston-cylinder system. The constant temperature is
Leona [35]

Answer:

Q_{in} = W_{out} = nRT ln (\frac{V_{2}}{V_{1}})

Explanation:

According to the first thermodynamic law, the energy must be conserved so:

dQ = dU - dW

Where Q is the heat transmitted to the system, U is the internal energy and W is the work done by the system.

This equation can be solved by integration between an initial and a final state:

(1) \int\limits^1_2 {} \, dQ = \int\limits^1_2 {} \, dU - \int\limits^1_2 {} \, dW

As per work definition:

dW = F*dr

For pressure the force F equials the pressure multiplied by the area of the piston, and considering dx as the displacement:

dW = PA*dx

Here A*dx equals the differential volume of the piston, and considering that any increment in volume is a work done by the system, the sign is negative, so:

dW = - P*dV

So the third integral in equation (1) is:

\int\limits^1_2 {- P} \, dV

Considering the gas as ideal, the pressure can be calculated as P = \frac{n*R*T}{V}, so:

\int\limits^1_2 {- P} \, dV = \int\limits^1_2 {- \frac{n*R*T}{V}} \, dV

In this particular case as the systems is closed and the temperature constant, n, R and T are constants:

\int\limits^1_2 {- \frac{n*R*T}{V}} \, dV = -nRT \int\limits^1_2 {\frac{1}{V}} \, dV

Replacion this and solving equation (1) between state 1 and 2:

\int\limits^1_2 {} \, dQ = \int\limits^1_2 {} \, dU + nRT \int\limits^1_2 {\frac{1}{V}} \, dV

Q_{2} - Q_{1} = U_{2} - U_{1} + nRT(ln V_{2} - ln V_{1})

Q_{2} - Q_{1} = U_{2} - U_{1} + nRT ln \frac{V_{2}}{V_{1}}

The internal energy depends only on the temperature of the gas, so there is no internal energy change U_{2} - U_{1} = 0, so the heat exchanged to the system equals the work done by the system:

Q_{in} = W_{out} = nRT ln (\frac{V_{2}}{V_{1}})

4 0
4 years ago
Give me some examples of fragile structures.
Anvisha [2.4K]

Answer:

i don't know if this help tell me if i am wrong

Explanation:

Gravity is the force that pulls all elements of matter together. Matter refers to things you can physically touch. The more matter there is, the greater the amount of gravity or force. This means that the Earth or other planets have a great deal of pull and that everything on Earth is pulled back to Earth.

Some examples of the force of gravity include:

The force that holds the gases in the sun.

The force that causes a ball you throw in the air to come down again.

The force that causes a car to coast downhill even when you aren't stepping on the gas.

The force that causes a glass you drop to fall to the floor.

3 0
3 years ago
Other questions:
  • An 80-L vessel contains 4 kg of refrigerant-134a at a pressure of 160kPa. Determine (a) the temperature, (b) the quality, (c) th
    11·1 answer
  • What is the difference between absolute and gage pressure?
    11·1 answer
  • An air-standard Otto cycle has a compression ratio of 6 and the temperature and pressure at the beginning of the compression pro
    13·1 answer
  • Which solution causes cells to shrink
    13·1 answer
  • A(n) _________ is a current greater than the equipment rated current or conductor ampacity, which is confined to the normal cond
    12·1 answer
  • Technician A says if the input signal turn-on time is too fast for the input circuit, your program may operate as though the inp
    11·1 answer
  • What is the IMA of a fixed pulley ​
    7·2 answers
  • A single-phase inductive load draws a 10 MW at 0.6 power factor lagging. Calculate the reactive power of a capacitor to be conne
    14·1 answer
  • Why is it important to follow the engineering design process before building a prototype
    13·1 answer
  • 10. True or False? A disruptive technology<br> radically changes the way people live and<br> work.
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!