Week 13a solution
13 a) Write a C++ program that creates a file of data in the form
of the temperature.Fill the file with at least 50 temperature readings.
Call this program store_temps.cpp and the file it creates raw_temps.txt.
Program:
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
double temp;
ofstream out("raw_temps.txt");
for(int i=1;i<=50;i++)
{
if(i<=25)
temp=20+.1*i;
else
temp=20+.25*i;
out<<temp<<"\n";
}
out.close();
cout<<"Temparature readings in the file are \n";
ifstream in("raw_temps.txt");
cout<<in.rdbuf();
in.close();
return 0;
}
Output:
Temparature readings in the file are
20.1
20.2
20.3
20.4
20.5
20.6
20.7
20.8
20.9
21
21.1
21.2
21.3
21.4
21.5
21.6
21.7
21.8
21.9
22
22.1
22.2
22.3
22.4
22.5
26.5
26.75
27
27.25
27.5
27.75
28
28.25
28.5
28.75
29
29.25
29.5
29.75
30
30.25
30.5
30.75
31
31.25
31.5
31.75
32
32.25
32.5
No comments:
Post a Comment