C++ :: Program To Predict Size Of Population Of Organisms
Feb 22, 2015
Write a program that will predict the size of a population of organisms. The program should ask the user for the starting number of organisms, their average daily population increase (as a percentage), and the number of days they will multiply. A loop should display the size of the population for each day.
Input Validation: Do not accept a number less than 2 for the starting size of the population. Do not accept a negative number for average daily population increase. Do not accept a number less than 1 for the number of days they will multiply.
My code works fine just up until the end.
#include <iostream>
using namespace std;
int main() {
int organisms = 0, growthRate, rate, days, amount = 0;
//int x; //for loop
I'm new to C++ and am trying to create a program to solve the problem as described in this image: [URL] .....
Here's my code. It fails to execute the main part of the problem (years, population of A & B) but works well in recognizing errors (if PopA >PopB or if growth rate of PopA<PopB)
Code: #include <iostream> #include <iomanip> #include <string> using namespace std; int main() { string city1, city2;
In a cartesian coordinate system, I want to be able to predict a compass angle of an object. So I have a base position of (0,0) and then a distance and compass angle to an object. This object also has a heading and a speed. How can I predict the new compass angle of the object with that information?
my coordinate system is like this:
Code: 0 y | | 270-------------- 90 x | | 180
I think the first step would be to compute the cartesian coordinates of the object:
float degs_to_rads = 3.141592653589793 / 180.0; x = distance * sin(angle*degs_to_rads); y = distance * cos(angle*degs_to_rads);
then the next step would be to compute the predicted x and y from the speed and heading of the object:
predictedx = ?? predictedy = ??
then finally convert back to an angle, and distance:
I'm supposed to store the value of a countrys population. Then gather out the percentage that countrys population holds when compared with the global population.
Anyway here's the code:
Code: #include <iostream> long swe_pop = 9644864; int main ()
[Code] .....
The result I'm getting is 0%.
I was under the impression that long (or long long) integers could hold high values. And that I could then divide these and answer with a float type value. Giving space for the decimals.
I'm trying to analyze Population Dynamics. I found some articles and read them but what kind of model i need to use. I tried Forest Fire model but i failed in modificating.
I'm having trouble figuring out how to find the size of an array program that involves "struct."
#include <iostream> using namespace std; struct d{ char* a; float b; int c;
[code].....
When I run this program, the output is 80(for my compiler). That would mean that each element in the array is 16 bytes but I don't understand how struct d is 16 bytes.
how we will increase the size of an arry during program execution. eg if the size of an array is 40 and during prog exexution we want to increase the size of an arry ,what is the procedure.
I am new to C. I've been trying to use C to code some statistical functions originally coded in R. I've encountered an interesting phenomenon. In the function foo1, I declared the array v1v2b using an actual value 1999000. The function runs fine when I call it in R.
Code: void foo1(double *x, double *y, int *nsamp){ int i, j, k, oper=2, l; double* v1v2=malloc(sizeof(double)*((*nsamp)*(*nsamp-1)/2 + 1)); outer_pos(x, y, nsamp, &v1v2[0]); double v1v2b[1999000]; //<-------HERE for(i=1; i<= 1999000]; i++){ v1v2b[i-1]=1; } }
However, in foo2, I first create an integer variable called index, and store the value 1999000 in it. I then use it to initialize the same array. When I tried calling this function in R, it either led to a stack overflow error, or completely crashed R.
Code: void foo2(double *x, double *y, int *nsamp){ int i, j, k, oper=2, l; double* v1v2=malloc(sizeof(double)*((*nsamp)*(*nsamp-1)/2 + 1));
Working on an assignment and I've hit TWO stumbling blocks. I now have to take the first line from a .txt file and use that number to determine the size of rows to create in my program. I am using fscanf but the program hangs. How can I read in this number, store it and use it in a for loop?
The second issue is after reading this number I have to print each number in the .txt file under a different column. (Note that it skips a line after reading the row count.) The .txt file is set up as follows:
I have a program which call only one time malloc at the start of the program. When running, I see with 'process-explorer.exe' that memory is growing in little steps. Is this normal? why?
comparing with screen size the height is bigger but lenght is smaller. I don't understand.
I can understand that different printers process the fonts in different way and then to have different lenghts. That's not the problem. The problem is I need to simulate in screen the same behaviour i will have on printer because these texts are being aligned in the document, and I don't want to see that the text si aligned different in text than in paper.
What can I do to render the text on screen with the same size I will have on the printer? Print preview is doing it. Should I change the font parameters? is something related with pixels per inch?
I was wondering why, in C, the sizeof of a struct is larger than the the sum of all the sizeofs of it's members. It only seems to be by a few bytes, but as a bit of a perfectionist I fine this a bit annoying.
I've been looking into the file structure of BMP images and everything I'm reading says that the 4 bytes following the signature are designated as the filesize of the bmp file... It's always zero for me regardless of the BMP file. The signature is always correct though.
I'm trying to put all of the words in a text document into an array but this text document is 2,138 kb, and when my program is crashing when I try to put it into an string array. Could the file be too big to put into the array?
The problem is with that a. What is it, a pointer? What's the difference between the a in the main function and the a in the function?
#include <iostream> #include "Header.h" using namespace std; short int capacity(int* a) { int capacity;
[Code] ....
The function it returns i think the size of the pointer instead of returning the size of my array. I don't think i fully understood pointer arithmetic.
int numbers[] = {8, 2, 0, 4, 100, 5}; for(int i = 0; i < sizeof(numbers); i++){ cout << numbers[i] << endl; }
However the results in the console is: 8 2 0 4 ,What am I doing wrong? Am I using the wrong built in function or something? I googled this and one of the links that came up stated to just do something like
arrayName.size()
but that didnt work for me either...
[URL]
Also, I know that I just enter the size of the list manually, in this case make i < 6 but I still want to know if there is a built in function or something.
After looking online for a string replace function in C and finding so many examples that go through the entire string twice. First round to find how number of occurances of substitute in string, using that to malloc for a new string to include additional space for replace, then going through the search string again to get all but what's to be substituted out. I feel it's kind of silly to go through the string twice. Therefore, I'm trying to implement my own string replace, that only searches through the string for what's to be substituted, once.
Here is the same code, but with execution + some syntax highlighting: Ideone.com | Online C Compiler & Debugging Tool..It works great, until it gets to grabbing whatever remains in the search string after the last found sub. The realloc throws a runtime error:
Aborted From my understanding, this is from me going outside of the bounds of the heap and using memory I haven't allocated, or using a free'd pointer. I'm not seeing where either of these are happening in my code, and was wondering what the best way to go about figuring out where the error exactly occurs.