write a C++ program. Write a program to read the survey results into a Vector, created in the class that contains the main function, and perform the following analysis. Do not use Arrays. You will not receive credit for Program 10 if you do. 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 #include #include #include #include
write a C++ program.
Write a program to read the survey results into a Vector, created in the class that contains the main function, and perform the following analysis. Do not use Arrays. You will not receive credit for Program 10 if you do.
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 now
This is a popular solution!
Step by step
Solved in 2 steps