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

Write a C++ program to solve problem 4 on p. 187 in the textbook with the follow

ID: 642627 • Letter: W

Question

Write a C++ program to solve problem 4 on p. 187 in the textbook with the following modification: the input containing the 12 temperatures is stored in a file, not entered from the keyboard. The 12 temperatures can be stored on 1 line, multiple lines, or 1 temperature a line. The input file and the output file MUST be named tempdata.in and tempdata.out and stored on the C drive using the pathname C:/tempdata.in and C:/ternpdata.out, respectively. The input file name and the output tile name are entered interactively from the keyboard. The following shows a sample run of the program. Enter the input tile name: C:/tempdata.in Enter the output file name: C:ftempdata.out Program terminates successfully. Output is stored in the output file C:/tempdata.out 2. Write an interactive C++ program whose input is a series of 12 temperatures as the difference between the current temperature and the one preceding it. The difference is not output for the first temperature that is input. At the end of the program, the average temperature should be displayed for the user via tout. For example, given the input data Be sure to use proper formatting and appropriate comments in your code. The input should be collected through appropriate prompts, and the output should be labeled clearly and formatted neatly.

Explanation / Answer

#include<iostream>
#include<fstream>
using namespace std;

int main()
{
//Variable declaration
float num[12]; //array to hold the Numbers
int i=0; //Variable to hold the no. of numbers taken as input
ifstream inf("tempdata.dat"); //open file in read mode
ofstream outputFile("tempdataout.dat");
//loop runs untill last data is retreved from the file
while(!inf.eof())
{
inf>>num; //Get data from file into array num
i++;
}

//To display the result
for(int j=0;j<i;j++)
{
outputFile<<num[j]<<" ";
//This loop is to calculate and display the difference part except for first number
if(j>0)
{
outputFile<<(num[j]-num[j-1]);
}
cout<<endl;
}
//To pause the screen so that output can be seen
system("pause");
outputFile.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