

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
How to use 2-d arrays in c++ to store tables of data for multiple students and their corresponding grades. It covers the memory layout of multi-dimensional arrays, the need to specify the second dimension when passing them as function parameters, and provides an example program to calculate the average dive score for each diver.
Typology: Study notes
1 / 2
This page cannot be seen from the preview
Don't miss anything!
Multi-dimensional Arrays 2-D arrays Allow you to store a table of data Example: float examGrades[3]; //1 dimensional array - lets you store 3 grades for one student //To store several grades for many students using one identifier – use a 2D array const int MAX_PEOPLE = 10; const int NUM_GRADES = 3; float examGrades[MAX_PEOPLE][NUM_GRADES]; //list row first, col second //How to use it – requires 2 loops to read data into individual array cells for (i =0; i < MAX_PEOPLE; i++) { for (j = 0; j < NUM_GRADES; j++) { cin >> examGrade[i][j]; } } When passed as a parameter, you don’t specify the first array size, but you need to specify the second (or others if there are more.) why? C++ stores in row order in memory: first row…. second row…..third row ….. To reference an element you need to know where each row begins Ex: //prototype void readData(int [][NUM_GRADES], int); //function heading void readData(int grades[][NUM_GRADES], int number) { … }
Example Program: #include
}//end CalculateAvgDive