Create a program to create a file containing a temperature conversion chart for 0 to 100 degrees Celsius at 10 degree intervals and the corresponding Fahrenheit temperature. In C++

Respuesta :

Answer:

Written in C++

#include<fstream>

using namespace std;

int main() {

ofstream Myfile("Temperature.txt");

Myfile<<"\tTemperature Conversions"<<endl;

Myfile<<"Celsius\t\t\tFahrenheit"<<endl;

for(int i=0;i<=100;i+=10) {

 Myfile<<i<<" C\t\t\t"<<(i* 9/5 + 32)<<" F"<<endl;

}

return 0;

}

Explanation:

This imports the file stream header which allows the application to handle files

#include<fstream>

using namespace std;

int main() {

This declares Myfile as an output stream object. With this, a text file named Temperature.txt will be created

ofstream Myfile("Temperature.txt");

This next two lines write contents in the created text files. These two contents serve as the header

Myfile<<"\tTemperature Conversions"<<endl;

Myfile<<"Celsius\t\t\tFahrenheit"<<endl;

The following iterated from 0 to 100 with an interval of 10

for(int i=0;i<=100;i+=10) {

This populates the file with degress Celsius and its Fahrenheit equivalents

 Myfile<<i<<" C\t\t\t"<<(i* 9/5 + 32)<<" F"<<endl;

}

return 0;

}