473,382 Members | 1,329 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Question On homework-- Please Help!!

Hi all, I'm having problem with this assignment. I just started C++ and I just can't get this assignment...if anyone could help me out and give me a code...it would be greatly appreciated. The assignment is due tomorrow...and I'm desperate...please help!


The fibonacci numbers are defined in the following way: The first fibonacci number is 1 and the second fibonacci number is 1. Thereafter, each fibonacci number is the sum of the previous two. For example, if you want to calculate the 5th fibonacci number then generate the sequence 1, 1, 2 (the sum of 1 and 1), 3 (the sum of 1 and 2), and 5 (the sum of 2 and 3). So 5 is the 5th fibonacci number.

Suppose we have an initial population of an invented organism called "green crud". "Green crud" reproduces asexually every five days. Suppose we call one generation equivalent to five days. Initially, it enters the world as a single immature organism incapable of reproducing. After one generation it matures, after the next generation it divides into two "green crud" organisms, one mature and one immature. Again the immature organism needs a generation to mature but the mature organism is ready to divide in the same way.



Problem: Write a C++ program that takes as input an initial population of immature "green crud" and determines the total population of “green crud” after:

1. One month (30 days)

2. Six months (180 days)

3. One year (360 days)



Assume no deaths along the way and assume that once an organism divides its “parent” is no longer around.



Hint: Build a model for a month using paper and pencil. Write down the sequence of the number of organisms after each generation. Notice a pattern in the number of organisms. How is the number of organism in generation i related to the number of organisms in generation i-1 and generation i-2?
Dec 6 '06 #1
3 2852
willakawill
1,646 1GB
Hi. Excellent problem. So what have you completed so far?
Dec 6 '06 #2
This is what I have completed so far...but the program I have come up with only gives me the fibonacci number for the integer that is entered. I can't figure out the formula for the program so that when I put in an initial number of crud, it will give me the total population for 30, six months, and a year. Please help...


#include <iostream.h>
long fibonacci( long );
int main()
{
long result, number;
cout << "Enter the initial number of green crud ";
cin >> number;
result = fibonacci( number );
cout << "The total number of green crud is = "
<< result << endl;
return 0;
}
//Recursive definition of function fibonacci
long fibonacci( long n )
{
if ( n == 0 || n == 1 ) // base case
return n;
else
return fibonacci( n-1 ) + fibonacci( n-2 );
}
Dec 6 '06 #3
Hi. Excellent problem. So what have you completed so far?
his is what I have completed so far...but the program I have come up with only gives me the fibonacci number for the integer that is entered. I can't figure out the formula for the program so that when I put in an initial number of crud, it will give me the total population for 30, six months, and a year. Please help...


#include <iostream.h>
long fibonacci( long );
int main()
{
long result, number;
cout << "Enter the initial number of green crud ";
cin >> number;
result = fibonacci( number );
cout << "The total number of green crud is = "
<< result << endl;
return 0;
}
//Recursive definition of function fibonacci
long fibonacci( long n )
{
if ( n == 0 || n == 1 ) // base case
return n;
else
return fibonacci( n-1 ) + fibonacci( n-2 );
}
Dec 6 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: KellyH | last post by:
Hi, I hope someone can point me in the right direction. I'll get it out of the way: Yes, I am a college student. No, I am not looking for anyone to do my homework, just looking for help. I have...
13
by: Roger | last post by:
Can anyone tell me what is the difference between these two? class nodeType { int data; nodeType *link; }; This is the first one:
1
by: Norm | last post by:
Hi, I've got a VBA Access application, and I want to remove the "Type a question for help" box from the menubar? How can I do this? Thanks, Norm
31
by: mark | last post by:
Hello- i am trying to make the function addbitwise more efficient. the code below takes an array of binary numbers (of size 5) and performs bitwise addition. it looks ugly and it is not elegant...
3
by: Amy | last post by:
Hi, I have 6 If Then Else statements I was supposed to write. I did so but I know that they have to be wrong because they all look the same. Could someone take a look at them and point me in the...
1
by: mastern200 | last post by:
I need some homework help with an assignment due wed. I need to make a program where in this program calculates the average of a set of test scores. The program will ask the user how many scores...
1
by: omid1980 | last post by:
hi I have an examination and i shuld answer this question please help me. Explain the advantages of using XML with a database for ecommerce sites?
5
by: karafire2003 | last post by:
I was wondering if someone can help me with my homework. here's the assignment: a. Write a C program that has a declaration in main() to store the string "What's for lunch?" into an array named...
1
by: itgetsharder | last post by:
Hey, i was wondering if anyone could help me. i have two questions that i cannot complete for a homework assignment: This method should convert its parameter (a string like "3.1415") to the...
2
by: DonE | last post by:
Help me please. I am having problems with my homework assignment. We are to create a product class that hold the item number, the name of the product, the number of units in stock, and the price of...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.