Question

Problem: The spread of disease through a community has been determined to follow the formula Current_Infected...

Problem: The spread of disease through a community has been determined to follow the formula Current_Infected = Initial_Infected * e^0.8t where t is the time in days

. Prompt the user to enter the initial (day 0) number of infected people and number of days to considered. The number of infected should be a floating point number and the number of days should be a whole number. Use while loops to confirm robustly that the initial number of infected and the number of days are positive number, you should assume the user enters values of appropriate data types. Create a table from day 0 to entered days and current infected using a for loop. Use formatting to line up the columns and to output the number of infected to 5 significant figures. Make sure that you include column headings. Do not create a variable or constant for e, instead use the appropriate built-in function to calculate the current infected.

using: C++ visual studio

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The program plan:

  • Ask the user for the correct input of infections and number of days using a while loop
  • Assign memories for days and infections
  • Calculate infection on each day using the given equation
  • Display the table at last.

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

The c++ code:

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
   double initialCount;
   int i, d;
   while (true) //loop till correct input is given
   {
       cout << "Enter the number of infected people : ";
       cin >> initialCount; //take input of infected people
       if (initialCount > 0)
           break;
       else
           cout << "\t||Error : Number of people are not positive.\n";
   }

   while (true) //loop till correct input is given
   {
       cout << "Enter the number of days : ";
       cin >> d; //take input of number of days
       if (d > 0)
           break;
       else
           cout << "\t||Error : Number of days are not positive.\n";
   }

   int* days = new int[d + 1]; //assign memory for day 0 to d
   double* counts = new double[d + 1]; //assign memory for infection count

   for (i = 0; i <= d; i++)
   {
       days[i] = i;
       counts[i] = initialCount * exp(0.8 * i); //calculate the infections for day i
   }

   //display the table below
   cout << "\nDays\tInfection Count\n";
   cout.precision(5); //sets maximum precision to 5 significant digits
   for (i = 0; i <= d; i++)
   {
       cout << days[i] << "\t" << counts[i] << "\n";
   }

   return 0;
}

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

Code Screenshot:

#include <iostream> [#include <cmath> using namespace std; int main() { 1 2 3 4 5 6 7 8 9 10 11 12 13 14 double initialCount;while (true) //loop till correct input is given cout << Enter the number of days : ; cin >> d; //take input of number of da//display the table below cout << \nDays\tInfection Count\n; cout.precision (5); for (i = 0; i <= d; i++) { 38 39 40 41 42

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

Output:

Microsoft Visual Studio Debug Console Enter the number of infected people : 10 Enter the number of days : 10 Days 0 1 2 3 4 5

======= THE END =======

Stay safe. Stay immune.

Add a comment
Know the answer?
Add Answer to:
Problem: The spread of disease through a community has been determined to follow the formula Current_Infected...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Part A - SIR model for the spread of disease Overview. This part of the assignment...

    Part A - SIR model for the spread of disease Overview. This part of the assignment uses a mix of theory and data to estimate the contact number c=b/k of an epidemic and hence to estimate the infection-spreading parameter b. The point is that once you know the value of b for a certain disease and population, you can use it in your model the next time there is an cpidemic, thus cnabling you to make predictions about the demand...

  • Problem 1 - Print positive message Create a new project named whatever you want in Visual...

    Problem 1 - Print positive message Create a new project named whatever you want in Visual Studio using the Windows Desktop Wizard or in Xcode. If you're using Visual Studio, add a main.c file to your project; you can use the main.c template I provided on Canvas if you'd like. If you're using Xcode, Xcode automatically generates a main.c file for you. Read in an integer from the user; don't prompt for the user input, because that will confuse the...

  • Problem: Create a program that will ask scientist in tracking the resistances of products from various...

    Problem: Create a program that will ask scientist in tracking the resistances of products from various batches. The resistances of good resistors should be between 3 and 3.5 inclusive. Your program will need to track the number of resistances that are too high (>3.5 ohms), the number of resistances that are too low (<3.0ohms) and calculate the average of the resistances that fall in the proper range (>=3 and <= 3.5). Your program should prompt the user to enter name...

  • Question: C Programming Problem: Pointer and Struct Description: The purpose of this assignment is to prov......

    Question: C Programming Problem: Pointer and Struct Description: The purpose of this assignment is to prov... C Programming Problem: Pointer and Struct Description: The purpose of this assignment is to provide practice programming using structs and pointers. Your program will accept user input and store it in a dynamic array of structs. First, you will define a structure to describe a item to be bought. Your program will prompt the user for the initial size of the array. It will...

  • If you’re using Visual Studio Community 2015, as requested, the instructions below should be exact but...

    If you’re using Visual Studio Community 2015, as requested, the instructions below should be exact but minor discrepancies may require you to adjust. If you are attempting this assignment using another version of Visual Studio, you can expect differences in the look, feel, and/or step-by-step instructions below and you’ll have to determine the equivalent actions or operations for your version on your own. INTRODUCTION: In this assignment, you will develop some of the logic for, and then work with, the...

  • Create a NOTEPAD or PDF file that restates the problem in your own words, specifies what input is needed, w...

    Create a NOTEPAD or PDF file that restates the problem in your own words, specifies what input is needed, what output is expected, the step by step process (algorithm) to get the output from the input, and test data (input for which you know the expected output) for each of the 3 problems given below. You should not write any actual C++ code. Make sure the problem statement is in your own words and is descriptive enough so someone not...

  • Need some help I am not understanding this programming class at all. We are using Microsoft...

    Need some help I am not understanding this programming class at all. We are using Microsoft visual studio with python in console mode to complete these labs. Double-click to hide white space CIS115 Week 4 Lab Overview Title of Lab: Multiplication Table in Python Summary This week's lab is to create a simple multiplication table using nested loops and if statements. Prompt the user for the size of the multiplication table (from 2x2 to 10x10). Use a validation loop to...

  • III. Overview & Requirements: The following description has been adopted from Deitel & Deitel. One of...

    III. Overview & Requirements: The following description has been adopted from Deitel & Deitel. One of the most popular games of chance is a dice game called "craps," which is played in casinos and back alleys throughout the world. The rules of the game are straightforward: A player rolls two dice. Each die has six faces. These faces contain 1, 2, 3, 4, 5, and 6 spots. After the dice have come to rest, the sum of the spots on...

  • This lab will create a digital clock based on nested FOR loops for hours, minutes, and...

    This lab will create a digital clock based on nested FOR loops for hours, minutes, and seconds, and a WHILE loop for doing over and over so that your clock works for all year long without interruption. Note: If a group of students is interested, we could create a real digital wall-mounted clock to be placed in our classroom, so I can keep track of the time during my lectures. The actual clock would be based on the LED Strip...

  • PROBLEM STATEMENT The Starship Enterprise may be in difficulty! It has been ordered by Star Fleet...

    PROBLEM STATEMENT The Starship Enterprise may be in difficulty! It has been ordered by Star Fleet to go on a peaceful scientific mission around the planet Delta Tau. Unfortunately, the Deltoids are not a very nice life form. Captain James T. Kirk is worried that the planet's inhabitants may use their giant tractor beam in an attempt to pull the Enterprise down to the surface of the planet and destroy it! Naturally, the engines of the mighty Enterprise are strong...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT