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
Assume that a p+ - n diode is built with an n region width l smaller than a hole diffusion length (l
RSB [31]

Answer: hiiiiii

fff

Explanation:

7 0
3 years ago
Easy POINTS computer genius help me plz
Norma-Jean [14]

Answer:

dedededededede

Explanation:

4 0
3 years ago
2. What is the original length of the rectangular bar if the deformation is 0.005 in with a force of 1000 lbs and an area of 0.7
Ugo [173]

Answer:

18.75in

Explanation:

Modulus of elasticity = Stress/Strain

Since stress = Force/Area

Given

Force = 1000lb

Area = 0.75sqin

Stress = 1000/0.75

Stress = 1333.33lbsqin

Strain

Strain = Stress/Modulus of elasticity

Strain = 1333.33/5,000,000

Strain = 0.0002667

Also

Strain = extension/original length

extension = 0.005in

Original length = extension/strain

Original length = 0.005/0.0002667

Original length = 18.75in

Hence the original length of the rectangular bar is 18.75in

6 0
3 years ago
¿Qué es la masonería?​
timofeeve [1]

Answer: freemasonry is Being a Mason is about a father helping his son make better decisions; a business leader striving to bring morality to the workplace; a thoughtful man learning to work through tough issues in his life.

Explanation:

3 0
3 years ago
Choose two consumer services careers and research online to determine what kinds of professional organizations exist for these p
Tom [10]

Answer:

Market Researcher

The Marketing Research Association (MRA) is a professional organization for market researchers. It provides information to its members on how to improve marketing research for businesses and individuals. The MRA gives its members important industry news and information through their website. Their code for marketing research standards also protects members from bad actors and improves the public perception of marketing research. The association also has a full time lobbyist representing the market research industry before government officials. The MRA has various membership categories as well. The membership fee differs for each category.  

Credit Analyst

A credit analyst is a person that reviews consumer or business financial profiles in order to give a loan or credit to them. When a business or individual applies for a credit card, loan, trade account, or another type of financial product whereby a company allows them the use of their money, a credit analyst’s job is to ensure that the consumer or business is willing and able to pay it back in the future. Credit analysts use tools such as credit reports, FICO scores, Dun & Bradstreet ratings, financial statement analyses, and personal references to perform their job. A credit analyst should have a bachelor’s degree with a major in business. Finance and economics majors are particularly suited to a credit analyst position. Certifications are not required, but some credit analysts pursue CPA or CFA (Certified Financial Analyst) designations.

Explanation:

5 0
3 years ago
Other questions:
  • What does the following program segment do? Declare Count As Integer Declare Sum As Integer Set Sum = 0 For (Count = 1; Count &l
    15·1 answer
  • ¿Por qué creen que la Ingeniería Metalúrgica es una carrera estratégica para el desarrollo de nuestro país?
    9·1 answer
  • Consider a system with two tasks, Task1 and Task2. Task1 has a period of 200 ms, and Task2 has a period of 300 ms. All tasks ini
    5·1 answer
  • Which definition best fits the idea of electrical resistance in a wire? A. the decrease in current flow due to electrons collidi
    12·1 answer
  • Block D of the mechanism is confined to move within the slot of member CB. Link AD is rotating at a constant rate of ωAD = 6 rad
    11·1 answer
  • A long corridor has a single light bulb and two doors with light switch at each door. design logic circuit for the light; assume
    8·1 answer
  • The natural material in a borrow pit has a mass unit weight of 110.0 pcf and a water content of 6%, and the specific gravity of
    11·1 answer
  • An exit sign must be:Colored in a way that doesn’t attract attentionIlluminated by a reliable light sourceAt least 3 inches tall
    14·1 answer
  • What is the answer???
    10·1 answer
  • A 360 kg/min stream of steam enters a turbine at 40 bar pressure and 100 degrees of superheat. The steam exits the turbine as a
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!