Write a C program that reads a set of data records each of w
(Write a C++ program) that reads a set of data records, each of which contains values for house id number, initial house cost, annual fuel cost, and tax rate. Calculate the total house cost for a five-year period, when given the above data.
Example::
initial house cost = $100000 annual fuel cost = $1000 tax rate = 0.02
The five year cost will be equal to (100000) + 5*(1000) + 5*(100000*0.02)
The resultant file should contain the house id number and the total cost for each house appended to the bottom of the original data file.
That\'s a text file
house number rate Initial_house_cost fuel cost
123 0.012 100000 1000
546 0.0460 240000 1500
134 0.0030 230000 1900
222 0.0600 600000 6750
199 0.0660 45000 330
567 0.0480 175000 5000
999 0.0540 340000 2000
246 0.0530 120000 1650
777 0.0280 205000 1500
789 0.0460 80000 920
99999
Solution
// C++ code determine total house cost for a five-year period
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
int house_ID;
double rate;
double initialCost;
int fuelCOst;
double annual_fuelCost;
ifstream inputfile (\"input.txt\");
ofstream outputfile (\"output.txt\");
if (inputfile.is_open())
{
outputfile << \"House ID\\tAnnual fuel Cost\ \";
while (true)
{
inputfile >> house_ID;
if(house_ID == 99999 )
break;
inputfile >> rate >> initialCost >> fuelCOst;
annual_fuelCost = initialCost+5*fuelCOst + 5*(initialCost*rate);
outputfile << \"\\t\" << house_ID << \"\\t\\t\\t\" << annual_fuelCost << endl;
}
inputfile.close();
}
else cout << \"Unable to open Input file\";
return 0;
}
/*
input.txt
123 0.012 100000 1000
546 0.0460 240000 1500
134 0.0030 230000 1900
222 0.0600 600000 6750
199 0.0660 45000 330
567 0.0480 175000 5000
999 0.0540 340000 2000
246 0.0530 120000 1650
777 0.0280 205000 1500
789 0.0460 80000 920
99999
output.txt
House ID Annual fuel Cost
123 111000
546 302700
134 242950
222 813750
199 61500
567 242000
999 441800
246 160050
777 241200
789 103000
*/

