View the step-by-step solution to:

Topics 8.1 Arrays Hold Multiple Values 8.2 Accessing Array Elements 8.3 Inputting and Displaying Array Contents 8.4 Array Initialization 8.5...

4)Rain or Shine:
An amateur meteorologist wants to keep track of weather conditions during the past year's three month summer season and has designated each day as either rainy(R), cloudy (C) or sunny (S). Write a program that stores this information in a 3x30 array of characters, where the row indicates the month (0=june,1=july,2=August) and the column indicates the day of the month. Note that data is not being collected for the 31st of any month. The program should begin by reading the weather data in from a file. Then it should create a report that displays for each month and for the whole 3 month period, how many days were rainy, how many were cloudy, and how many were sunny. It should also report which of the three months had the largest number of rainy days. Data for the program can be found in rainorshine.dat file.
Topics 8.1 Arrays Hold Multiple Values 8.2 Accessing Array Elements 8.3 Inputting and Displaying Array Contents 8.4 Array Initialization 8.5 Processing Array Contents 8.6 Using Parallel Arrays 8.7 The typedef Statement 8.8 Arrays as Function Arguments 8.9 Two-Dimensional Arrays 8.10 Arrays with Three or More Dimensions 8.11 Vectors 8.12 Arrays of Class Objects 8.1 Arrays Hold Multiple Values * Array : variable that can store multiple values of the same type *Values are stored in adjacent memory locations * Declared using [] operator const int ISIZE = 5; int tests[ISIZE]; Array Storage in Memory The definition int tests[ISIZE]; // ISIZE is 5 allocates the following memory Array Terminology In the definition int tests[ISIZE]; * int is the data type of the array elements * tests is the name of the array * ISIZE , in [ISIZE] , is the size declarator . It shows the number of elements in the array. *The size of an array is the number of bytes allocated for it (number of elements) * (bytes needed for each element) Array Terminology Examples Examples: Assumes int uses 4 bytes and double uses 8 bytes const int ISIZE = 5, DSIZE = 10; int tests[ISIZE]; // holds 5 ints, array // occupies 20 bytes double volumes[DSIZE]; // holds 10 doubles
Background image of page 01
// array is 80 bytes 8.2 Accessing Array Elements *Each array element has a subscript , used to access the element. *Subscripts start at 0 Accessing Array Elements Array elements (accessed by array name and subscript) can be used as regular variables tests[0] = 79; cout << tests[0]; cin >> tests[1]; tests[4] = tests[0] + tests[1]; cout << tests; // illegal due to // missing subscript 8.3 Inputting and Displaying Array Contents cout and cin can be used to display values from and store values into an array const int ISIZE = 5; int tests[ISIZE]; // Define 5-elt. array cout << "Enter first test score "; cin >> tests[0]; Array Subscripts *Array subscript can be an integer constant, integer variable, or integer expression *Examples: Subscript is cin >> tests[3]; int constant cout << tests[i]; int variable cout << tests[i+j]; int expression Inputting and Displaying All Array Elements To access each element of an array *Use a loop *Let the loop control variable be the array subscript * A different array element will be referenced each time through the loop for (i = 0; i < 5; i++) cout << tests[i] << endl; Getting Array Data from a File const int ISIZE = 5, sales[ISIZE]; ifstream dataFile;
Background image of page 02
Show entire document
Sign up to view the entire interaction

Top Answer

Dear Student, I have reviewed your assignment thoroughly, based on your assignment details and current... View the full answer

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask a homework question - tutors are online