Need help with C++ problem in xcode File weather.txt contains some unknown numbe
ID: 3717274 • Letter: N
Question
Need help with C++ problem in xcode
File weather.txt contains some unknown number of lines of weather data using the following format. Some fields are of fixed width and others are free format. All entries are from the same month. You may assume data is valid and the file is not empty. The program should work for any valid file with similar format of data Column 1: Width 15 Column 2:Width 15 Column 3: Width 10 Column 4 Width 10 Column 5: No width Column 6: No width Column 7: No width Contains a town name Contains a date in the form: mm/dd/yy Contains a double wind speed value in units of m/sec Contains a wind direction N ESW Contains a double temperature Contains a temperature scale code F (Fahrenheit) or C (Celsius) Contains a nameExplanation / Answer
Answer 1 :-
#include <iostream>
using namespace std;
//main
int main()
{
float Fahrenheit;
float celsius;
// read input from customer
cout << "Enter the value in Fahrenheit : ";
cin>>Fahrenheit;
celsius = (5.0/9.0)*(Fahrenheit-32);
cout<<endl<<"Celsius equivalent is : "<<celsius<<endl;
return 0;
}
----------------
output sample:-
Enter the value in Fahrenheit : -40
Celsius equivalent is : -40
Enter the value in Fahrenheit : 100
Celsius equivalent is : 37.7778
---------------------------------------------------------------------------
Answer 2:-
#include <iostream>
using namespace std;
//main
int main()
{
float Fahrenheit;
float celsius;
// read input from customer
cout << "Enter the value in celsius : ";
cin>>celsius;
Fahrenheit = 1.8*celsius + 32.0;
cout<<endl<<"Fahrenheit equivalent is : "<<Fahrenheit<<endl;
return 0;
}
---------
output sample:-
Enter the value in celsius : -40
Fahrenheit equivalent is : -40
Enter the value in celsius : 100
Fahrenheit equivalent is : 212
----------------------------------------------------------
Answer 3:-
#include <iostream>
#include<cmath>
using namespace std;
//main
int main()
{
float wind_speed;
float celsius;
float wind_chill_factor;
// read input from customer
cout << "Enter the value in wind speed in m/sec: ";
cin>>wind_speed;
cout << "Enter the value in temperature in celsius: ";
cin>>celsius;
wind_chill_factor = (33 -(((10*sqrt(wind_speed)-wind_speed +10.5)*(33-celsius))/23.1));
cout<<endl<<"wind_chill_factor equivalent is : "<<wind_chill_factor<<endl;
return 0;
}
------------------
output sample:-
Enter the value in wind speed in m/sec: 23
Enter the value in temperature in celsius: 45
wind_chill_factor equivalent is : 51.4199
---------------------
Read file input in program
#include <iostream>
#include<cmath>
#include<fstream>
using namespace std;
//main
int main()
{
float wind_speed;
float celsius;
float wind_chill_factor;
ifstream myReadFile;
//read file input
myReadFile.open("C:/sample.txt");
char output[100];
if (myReadFile.is_open()) {
while (!myReadFile.eof()) {
myReadFile >> output;
cout<<output;
}
}
myReadFile.close();
return 0;
}
---------------------------------------------------------------------------------------------
If you have any query, please feel free to ask.
Thanks a lot.