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

Write a program that will read the following list of home market values for a de

ID: 3546779 • Letter: W

Question

Write a program that will read the following list of home market values for a development, from the keybooard, and store it in an array called prices. It will then caluculate and display the average of the enterdprices to the screen, and then writes the "prices" and the average to a file called prices.txt.Calculation and display of the average should be handled by a function named avgCalc(), writing to the file should be handled by a function named writeResult().


Prices: 150000, 165000, 180000, 210000 , 212000, 300000, 400000, 350000, 195000, 179000


Explanation / Answer

#include<iostream>
#include<fstream>
using namespace std;
double avgCalcc(double prices[],int size)
{
double sum =0;
for(int i=0; i<size; i++)
sum = sum + prices[i];
return sum/size;
}
void writeResult(ofstream& outfile,double prices[],int size,double average)
{
for(int i=0; i<size; i++)
outfile << prices[i] <<" ";
outfile << endl;
outfile <<"Average of prices given by "<< average << endl;
}
int main()
{
double prices[10];
double average;
ofstream outfile("prices.txt");
for(int i=0; i<10; i++)
{
cout << "Enter price " << (i+1) << " : ";
cin >> prices[i];
cout << endl;
}
average = avgCalcc(prices,10);
cout <<"Average of prices given by " << average << endl;
writeResult(outfile,prices,10,average);
outfile.close();
return 0;
}

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