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]
4 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]4 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
Technology trends continue to increase the processing capabilities of mobile devices. The latest smartphones include up to 8 pro
baherus [9]

Answer:

Two circumstances under which it might be beneficial to offload application functionality from a powerful smartphone are Data Saving and Ransomware/Malware Protection.

Explanation:

Various data like documents, videos,photos etc can be offloaded to a cloud or cloud-let in order to prevent permanent data loss during inevitable as loss of phone, theft etc.  Such saved data can be easily retrieved from cloud storage when new phones are gotten without any loss. Also, in order to prevent total data and application loss by various various attacks, it is advisable that one stores various application and data on cloud servers to enable retrieval easily. Even some cloud servers offer backup security against such virus attacks.

6 0
3 years ago
How did early games in generation 1 or 2 influence zelda botw
Novay_Z [31]

Answer:

Open world exploration and inventory management

Explanation:

In the first Zelda game (NES) and Zelda ii (NES) there were very early open world mechanics along with inventory management.

5 0
3 years ago
Read 2 more answers
A determinant is any attribute whose value determines other values within a column.
guajiro [1.7K]

Answer:

true

Explanation:

4 0
3 years ago
Which of these protections covers creative works such as books and artwork?
Oduvanchick [21]
The answer is D copyright
6 0
3 years ago
This isn't an academic question, but it's a question about something I am consistently seeing on Brainly, so please don't delete
s344n2d4d5 [400]
Yes it does. Hope that answers
3 0
3 years ago
Read 2 more answers
Other questions:
  • PLEASE HELP YOU GUYS
    7·2 answers
  • if you want to presents slides to fellow sudents or co-workers witvh productively software should you use to create them?
    6·1 answer
  • In the borders and shading dialog box where would you look to see if your border will have two sides
    11·2 answers
  • The ____ keyword specifies that a function or method does not return a value.
    5·1 answer
  • You are setting up a desktop computer for an AutoCAD specialist who needs a minimum of 125GB of RAM. Which operating system belo
    6·1 answer
  • (Package Inheritance Hierarchy) Package-delivery services, such as FedEx®, DHL® and UPS®, offer a number of different shipping o
    10·1 answer
  • Which kind of blocks is used to hold values​
    7·1 answer
  • Before u can open and edit a file, you need to zip it, T/F
    12·1 answer
  • I can login to it says to me u cant login at that time
    10·2 answers
  • What is a computer?write any four features of computer​
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!