Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that will predict the size of a population of organisms. The pro

ID: 3797116 • Letter: W

Question

Write a program that will predict the size of a population of organisms. The program should ask for the starting number of organisms, their average daily population increase, and the number of days they will multiply. For example, a population might begin with two organisms, have a daily average increase of 50 percent, and will be allowed to multiply for seven days. The program should use a loop to 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.
You should get something like the following when you run this program:
User Prompts: (User input in bold)
Enter the starting number of organisms: 2
Enter the daily increase: .50
Enter the number of days the organisms will multiply: 7

Program Output:
Day Organisms
1 2.0
2 3.0
3 4.5
4 6.75
5 10.125
6 15.1875
7 22.78125

Modify the program you just wrote so it writes the output to a file instead of the computer screen. The number of organisms in this version of the program should be a real number rounded to two significant figures after the decimal point. Open your output text file with Notepad or another text editor to confirm the output Write a program that will predict the size of a population of organisms. The program should ask for the starting number of organisms, their average daily population increase, and the number of days they will multiply. For example, a population might begin with two organisms, have a daily average increase of 50 percent, and will be allowed to multiply for seven days. The program should use a loop to 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.
You should get something like the following when you run this program:
User Prompts: (User input in bold)
Enter the starting number of organisms: 2
Enter the daily increase: .50
Enter the number of days the organisms will multiply: 7

Program Output:
Day Organisms
1 2.0
2 3.0
3 4.5
4 6.75
5 10.125
6 15.1875
7 22.78125

Modify the program you just wrote so it writes the output to a file instead of the computer screen. The number of organisms in this version of the program should be a real number rounded to two significant figures after the decimal point. Open your output text file with Notepad or another text editor to confirm the output Write a program that will predict the size of a population of organisms. The program should ask for the starting number of organisms, their average daily population increase, and the number of days they will multiply. For example, a population might begin with two organisms, have a daily average increase of 50 percent, and will be allowed to multiply for seven days. The program should use a loop to 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.
You should get something like the following when you run this program:
User Prompts: (User input in bold)
Enter the starting number of organisms: 2
Enter the daily increase: .50
Enter the number of days the organisms will multiply: 7

Program Output:
Day Organisms
1 2.0
2 3.0
3 4.5
4 6.75
5 10.125
6 15.1875
7 22.78125

Modify the program you just wrote so it writes the output to a file instead of the computer screen. The number of organisms in this version of the program should be a real number rounded to two significant figures after the decimal point. Open your output text file with Notepad or another text editor to confirm the output

Explanation / Answer

// C++ code
#include <iostream>
#include <fstream>
#include <cctype>
#include <cstring>
#include <stdlib.h> /* srand, rand */
#include <iomanip>
#include <limits.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>

using namespace std;

int main()
{

int days;   
double organisms = 0;   
double increaseRate = 0;
  
  
cout << "Number the starting number of organisms: ";
cin >> organisms;
  
while( organisms < 2)
{
cout << "Ivalid entry. Re-enter a value greater than 1: ";
cin >> organisms;
}
  
cout << "Enter the daily increase: ";
cin >> increaseRate;
  
while( increaseRate < 0)
{   
cout << "Ivalid entry. Re-enter a non-negative value: ";
cin >> increaseRate;
}

cout << "Enter the number of days the organisms will multiply: ";
cin >> days;
while(days < 1)
{
cout << "Invalid entry. Re-enter a value greater than 0: ";
cin >> days;
}
  
// output to file
ofstream outFile;
outFile.open ("output.txt");
  

increaseRate = increaseRate/100;
cout << "Day Organisms ";
cout << "1 " << organisms << endl;

outFile << "Day Organisms ";
outFile << "1 " << organisms << endl;

for(int i=2; i<=days; i++)
{
organisms += (organisms*increaseRate);
cout << i << " " << organisms << endl;

outFile << i << " " << organisms << endl;
}

// close file
outFile.close();
return 0;
}


/*
output:


Number the starting number of organisms: 2
Enter the daily increase: 50
Enter the number of days the organisms will multiply: 7
Day Organisms
1 2
2 3
3 4.5
4 6.75
5 10.125
6 15.1875
7 22.7812

output.txt
Day Organisms
1 2
2 3
3 4.5
4 6.75
5 10.125
6 15.1875
7 22.7812

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote