Write a C++ program that demonstrates use of programmer-defined data structures (structs), an array of structs, passing an array of structs to a function, and returning a struct as the value of a function. A function in the program should read several rows of data from a text file. (The data file should accompany this assignment.) Each row of the file contains a month name, a high temperature, and a low temperature. The main program should call another function which finds and returns a struct which contains the month with the highest temperature, and another function to do the same with the lowest temperature. The main program should output the highest and lowest temperatures for the year, along with the month names that correspond to those temperatures.
Your program MUST use the following functions:
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
// tempMonths.txt
January 47 36
February 51 37
March 57 39
April 62 43
May 69 48
June 73 52
July 81 56
August 81 57
September 75 52
October 64 46
November 52 41
December 45 35
________________________
#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;
struct Temperature
{
string monName;
int high;
int low;
};
void loadData( ifstream &infile, Temperature [], int
&rows );
Temperature findLow( Temperature [], int rows );
Temperature findHigh( Temperature [], int rows );
int main() {
string monName;
int high,low,rows=0;
//defines an input stream for the data file
ifstream dataIn;
//Opening the input file
dataIn.open("tempsMonths.txt");
//checking whether the file name is valid or not
if(dataIn.fail())
{
cout<<"** File Not Found **";
return 1;
}
else
{
cout<<"This program finds the warmest and
coolest months as listed in a data file."<<endl;
Temperature temps[100];
loadData(dataIn,temps,rows);
cout<<"found "<<rows<<" months of
data"<<endl;
Temperature taHigh=findHigh(temps,rows);
cout<<"The lowest average temperaure was
"<<taHigh.low<<" in
"<<taHigh.monName<<endl;
Temperature taLow=findLow(temps,rows);
cout<<"The lowest average temperaure was
"<<taLow.low<<" in
"<<taLow.monName<<endl;
}
//Closing the intput file
dataIn.close();
return 0;
}
void loadData( ifstream &infile, Temperature temps[], int
&rows )
{
int i=0;
cout<<"(loadData called)"<<endl;
while(infile>>temps[i].monName>>temps[i].high>>temps[i].low)
{
i++;
rows++;
}
infile.close();
}
Temperature findLow(Temperature temps[],int rows)
{
cout<<"(averageLow called)"<<endl;
int min=temps[0].low;
int indx=0;
for(int i=0;i<rows;i++)
{
if(min>temps[i].low)
{
min=temps[i].low;
indx=i;
}
}
return temps[indx];
}
Temperature findHigh( Temperature temps[], int rows )
{
cout<<"(averageHigh
called)"<<endl;
int max=temps[0].high;
int indx=0;
for(int i=0;i<rows;i++)
{
if(max<temps[i].low)
{
max=temps[i].low;
indx=i;
}
}
return temps[indx];
}
_________________________
Output:
_______________Could you plz rate me well.Thank You
Write a C++ program that demonstrates use of programmer-defined data structures (structs), an array of structs, passing...
Write a program that demonstrates use of programmer - defined
data structures. Please provide code! Thank you.
Here are the temps given:
January 47 36
February 51 37
March 57 39
April 62 43
May 69 48
June 73 52
July 81 56
August 83 57
September 81 52
October 64 46
November 52 41
December 45 35
Janual line Iranin Note: This program is similar to another recently assigned program, except that it uses struct and an array of...
Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. You should also have a parallel array to store the names of the 12 months. The program should read the Month's names, and the temperatures from a given input file called temperature.txt. The program should output the highest and lowest temperatures for the year, and the months that correspond to those temperatures. The program must use the following functions:...
Write a program that dynamically allocates an array in the freestore large enough to hold a user defined number of test scores as doubles. Once all the scores are entered, the array should be passed to a function that finds the highest score. Another function the array should be passed to a function that finds the lowest score. Another function should be called that calculates the average score. The program should show the highest, lowest and average scores. Must use...
Write a program that dynamically allocates an array in the freestore large enough to hold a user defined number of test scores as doubles. Once all the scores are entered, the array should be passed to a function that finds the highest score. Another function the array should be passed to a function that finds the lowest score. Another function should be called that calculates the average score. The program should show the highest, lowest and average scores. Must use...
Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and the highest and lowest temperatures for the year. Your program must consist of the following functions 1. Function getData: This function reads and stores data in the two- dimensional array. 2. Function averageHigh: This function calculates and returns the aver- age high temperature for the year. 3. Function averageLow:...
Program in C Student Data using Structs In this assignment you will create a program (using multiple .c files) to solve the following problem: You have been hired by the university to create a program that will read in input from a .txt file. This input will contain a student name, student id #, their age and their current gpa. You should use the following struct for your student data: struct Student{ char name[50]; int id; float...
I need this asap. C++ please
A A Ap Aa Consolas 14 AaBbCcDd AaBbCcDd AaBbCc Editing ste 1 No Spac.. Heading 1 В I 1 Normal x A U A v ab х. Dictate ipboard Font Paragraph Styles Voice Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and the highest and lowest temperatures for the year. Your program...
The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...
Write a program in C++ language that finds the largest number in an array of positive numbers using recursion. Your program should have a function called array_max that should pass in an int array, and an int for the size of the array, respectively, and should return an int value. As an example, given an array of size 10 with contents: {10, 9, 6, 1, 2, 4, 16, 8, 7, 5} The output should be: The largest number in the...
Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions. • void getScore() should ask the user for a test score, store it in the reference parameter variable, and validate it. This function should be called by the main once for each of the five scores to be entered. •...