Course Answers

BUSINESS
COMPUTER SCIENCE
OTHER COURSES
My Profile

Solved: 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 O

By |

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.

  • The program should define a struct that holds a month name, a low temperature (an int) and a high temperature (an int).
  • The program should define an array of such structs. The number of elements in that array should be established using a named constant of type int. This value should be sufficient to store all of the data records from the provided data file.

Your program MUST use the following functions:

  • Function loadData: The function reads and stores data in the parallel array and 2D array from a text file (temps.txt).
    int loadData( ifstream &infile, Temperature [], int &rows )
    (Note that the last parameter returns the number of rows of data actually read from the file.)
  • Function findLow: This function finds the month that has the lowest temperature and returns a copy of the struct containing that information.
    Temperature findLow( Temperature [], int rows )
  • Function findHigh: This function finds the month that has the highest temperature and returns a copy of the struct containing that information.
    Temperature findHigh( Temperature [], int rows ):
  1. The main program should display a brief description of the program.
  2. The main program should report the number of months of data read from the file.
  3. The main program should not call the High and Low functions if the number of rows is less than 1.
  4. Do not use any global variables. (All variables must be declared inside functions.)
  5. You must use all the given function prototypes and not change them. You can add more functions if you like.
  6. The first thing each function should do is announce that it has been called, after which it should display no other output.
  7. Use a while loop to read all lines of text from the input file.
  8. LoadData( ) should include code to prevent the arrays from being exceeded.
  9. The loadData function should return 0 if no error occurred or a nonzero number if an error occurred.
  10. The program should return an error if the file could not be opened.
  11. Keep the input file in the same directory as your project.

This program finds the warmest and coldest months as listed in a data file. KloadData called) found 12 months of data Kaverag



This program finds the warmest and coldest months as listed in a data file. KloadData called) found 12 months of data KaverageHigh called> The highest average temperature was KaverageLow called The lowest average temperature was in in Process returned 0 (Ox0) Press any key to continue. execution time: 0.140 s

Answer Preview

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 Ju

Get Answer Now


Buy (USD $9.00)

Get Answer Now

Answered
Buy @ USD $9.00
Related Questions

OTHER COURSES
OTHER COURSES
OTHER COURSES
OTHER COURSES
OTHER COURSES
OTHER COURSES
OTHER COURSES
OTHER COURSES
OTHER COURSES
OTHER COURSES