C++ please help Notes: Observe the usual guidelines regarding the initial commen
ID: 3725670 • Letter: C
Question
C++ please help
Notes: Observe the usual guidelines regarding the initial comment section, indenting, and so on. There must be a problem statement at the beginning of the program or a deduction will be made . . In if-else statements, indent statements to be executed for if or else conditions three to five spaces. Align else or else if with corresponding if . Indent statements within loops 1. In a Matlab text by Gilat a problem presents the relationship between temperatures in New York City and Anchorage, Alaska during the month of January, 2001. According to the U S National Oceanic Atmospheric Admnistration, the January Fahrenheit high Anchorage Temperature degrees Fahrenheit) temperatures for New York City and Anchorage Alaska were New York City Temperature (degrees Fahrenhett Date 26 30 24 38 25 28 46 29 36 20 10 42 36 39 31 34 40 36 34 16 43 19Explanation / Answer
Screenshot
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Code:-
// FileReading.cpp : Defines the entry point for the console application.
//
//Header files
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
//Main method
int main() {
//Variable declaration
int sumN = 0, sumA = 0,countAgreaterN=0, countGeater32 = 0,tempH=0,dateH=0,tempL = 42, dateL = 0;
int x,y,z;
ifstream inFile; //file object creation
//Open fie for reading
inFile.open("C:/Users/deept/source/repos/temperature.txt");
//check the file can open or not
if (!inFile) {
cout << "Unable to open file";
exit(1); // terminate with error
}
cout << "Date" << " NewyorkTemperator " <<" AnchorageTemperature" << endl;
//Loop to read data from file
while (inFile >> x>>y>>z) {
sumN += y; //Sum of Newyork temperature to find average
sumA += z; //Sum of Anchorage temperature to find average
if (z > y) {
countAgreaterN += 1; //find the count of anchorage temperature greater than Newyork temperature
}
if (y > 32 && z>32) {
countGeater32 += 1; //Find the count of temperature greater than 32 simultaneously
}
//Find highest temperure and date of Newyork
if (tempH < y) {
tempH = y;
dateH = x;
}
//Find lowest temperure and date of Anchorage
if (tempL > z) {
tempL = z;
dateL = x;
}
//display file data
cout<<" "<<x <<" "<<y <<" "<<z << endl;
}
inFile.close();//Close file
//display all results of calculations
cout << "Average temperature of Newyork = " <<sumN/31 << endl;
cout << "Average temperature of Anchorage = " << sumA/31 << endl;
cout << "Anchored temperature Greater than Newyork temperature,Count = " << countAgreaterN << endl;
cout << "Newyork's highest temperature = " << tempH << " , Date = " << dateH<< endl;
cout << "Anchorage's Lowest temperature = " << tempL << " , Date = " << dateL << endl;
cout << "Temperature Greater than 32 simultaneously,Count = " << countGeater32 << endl;
return 0;
}
-------------------------------------------------------------------------------------------------------------------------------------------------
Note:-
I am using visual studio2017.
If any query,let me know
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.