use C++ 20 points. A housing company needs to have an array of structures to hol
ID: 3910047 • Letter: U
Question
use C++
20 points. A housing company needs to have an array of structures to hold the following ustomer code (number), Family size (number). Income (decimal number). Type of Residence and preferred zip code for residence (number) 1. Declare a structure to hold this data. 2. Declare an array of structures to hold all the company data. 3. Write function GetData that will fill the array of structures with this data from a file and return to main the array of structures and the size of the array. The data will come from a file "Housng.tt. H. M. L)Explanation / Answer
#include<iostream>
#include <fstream>
#include <string>
using namespace std;
struct data
{
int customer_code, family_size;
float income;
char res_type;
long int zip;
};
int GetData()
{
int cc, fs;
float in;
char res;
long int z;
ifstream infile("Housing.txt");
int counter=0;
while (infile >> cc >> fs>>in>>res>>z)
{
data* newdata=new data;
counter++;
newdata->customer_code=cc;
newdata->family_size=fs;
newdata->income=in;
newdata->res_type=res;
newdata->zip=z;
cout<<cc<<" "<<fs<<" "<<in<<" "<<res<<" "<<z<<" ";
}
infile.close();
return(counter);
}
int main()
{
int size=GetData();
cout<<"Size="<<size;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.