1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Soloha48 [4]
3 years ago
10

We will use linear interpolation in a C program to estimate the population of NJ between the years of the census, which takes pl

ace every 10 years. For our program the x's are the years and the y's are the population. So given a year, we will use linear interpolation to calculate the population for that year, using the surrounding census years.
1. read the data from the file njpopulation.dat into two arrays, one for the years and one for the populations
2. use int for the years and float for the populations
3. create a loop to do the following, until the user enters 0 1. prompt the user to enter a year between 1790 and 2010 2. give an error message and reprompt if the user enters a value outside the valid range 3. use linear interpolation to approximate the population for the given year
4. print the year and the approximate population; print the population with two decimal places
Computers and Technology
1 answer:
nikklg [1K]3 years ago
5 0

Answer:

See explaination for program code

Explanation:

program code below:

#include<stdio.h>

int main()

{

//file pointer to read from the file

FILE *fptr;

//array to store the years

int years[50];

//array to store the population

float population[50];

int n = 0, j;

//variables for the linear interpolation formula

float x0,y0,x1,y1,xp,yp;

//opening the file

fptr = fopen("njpopulation.dat", "r");

if (fptr != NULL)

{

//reading data for the file

while(fscanf(fptr, "%d %f", &years[n], &population[n]) == 2)

n++;

//prompting the user

int year = -1;

printf("Enter the years for which the population is to be estimated. Enter 0 to stop.\n\n");

while(year != 0)

{

printf("Enter the year (1790 - 2010) : ");

scanf("%d", &year);

if (year >= 1790 && year <= 2010)

{

//calculating the estimation

xp = year;

for (j = 0; j < n; j++)

{

if (year == years[j])

{

//if the year is already in the table no nedd for calculation

yp = population[j];

}

else if (j != n - 1)

{

//finding the surrounding census years

if (year > years[j] && year < years[j + 1])

{

//point one

x0 = years[j];

y0 = population[j];

//point two

x1 = years[j + 1];

y1 = population[j + 1];

//interpolation formula

yp = y0 + ((y1-y0)/(x1-x0)) * (xp - x0);

}

}

}

printf("\nEstimated population for year %d : %.2f\n\n", year, yp);

}

else if (year != 0)

{

printf("\nInvalid chioce!!\n\n");

}

}

printf("\nAborting!!");

}

else

{

printf("File cannot be opened!!");

}

close(fptr);

return 0;

}

OUTPUT :

Enter the years for which the population is to be estimated. Enter 0 to stop.

Enter the year (1790 - 2010) : 1790

Estimated population for year 1790 : 184139.00

Enter the year (1790 - 2010) : 1855

Estimated population for year 1855 : 580795.00

Enter the year (1790 - 2010) : 2010

Estimated population for year 2010 : 8791894.00

Enter the year (1790 - 2010) : 4545

Invalid chioce!!

Enter the year (1790 - 2010) : 1992

Estimated population for year 1992 : 7867020.50

Enter the year (1790 - 2010) : 0

Aborting!!

You might be interested in
Which approach does procedural programming follow? bottom up, top down, random, or object oriented​
ELEN [110]

Answer:

Top to down approach

Explanation:

7 0
2 years ago
In 2-5 paragraphs, describe the points that Kendra needs to consider when choosing a telecommunications technology to meet her n
never [62]

Answer:

For marketing requirements, various communication mediums like digital communication medium, as well as non digital traditional communication medium can be used. Some like Blogs, Article directories, forums etc. can be used.

However, the AI, ML, DL and the traditional statistical analysis from Data Science can also be used. You need to install on your blog the chat-bots, And through the Chat-bots we can make a data set, that is in fact automatically generated, and contains email, phone numbers, addresses etc, and this data base can be used to run the Amazon Sage-makers. and a lot of meaningful information can be achieved through the prepared data-set through the Sage-maker.

Thus, you can find out quite easily what is good.

Sage maker, Chat bots and Blog technology is quite cost effective as well.

Explanation:

The above details covers all the requirements.

7 0
2 years ago
Mary and Billy are moving away to college and both know in their hearts that they need to end their relationship. They move away
ivanzaharov [21]

In the case of Mary and Billy, the above is called Negotiated farewell.

<h3>What is Negotiated farewell?</h3>

In the case of  Negotiated Farewell, one can say that couples are knonw to jointly create the story of the end to what we say their marriage.

Note that Negotiated Farewell is one that is made for emotionally immature or any kind of combative people. hence, In the case of Mary and Billy, the above is called Negotiated farewell.

Learn more  about relationship from

brainly.com/question/10286547

#SPJ1

4 0
1 year ago
Choose all items that represent characteristics of a work samples.
Gnom [1K]

Answer:

A.  provides examples of creative work such as writing, film, or art

C.  can be referenced in your resume and taken to job interviews

D.  is well organized and easy for a potential employer to find and digest

Explanation:

Here is the right answer.

5 0
2 years ago
Read 2 more answers
Is apple better than android
KatRina [158]

In a sense yes as it has a more user friendly interface but in terms of usability android is a far better os

3 0
3 years ago
Read 2 more answers
Other questions:
  • Which of these is a subdirectory? <br> HTTPS <br> /FAQ <br> .org <br> WWW
    15·1 answer
  • What is a social media networks
    5·1 answer
  • Crossing out answers that could not possibly be correct is called ‘eliminating answers.’ Please select the best answer from the
    13·2 answers
  • How do you know if a remote host is alive or not?
    5·1 answer
  • ​if a primary key combines two or more fields, then it is called a _____.
    14·1 answer
  • The parallax perspective says that objects that are close up appear to move __________ than far away objects.
    10·1 answer
  • What was the first e-commerce service?
    10·1 answer
  • Read the excerpt from The Code Book. Other attacks include the use of viruses and Trojan horses. Eve might design a virus that i
    13·1 answer
  • HELP ME PLEASE
    14·1 answer
  • • Use variable to create the number 0 at location 0, 400.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!