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
All circuits need three basic parts: an energy source, wires, and the object that is going to change the electrical energy into
Radda [10]

load every electric circuit,regardless of where it is or how large or small, has four basic parts: an energy source (ac or dc),a conductor (wire), an electrical load (device), and at least one controller(switch)
7 0
3 years ago
Read 2 more answers
List all the qualities of an engineer?
Dennis_Churaev [7]

Answer:

Math and Computer Skills. A qualified engineer should be good at math, at least through the level of calculus and trigonometry, and understand the importance of following the data when making design decisions.

Organization and Attention to Detail.  

Curiosity.  

Creativity.  

Critical Thinking.

Intuition.

Explanation:

6 0
2 years ago
If we have silicon at 300K with 10 microns of p-type doping of 4.48*10^18/cc and 10 microns of n-type doping at 1000 times less
liq [111]

Answer:

The resistance is 24.9 Ω

Explanation:

The resistivity is equal to:

R=\frac{1}{N_{o}*u*V } =\frac{1}{4.48x10^{15}*1500*106x10^{-19}  } =0.93ohm*cm

The area is:

A = 60 * 60 = 3600 um² = 0.36x10⁻⁴cm²

w=\sqrt{\frac{2E(V_{o}-V) }{p}(\frac{1}{N_{A} }+\frac{1}{N_{D} })

If NA is greater, then, the term 1/NA can be neglected, thus the equation:

w=\sqrt{\frac{2E(V_{o}-V) }{p}(\frac{1}{N_{D} })

Where

V = 0.44 V

E = 11.68*8.85x10¹⁴ f/cm

V_{o} =\frac{KT}{p} ln(\frac{N_{A}*N_{D}}{n_{i}^{2}  } , if n_{i}=1.5x10^{10}cm^{-3}  \\V_{o}=0.02585ln(\frac{4.48x10^{18}*4.48x10^{15}  }{(1.5x10^{10})^{2}  } )=0.83V

w=\sqrt{\frac{2*11.68*8.85x10^{-14}*(0.83-0.44) }{1.6x10^{-19}*4.48x10^{15}  } } =3.35x10^{-5} cm=0.335um

The length is:

L = 10 - 0.335 = 9.665 um

The resistance is:

Re=\frac{pL}{A} =\frac{0.93*9.665x10^{-4} }{0.36x10^{-4} } =24.9ohm

7 0
3 years ago
The purpose of pasteurizing milk is to A. Kill pathogens B. Break down milk fat C. Add vitamins and minerals D. Prevent spoilage
motikmotik
Answer: A Kill pathogens
7 0
2 years ago
; How do engineers make a difference in the world and with proof ?​
kumpel [21]
Engineers are the reason healthcare has improved so dramatically throughout the years. The advancements in medical technology are down to the work conducted by engineers as well as the creation of devices that help to save lives and improve the quality of life for others. New developments are being created by engineers constantly, for example, the Crossrail project in London is creating a new transport system throughout the South East to create shorter journey times and easier connections. The existing transport system wouldn’t be where it is today without engineers.
3 0
3 years ago
Read 2 more answers
Other questions:
  • A steady‐flow gas furnace supplies hot air at a rate of 850 cfm and conditions of 120F and 1.00 atm. The air splits into two bra
    14·1 answer
  • (8 points) Consider casting a concrete driveway 40 feet long, 12 feet wide and 6 in. thick. The proportions of the mix by weight
    8·1 answer
  • Name the important trees of tropical monsoon forest​
    11·1 answer
  • What are the equipment requirements for windshields and side windows?
    13·1 answer
  • Give five examples of
    14·1 answer
  • I NEED HELP ASAP WILL AWARD BRAINLIEST
    8·2 answers
  • Which actions would the maintenance and operations crews carry out as a building is completed and preparing to open to the publi
    8·2 answers
  • ¿Cómo llevan a cabo el lavado ropa?​
    8·1 answer
  • Determine the maximum height (in inches) that a lift pump can raise water (0.9971 g/ml) from a well at normal atmospheric pressu
    10·1 answer
  • The use of seatbelts in a car has significantly reduced the number of crash fatalities. Which statement best explains how societ
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!