Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The results of a survey of the households in your township are available for pub

ID: 3546378 • Letter: T

Question

                    The results of a survey of the households in your township are available for public scrutiny. Each record contains data for one household, including a                     four-digit integer identification number, the annual income for the house-hold, and the number of household members. Write a program to read the survey results                     into three arrays and perform the following analyses.                 

                

                    
                

                

                    a. Count the number of households included in survey and prints a three-column table displaying the data. (Assume that no more than 25 households were                     surveyed.) display a table                 

                

                    
                

                

                    b. Calculate the average household income, and list the identification number and income of each household that exceeds the average. display a table,                     find average                 

                

                    
                

                

                    c. Determine the percentage of households that have incomes below the poverty level. Compute the poverty level income using the formula.                     p=$6500+$750*(m-2) where m is the number of members of each household. This formula shows that the poverty level depends on the number of family members, m,                     and that the poverty-level income increases as m gets larger. Test your program on the following data.                 

                

                    
                

                

                    Identification Number Annual Income Household Members                 

                

                    1041 12,180 4                 

                

                    1062 13,240 3                 

                

                    1327 19,800 2                 

                

                    1483 22,458 8                 

                

                    1900 17,000 2                 

                

                    2112 18,125 7                 

                

                    2345 15,623 2                 

                

                    3210 3,200 6                 

                

                    3600 6,500 5                 

                

                    3601 11,970 2                 

                

                    4724 8,900 3                 

                

                    6217 10,000 2                 

                

                    9280 6,200 1                 

                

                    "Must be in 1 data file"
                

                

                    
                

                                      http://www.chegg.com/homework-help/questions-and-answers/help-program-im-stump-figuring-start-results-survey-households-township-available-public-s-q4376470                     <-- This link is the example in java how the answer should be look like but I need in C++

Explanation / Answer


