
Concept explainers
write a C++ program.
Write a program to read the survey results into a
a) Print the record of each household included in the survey in a four-column format with headings.
b) Calculate and print the average household income.
c) List the identification number, income, members, and state of the households that exceed the average in a four-column format with headings.
d) Determine and print the identification number, income, members, and state of the households, in a four-column format with headings, that have income below the 2021 United States poverty level.
e) Determine and print the percentage of households that have income below the 2021 United States poverty level.
Compute the poverty level income using one of the formulas below.
povertyLevel = 17420.00 + 4540.00 * (m – 2)
If household is in the 48 contiguous states or the District Of Columbia
povertyLevel = 21770.00 + 5680.00 * (m – 2)
If household is in the state of Alaska
povertyLevel = 20040,00 + 5220.00 * (m – 2)
If household is in the state of Hawaii
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 the poverty level income increases as m gets larger.
Create a Class named, HouseHold, in a header file named, HouseHold.h, and a source file named, HouseHold.cpp, that contain the attributes described earlier and other necessary member functions. Write a test Class named, Program10.cpp, that creates a Vector of HouseHold objects.
Here is the temple for Program10.cpp
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <vector>
#include <conio.h>
#include "HouseHold.h"
using namespace std;
int openFiles(ifstream &, ofstream &);
void readFile(vector<HouseHold> &, ifstream &);
double averageDataInVector(vector<HouseHold>, int);
void aboveAverage(vector<HouseHold>, double, int, ofstream &);
void belowPovertyLevel(vector<HouseHold>, int, ofstream &);
void printDataInVector(vector<HouseHold>, int, ofstream &);
void printRecord(int, double, int, string, ofstream &);
void closeFiles(ifstream &, ofstream &);
void holdScreen(int);
void developerInfo(ofstream &);
int main()
{
int rtnCode = 0;
int vectorSize = 0;
double average = 0.0;
ifstream inputFileObject; // create an input file object
ofstream outputFileObject; // create an input file object
rtnCode = openFiles(inputFileObject, outputFileObject);
if (rtnCode == 0)
{
outputFileObject << fixed
<< showpoint
<< setprecision(2);
developerInfo(outputFileObject);
vector<HouseHold> houseHold;
readFile(houseHold, inputFileObject);
vectorSize = houseHold.size();
printDataInVector(houseHold, vectorSize, outputFileObject);
average = averageDataInVector(houseHold, vectorSize);
aboveAverage(houseHold, average, vectorSize, outputFileObject);
belowPovertyLevel(houseHold, vectorSize, outputFileObject);
closeFiles(inputFileObject, outputFileObject);
holdScreen(1);
}
else
{
holdScreen(0);
}
return 0;
}
int openFiles(ifstream &inFileObject, ofstream &outFileObject)
{
int rc = 1;
inFileObject.open("Program10.txt"); // open the file for read
if (!inFileObject.fail())
{
outFileObject.open("Program10-output.txt"); // open the file for write
if (!outFileObject.fail())
{
rc = 0;
}
else
{
cout << "Unable to create output file \"Program10-output.txt\" " << endl;
}
}
else
{
cout << "File \"Program10.txt\" " << "was not found." << endl;
}
return rc;
}
void readFile(vector<HouseHold> &houseHold, ifstream &inFileObject)
{
int rc = 0;
int tempId;
double tempIncome;
int tempMembers;
string tempState;
inFileObject >> tempId // read first data
>> tempIncome
>> tempMembers
>> tempState;
while (!inFileObject.eof()) // if data is not end-of-file
{
HouseHold family(tempId, tempIncome, tempMembers, tempState);
houseHold.push_back(family);
inFileObject >> tempId // read the next data
>> tempIncome
>> tempMembers
>> tempState;
}
}
double averageDataInVector(vector<HouseHold> houseHold, int theSize)
{
}
void aboveAverage(vector<HouseHold> houseHold, double theAverage, int theSize, ofstream &outFile)
{
}
void belowPovertyLevel(vector<HouseHold> houseHold, int theSize, ofstream &outFile)
{
}
void printDataInVector(vector<HouseHold> houseHold, int theSize, ofstream &outFile)
{
}
void printRecord(int theId, double theIncome, int theMembers, string theState, ofstream &outFile)
{
}
void holdScreen(int theFlag)
{
char ch;
if (theFlag)
cout << "\nOutput sent to \"Program10-output.txt\". Press any key to exit... ";
else
cout << "\nPress any key to exit... ";
ch = getch();
cout << endl;
}
void developerInfo(ofstream &outputFileObject)
{
outputFileObject << "Name: Reshma Kumar" << endl;
outputFileObject << "Course: COSC-1337
outputFileObject << "Program: Ten"
<< endl
<< endl;
} // End of developerInfo
void closeFiles(ifstream &inFileObject, ofstream &outFileObject)
{
inFileObject.close();
outFileObject.close();
}

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

- It's important to note that the name of an array by itself is really a pointer to the first element of the array. Therefore passing an array to function is simple since you can just specify the name of the array. Are these statements true?arrow_forwardWrite a function or script in a programming language of your choice to calculate the convolution of two arrays each with 100 elements. The result will be ?[?] and the input arrays will be ?[?] and ?[?].arrow_forwardProgram in C. You are grading your students’ exams and will create a program to help you with the process. Each exam contains 3 problems. Minimum score in each problem is 0; maximum score is 33.33. Use these steps as your guidance: Define a structure called Student. Give the structure 4 members; one ID (integer) and three scores (decimal numbers). Then, in main, ask for the number of students you will be grading. Then, create an array of structures of type Student. Then, also in main, iterate through each one of them and scan their ID and scores. Lastly, also in main, print out the ID of the student, followed by the final grade (addition of the three scores). Notes: You don’t have to check if the user inputted a score between 0 and 33.33. You may assume users will always input a score within this range. No need of functions (everything can be done in main if you want to).arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





