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
An engine has a piston with a surface area of 17.31 in2 and can travel 3.44 inches. What is the potential change in volume, disp
Katena32 [7]

Answer:

$$\begin{align*}

P(Y-X=m | Y > X) &= \sum_{k} P(Y-X=m, X=k | Y > X) \\ &= \sum_{k} P(Y-X=m | X=k, Y > X) P(X=k | Y > X) \\ &= \sum_{k} P(Y-k=m | Y > k) P(X=k | Y > X).\end{split}$$

Explanation:

\eqalign{

 P(Y-X=m\mid Y\gt X)

   &=\sum_kP(Y-X=m,X=k\mid Y\gt X)\cr

   &=\sum_kP(Y-X=m\mid X=k,Y\gt X)\,P(X=k\mid Y>X)\cr

   &=\sum_kP(Y-k=m\mid Y\gt k)\,P(X=k\mid Y\gt X)\cr

}

P(Y-X=m | Y > X) &= \sum_{k} P(Y-X=m, X=k | Y > X) \\ &= \sum_{k} P(Y-X=m | X=k, Y > X) P(X=k | Y > X) \\ &= \sum_{k} P(Y-k=m | Y > k) P(X=k | Y > X).\end{split}$$

5 0
2 years ago
A 0.25" diameter A36 steel rivet connects two 1" wide by .25" thick 6061-T6 Al strips in a single lap shear joint. The shear str
just olya [345]

Answer:

Option B

1025 psi

Explanation:

In a single shear, the shear area is \frac {\pi d^{2}}{4}=\frac {\pi 0.25^{2}}{4}

The shear strength=0.58\sigma_y and in this case \sigma_y=36 000 psi

Shear strength=\frac {Load}{Shear area} hence making load the subject then

Load=Shear area X Shear strength

Load=\frac {\pi 0.25^{2}}{4} \times 0.58\times 36000\approx 1025 psi

3 0
3 years ago
LC3 Programming ProblemUse .BLKW to set up an array of 10 values, starting at memory location x4000, as in lab 4.Now programmati
irga5000 [103]

Answer:

Check the explanation

Explanation:

Code

.ORIG x4000

;load index

LD R1, IND

;increment R1

ADD R1, R1, #1

;store it in ind

ST R1, IND

;Loop to fill the remaining array

TEST LD R1, IND

;load 10

LD R2, NUM

;find tw0\'s complement

NOT R2, R2

ADD R2, R2, #1

;(IND-NUM)

ADD R1, R1, R2

;check (IND-NUM)>=0

BRzp GETELEM

;Get array base

LEA R0, ARRAY

;load index

LD R1, IND

;increment index

ADD R0, R0, R1

;store value in array

STR R1, R0,#0

;increment part

INCR

;Increment index

ADD R1, R1, #1

;store it in index

ST R1, IND

;go to test

BR TEST

;get the 6 in R2

;load base address

GETELEM LEA R0, ARRAY

;Set R1=0

AND R1, R1,#0

;Add R1 with 6

ADD R1, R1, #6

;Get the address

ADD R0, R0, R1

;Load the 6th element into R2

LDR R2, R0,#0

;Display array contents

PRINT

;set R1 = 0

AND R1, R1, #0

;Loop

;Get index

TOP ST R1, IND

;Load num

LD R3,NUM

;Find 2\'s complement

NOT R3, R3

ADD R3, R3,#1

;Find (IND-NUM)

ADD R1, R1,R3

;repeat until (IND-NUM)>=0

BRzp DONE

;load array address

LEA R0, ARRAY

;load index

LD R1, IND

;find address

ADD R3, R0, R1

;load value

LDR R1, R3,#0

;load 0x0030

LD R3, HEX

;convert value to hexadecimal

ADD R0, R1, R3

;display number

OUT

;GEt index

LD R1, IND

;increment index

ADD R1, R1, #1

;go to top

BR TOP

;stop

DONE HALT

;declaring variables

;set limit

NUM .FILL 10

;create array

ARRAY .BLKW 10 #0

;variable for index

IND .FILL 0

;hexadecimal value

HEX .FILL x0030

;stop

.END

7 0
3 years ago
It is desired to produce and aligned carbon fiber-epoxy matrix composite having a longitudinal tensile strength of 800 MPa. Calc
Aloiza [94]

Answer:

A certain vehicle loses 3.5% of its value each year. If the vehicle has an initial value of $11,168, construct a model that represents the value of the vehicle after a certain number of years. Use your model to compute the value of the vehicle at the end of 6 years.

Explanation:

5 0
3 years ago
Paint can shaker mechanisms are common in paint and hardware stores. While they do a good job of mixing the paint, they are also
Ymorist [56]

Answer:

A good design for a portable device to mix paint minimizing the shaking forces and vibrations while still effectively mixing the paint. Is:

The best design is one with centripetal movement. Instead of vertical or horizontal movement. With a container and system of holding structures made of materials that could absorb the vibration effectively.

Explanation:

First of all centripetal movement would be friendlier to our objective as it would not shake the can or the machine itself with disruptive vibrations. Also, we would have to use materials with a good grade of force absorption to eradicate the transmission of the movement to the rest of the structure. Allowing the reduction of the shaking forces while maintaining it effective in the process of mixing.

6 0
3 years ago
Other questions:
  • What are the three main areas of bioengineering?
    11·1 answer
  • Biologists use a sequence of letters A, C, T, and G to model a genome. A gene isa substring of a genome that starts after a trip
    5·1 answer
  • A 55-μF capacitor has energy ω (t) = 10 cos2 377t J and consider a positive v(t). Determine the current through the capacitor.
    12·1 answer
  • A __ insulated panel consists of a layer of insulating foam between two osb or plywood panels
    14·2 answers
  • Air in a 10 ft3 cylinder is initially at a pressure of 10 atm and a temperature of 330 K. The cylinder is to be emptied by openi
    10·2 answers
  • The line touching the circle at a point ....................... is known as ........................... .
    12·1 answer
  • Pls help me with these 3 ez questions.
    8·2 answers
  • A misfire code is a type ____ DTC<br> A) 1 or 2<br> B) a or b<br> C) c or d<br> D l or ll
    15·1 answer
  • To understand the concept of moment of a force and how to calculate it using a scalar formulation.
    9·1 answer
  • An earth fill, when compacted will occupy a net volume of 187,000 cy. The borrow material that will be used to construct this fi
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!