01#include <iostream> 02#include <iomanip> 03#include <fstream> 04 05 06using namespace std; 07 08int readHousehold(ifstream &inFile,int idhouseholdArray[], double incomeArray[], int membersArray[], int size); 09void displayhouseData(int idhouseholdArray[], double incomeArray[], int membersArray[]); 10 11const int OK = 0; 12 13int main() 14{ 15 int rc, size; 16 17 int idhouseholdArray[24] = {1041,1062,1327,1483,1900,2112,2345,3210,3600,3601,4724,6217,9280,1000,1200,5601,5724,5217,5280,5000,5200,5230,6641,7000}; 18 19 double incomeArray[24] = {12180,13240,19800,22458,17000,18125,15623,3200,6500,11970,8900,10000,6200,30000,35000,51970,66900,10000,70000,100000,25000,12000,85000,45500}; 20 21 int membersArray[24] ={4,3,2,8,2,7,2,3,5,2,3,2,1,3,2,9,3,2,1,6,3,6,7,4}; 22 23 ifstream inFile; // create an input file object 24 25 cout << fixed 26 << showpoint 27 << setprecision(2); 28 29 inFile.open("Bonus-Program.txt"); // open the file read 30 31 if (!inFile.fail()) // if open was successful 32 { // execute statements in true path 33 rc = readHousehold(inFile, idhouseholdArray, incomeArray, membersArray, size); 34 if (rc == OK) 35 displayhouseData(idhouseholdArray, incomeArray, membersArray); 36 else 37 cout << "Error: Incorrect house data in file!!" << endl; 38 } 39 else // if fail was not successful 40 { // execute statements in false path 41 cout << "File "bonus.txt" " 42 << "not found." 43 << endl; 44 } 45 46 system("PAUSE"); 47 48 return 0; 49} 50 51int readHousehold(ifstream &inFile,int idhouseholdArray[], double incomeArray[], int membersArray[],int size) 52{ 53 int count = 0, rtnCode = 0; 54 int temp; 55 56 inFile >> temp; 57 while ((!inFile.fail()) && (count < size)) 58 { 59 idhouseholdArray[count] = temp; 60 count++; 61 62 incomeArray[count] = temp; 63 count++; 64 65 membersArray[count] = temp; 66 count++; 67 68 69 inFile >> temp; 70 if (count == size) 71 { 72 if (!inFile.fail()) 73 rtnCode = 1; 74 } 75 } 76 77 if (count < size) 78 rtnCode = 1; 79 80 return rtnCode; 81} 82 83 84void displayhouseData(int idhouseholdArray[], double incomeArray[], int membersArray[]) 85{ 86 87 cout << idhousholdArray[]; 88 89} 90]
01#include <iostream> 02#include <iomanip> 03#include <fstream> 04 05 06using namespace std; 07 08int readHousehold(ifstream &inFile,int idhouseholdArray[], double incomeArray[], int membersArray[], int size); 09void displayhouseData(int idhouseholdArray[], double incomeArray[], int membersArray[]); 10 11const int OK = 0; 12 13int main() 14{ 15 int rc, size; 16 17 int idhouseholdArray[24] = {1041,1062,1327,1483,1900,2112,2345,3210,3600,3601,4724,6217,9280,1000,1200,5601,5724,5217,5280,5000,5200,5230,6641,7000}; 18 19 double incomeArray[24] = {12180,13240,19800,22458,17000,18125,15623,3200,6500,11970,8900,10000,6200,30000,35000,51970,66900,10000,70000,100000,25000,12000,85000,45500}; 20 21 int membersArray[24] ={4,3,2,8,2,7,2,3,5,2,3,2,1,3,2,9,3,2,1,6,3,6,7,4}; 22 23 ifstream inFile; // create an input file object 24 25 cout << fixed 26 << showpoint 27 << setprecision(2); 28 29 inFile.open("Bonus-Program.txt"); // open the file read 30 31 if (!inFile.fail()) // if open was successful 32 { // execute statements in true path 33 rc = readHousehold(inFile, idhouseholdArray, incomeArray, membersArray, size); 34 if (rc == OK) 35 displayhouseData(idhouseholdArray, incomeArray, membersArray); 36 else 37 cout << "Error: Incorrect house data in file!!" << endl; 38 } 39 else // if fail was not successful 40 { // execute statements in false path 41 cout << "File "bonus.txt" " 42 << "not found." 43 << endl; 44 } 45 46 system("PAUSE"); 47 48 return 0; 49} 50 51int readHousehold(ifstream &inFile,int idhouseholdArray[], double incomeArray[], int membersArray[],int size) 52{ 53 int count = 0, rtnCode = 0; 54 int temp; 55 56 inFile >> temp; 57 while ((!inFile.fail()) && (count < size)) 58 { 59 idhouseholdArray[count] = temp; 60 count++; 61 62 incomeArray[count] = temp; 63 count++; 64 65 membersArray[count] = temp; 66 count++; 67 68 69 inFile >> temp; 70 if (count == size) 71 { 72 if (!inFile.fail()) 73 rtnCode = 1; 74 } 75 } 76 77 if (count < size) 78 rtnCode = 1; 79 80 return rtnCode; 81} 82 83 84void displayhouseData(int idhouseholdArray[], double incomeArray[], int membersArray[]) 85{ 86 87 cout << idhousholdArray[]; 88 89} 90] 01#include <iostream> 02#include <iomanip> 03#include <fstream> 04 05 06using namespace std; 07 08int readHousehold(ifstream &inFile,int idhouseholdArray[], double incomeArray[], int membersArray[], int size); 09void displayhouseData(int idhouseholdArray[], double incomeArray[], int membersArray[]); 10 11const int OK = 0; 12 13int main() 14{ 15 int rc, size; 16 17 int idhouseholdArray[24] = {1041,1062,1327,1483,1900,2112,2345,3210,3600,3601,4724,6217,9280,1000,1200,5601,5724,5217,5280,5000,5200,5230,6641,7000}; 18 19 double incomeArray[24] = {12180,13240,19800,22458,17000,18125,15623,3200,6500,11970,8900,10000,6200,30000,35000,51970,66900,10000,70000,100000,25000,12000,85000,45500}; 20 21 int membersArray[24] ={4,3,2,8,2,7,2,3,5,2,3,2,1,3,2,9,3,2,1,6,3,6,7,4}; 22 23 ifstream inFile; // create an input file object 24 25 cout << fixed 26 << showpoint 27 << setprecision(2); 28 29 inFile.open("Bonus-Program.txt"); // open the file read 30 31 if (!inFile.fail()) // if open was successful 32 { // execute statements in true path 33 rc = readHousehold(inFile, idhouseholdArray, incomeArray, membersArray, size); 34 if (rc == OK) 35 displayhouseData(idhouseholdArray, incomeArray, membersArray); 36 else 37 cout << "Error: Incorrect house data in file!!" << endl; 38 } 39 else // if fail was not successful 40 { // execute statements in false path 41 cout << "File "bonus.txt" " 42 << "not found." 43 << endl; 44 } 45 46 system("PAUSE"); 47 48 return 0; 49} 50 51int readHousehold(ifstream &inFile,int idhouseholdArray[], double incomeArray[], int membersArray[],int size) 52{ 53 int count = 0, rtnCode = 0; 54 int temp; 55 56 inFile >> temp; 57 while ((!inFile.fail()) && (count < size)) 58 { 59 idhouseholdArray[count] = temp; 60 count++; 61 62 incomeArray[count] = temp; 63 count++; 64 65 membersArray[count] = temp; 66 count++; 67 68 69 inFile >> temp; 70 if (count == size) 71 { 72 if (!inFile.fail()) 73 rtnCode = 1; 74 } 75 } 76 77 if (count < size) 78 rtnCode = 1; 79 80 return rtnCode; 81} 82 83 84void displayhouseData(int idhouseholdArray[], double incomeArray[], int membersArray[]) 85{ 86 87 cout << idhousholdArray[]; 88 89} 90] 51int readHousehold(ifstream &inFile,int idhouseholdArray[], double incomeArray[], int membersArray[],int size) 52{ 53 int count = 0, rtnCode = 0; 54 int temp; 55 56 inFile >> temp; 57 while ((!inFile.fail()) && (count < size)) 58 { 59 idhouseholdArray[count] = temp; 60 count++; 61 62 incomeArray[count] = temp; 63 count++; 64 65 membersArray[count] = temp; 66 count++; 67 68 69 inFile >> temp; 70 if (count == size) 71 { 72 if (!inFile.fail()) 73 rtnCode = 1; 74 } 75 } 76 77 if (count < size) 78 rtnCode = 1; 79 80 return rtnCode; 81} 82 83 84void displayhouseData(int idhouseholdArray[], double incomeArray[], int membersArray[]) 85{ 86 87 cout << idhousholdArray[]; 88 89} 90] 57 while ((!inFile.fail()) && (count < size)) 58 { 59 idhouseholdArray[count] = temp; 60 count++; 61 62 incomeArray[count] = temp; 63 count++; 64 65 membersArray[count] = temp; 66 count++; 67 68 69 inFile >> temp; 70 if (count == size) 71 { 72 if (!inFile.fail()) 73 rtnCode = 1; 74 } 75 } 76 77 if (count < size) 78 rtnCode = 1; 79 80 return rtnCode; 81} 82 83 84void displayhouseData(int idhouseholdArray[], double incomeArray[], int membersArray[]) 85{ 86 87 cout << idhousholdArray[]; 88 89} 90]
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote