Question: GEEN163 Average Housing Cost Write a program to determine the average amount households spend on housing (rent or mortgage) based on their income. The U.S.

 GEEN163 Average Housing Cost Write a program to determine the average
amount households spend on housing (rent or mortgage) based on their income.

GEEN163 Average Housing Cost Write a program to determine the average amount households spend on housing (rent or mortgage) based on their income. The U.S. Department of Housing and Urban Development's (HUD) Housing Affordability Data System (HADS) provides data samples of housing and income from across the country. Your instructor has provided you with select information from HADS in the file HADS.txt with about 59,000 lines of data. Each line in the file contains: Age Region Built Value int int int int Age of the head of household Census region Year the house was built Value of the house Tenure int Rent or mortgage indicator Utility double Utility costs Cost double Monthly rent or mortgage Income i Annual household income Your program only needs the Cost and Income values, but your program must read all data values in the file. The first line of the file contains header information. Your program should call readtine () once in the beginning to get past the header. You need to group the data by income. Each group represents a salary range of $10,000. You need to separate the households that have an income less than $10,000 from the many lines of data that show zero income. You also need to group the few households with large incomes into the last group. Your program can create an index for each group by if (income 0) index0; index 20; index income / 10000 + 1; else if (income 200000) elset The index can be used to index two arrays of 21 values, an array of doubles that will hold the sum of the cost for that group and an array of integers that counts the number of lines in this group Your program should read each line of data, calculate the index, add the cost to the sum for that group and increment the count of lines in that group. After reading all data in the file, the program should display the results stored in the arrays. For each group, divide the sum of the cost for that group by the number in that group to get an average Display the group and the average monthly housing cost. Use the printf method to make the columns align and the average cost to be displayed with only two decimal digits. GEEN163 Average Housing Cost Write a program to determine the average amount households spend on housing (rent or mortgage) based on their income. The U.S. Department of Housing and Urban Development's (HUD) Housing Affordability Data System (HADS) provides data samples of housing and income from across the country. Your instructor has provided you with select information from HADS in the file HADS.txt with about 59,000 lines of data. Each line in the file contains: Age Region Built Value int int int int Age of the head of household Census region Year the house was built Value of the house Tenure int Rent or mortgage indicator Utility double Utility costs Cost double Monthly rent or mortgage Income i Annual household income Your program only needs the Cost and Income values, but your program must read all data values in the file. The first line of the file contains header information. Your program should call readtine () once in the beginning to get past the header. You need to group the data by income. Each group represents a salary range of $10,000. You need to separate the households that have an income less than $10,000 from the many lines of data that show zero income. You also need to group the few households with large incomes into the last group. Your program can create an index for each group by if (income 0) index0; index 20; index income / 10000 + 1; else if (income 200000) elset The index can be used to index two arrays of 21 values, an array of doubles that will hold the sum of the cost for that group and an array of integers that counts the number of lines in this group Your program should read each line of data, calculate the index, add the cost to the sum for that group and increment the count of lines in that group. After reading all data in the file, the program should display the results stored in the arrays. For each group, divide the sum of the cost for that group by the number in that group to get an average Display the group and the average monthly housing cost. Use the printf method to make the columns align and the average cost to be displayed with only two decimal digits

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!