-------- C++ ------

Assume you need to test a function named inOrder. The function inOrder receives three intarguments and returns true if and only if the arguments are in non-decreasing order: that is, the second argument is not less than the first and the third is not less than the second. Write the definition of driver function testInOrder whose job it is to determine whether inOrder is correct. So testInOrder returns true if inOrder is correct and returns false otherwise.

For the purposes of this exercise, assume inOrder is an expensive function call, so call it as few times as possible!

-------------------------------------------

Assume you need to test a function named max. The function max receives two int arguments and returns the larger. Write the definition of driver function testmax whose job it is to determine whether max is correct. So testmax returns true if max is correct and returns false otherwise.

------------------------------------------

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, expressed as a fraction in decimal form: for example 0.052 would mean a 5.2% increase each day), 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. If the user fails to satisfy this print a line with this message "The starting number of organisms must be at least 2.", display the prompt again and try to read the value. Similarly, do not accept a negative number for average daily population increase, using the message "The average daily population increase must be a positive value." and retrying. Finally, do not accept a number less than 1 for the number of days they will multiply and use the message "The number of days must be at least 1."

Answers

Answer 1

Answer:

The function testInOrder is as follows:

bool testInOrder(){

bool chk= false;

   int n1, n2, n3;

   cin>>n1;cin>> n2; cin>> n3;

   if(n2>=n1 && n3 >= n2){chk = true;}

   bool result = inOrder(n1,n2,n3);

   if(result == chk){ return true;}

   else{return false;}

}

The function testmax is as follows:

bool testmax(){

   bool chk = false;

   int n1, n2;

   cin>>n1; cin>>n2;

   int mx = n1;    

   if(n2>=n1){        mx = n2;    }

   int returnMax = max(n1,n2);

   if(returnMax == mx){        chk = true;            }

   return chk;

}

The prediction program is as follows:

#include <iostream>

using namespace std;

int main(){

   int startSize,numDays;

   float aveInc;

   cout<<"Start Size: ";

   cin>>startSize;

   while(startSize<2){

       cout<<"The starting number of organisms must be at least 2.";

       cin>>startSize;    }

   cout<<"Average Daily Increase: ";

   cin>>aveInc;

   while(aveInc<1){

       cout<<"The average daily population increase must be a positive value.";

       cin>>aveInc;    }

   cout<<"Number of days: ";

   cin>>numDays;

   while(numDays<1){

       cout<<"The number of days must be at least 1.";

       cin>>numDays;    }

   for(int i = 0;i<numDays;i++){        startSize*=(1 + aveInc);    }

   cout<<"Predicted Size: "<<startSize;

}

Explanation:

testInOrder

This defines the function

bool testInOrder(){

bool chk= false;

This declares all three variales

   int n1, n2, n3;

This gets input for the three variables

   cin>>n1; cin>>n2; cin>>n3;

This correctly check if the numbers are in order, the result is saved in chk

   if(n2>=n1 && n3 >= n2){chk = true;}

This gets the result from inOrder(), the result is saved in result

   bool result = inOrder(n1,n2,n3);

If result and chk are the same, then inOrder() is correct

   if(result == chk){ return true;}

If otherwise, then inOrder() is false

   else{return false;}

testmax

This defines the function

bool testmax(){

This initializes the returned value to false

   bool chk = false;

This declares the two inputs as integer

   int n1, n2;

This gets input for the two numbers

   cin>>n1; cin>>n2;

This initializes the max of both to n1

   int mx = n1;    

This correctly calculates the max of n1 and n2

   if(n2>=n1){        mx = n2;    }

This gets the returned value from the max() function

   int returnMax = max(n1,n2);

If returnMax and max are the same, then max() is correct

   if(returnMax == mx){        chk = true;            }

   return chk;

}

Prediction program

This declares all necessary variables

   int startSize,numDays;  float aveInc;

This gets input for start size

   cout<<"Start Size: ";    cin>>startSize;

The loop is repeated until the user enters valid input (>=2) for startSize

   while(startSize<2){

       cout<<"The starting number of organisms must be at least 2.";

       cin>>startSize;    }

This gets input for average increase

   cout<<"Average Daily Increase: ";    cin>>aveInc;

The loop is repeated until the user enters valid input (>=1) for aveInc

   while(aveInc<1){

       cout<<"The average daily population increase must be a positive value.";

       cin>>aveInc;    }

This gets input for the number of days

   cout<<"Number of days: ";    cin>>numDays;

The loop is repeated until the user enters valid input (>=1) for numDays

   while(numDays<1){

       cout<<"The number of days must be at least 1.";

       cin>>numDays;    }

The following loop calculates the predicted size at the end of numDays days

   for(int i = 0;i<numDays;i++){        startSize*=(1 + aveInc);    }

This prints the predicted size

   cout<<"Predicted Size: "<<startSize;


Related Questions

100 POINTS NEED THIS BEFORE 11:59 TODAY!!!!!!!!!!!!!!!

Answers

Answer:ok be how hobrhkihfehgdhdj fuiufiisefif jfkijfjfhhfhfhfhf

Explanation:

how do i give brainliest? if what you say works i'll give de brain

Answers

two people have to answer the question and at the bottom of the question you'll see a crown and you just click on that to give them brainliest

Answer:

When Two people answer a question A crown should appear at the bottom where you find the buttons like and rat/e so once you click it the crown will go to the top of the question of the question that you think is the best.

Explanation:

Other Questions
The diffrents between an element molecule and a compond molecule is the type of atoms with whitch it is made true or false. Que enseaza obtuviste de los 7 hbitos de los adolescentes altamente efectivos The mayor-council system or the council-manager system are used to run Washingtons Please help will mark brainliest Blue Corporation purchased a truck at the beginning of 2020 for $61,000. The truck is estimated to have a salvage value of $2,440 and a useful life of 195,200 miles. It was driven 28,060 miles in 2020 and 37,820 miles in 2021. Compute depreciation expense using the units-of-production method for 2020 and 2021. Depreciation expense for 2020 Depreciation expense for 2021 Ella ____ todos los das.-nad-nada-nadaba-nadaron square & cube numbers puzzle| Using only square and cube numbers less than or equal to 100, can you fill in the circles to make these| sums true? You can only use each number once and you must use all the numbers.36) + (64Square and cube numbers help me pls! i'll mark u brainliest promised If having long fur helps a guinea pig survive, whatwould you expect to see change in the populationas it evolves?DONE Can someone explain this question which part of the class do you think you will apply to your life both now or in the future? A sewing class has 185 yards of fabric to make quilts. Each quilt requires 8 yards of fabric. How much fabric will remain after all the quilts are made? A coach purchases 47 hats for his players and their families at a total cost of $302. The cost of a small hat is $5.50. A medium hat costs $6.00. A large hat costs $7.00. He purchases three times as many medium hats as small hats. Using matrices, how many large hats did the coach purchase? HELLLLLPP FASSTT PLZZZZ!!!!!! U ANSWER THIS THANNNKKK YOU HELP ME WITH THIS PLEASE. THANK YOU A pretzel company calculated that there is a mean of 73.5 broken pretzels in each production run with a standard deviation of 5.1. If the distribution is approximately normal, find the probability that there will be fewer than 69 broken pretzels in a run. who is responsible for keeping the president up to date about what is happening in the world A car travels at the rate of 60 miles per hour and averages 30 miles per gallon of gasoline. Which of the following is the bestapproximation of the number of gallons of gasoline that will be used in 8 hours of traveling at 60 miles per hour?0.06 gallons16 gallons3.75 gallons7.5 gallons480 gallons What is the surface area of this square pyramid 18 ft33ft36 ft57 ft Hardy Company must maintain a compensating balance of $50,000 in its checking account as one of the conditions of its short-term 6% bank loan of $500,000. Hardy's checking account earns 2% interest. Ordinarily, Hardy would maintain a $20,000 balance in the account for transaction purposes. What is the loan's approximate effective interest rate 10 medications for diabetes