1 / 13

Activation Record

Activation Record. void GetAllData (float a[][MAX_COLS], int& numRows , int& numCols ) { cin >> numRows >> numCols ; for (. . .) for (. . .) cin >> a[ i ][j]; }. int main() { float allScores[MAX_ROWS][MAX_COLS]; int rows, cols;

jana
Download Presentation

Activation Record

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Activation Record void GetAllData(float a[][MAX_COLS], int& numRows, int& numCols) { cin >> numRows >> numCols; for (. . .) for (. . .) cin >> a[i][j]; } int main() { float allScores[MAX_ROWS][MAX_COLS]; int rows, cols; GetAllData(allScores, rows, cols); . . . } Rows: cols: allScores[][]: ? ? ? 5 24 … &numRows: &numCols: a[][]: Return Address ? ? ? 5 24 …

  2. Activation Record GetInput() main() void GetInput(float& payRate, float& hoursWorked) { cout << "Enter pay rate: "; cin >> payRate; cout << "Enter hours: "; cin >> hoursWorked; return; } const float REG_HOURS = 40.0; const float OVER_TIME = 1.5; int main() { float hours, rate, gross; GetInput(rate, hours); gross = GrossPay(rate, hours); // display result return 0; } GrossPay() float GrossPay(float payRate, float hours) { if (hours > REG_HOURS) payRate = (hours - REG_HOURS) * OVER_TIME * payRate + REG_HOURS * payRate; else payRate = hours * payRate; return payRate; }

  3. Activation Record void GetInput(float& payRate, float& hoursWorked) { cin >> payRate; cin >> hoursWorked; return; } int main() { float hours, rate, gross; GetInput(rate, hours); . . . } hours: rate: gross: &payRate: &hoursWorked: Return Address ? ? ? 10 45 45 10 ? ? ?

  4. Activation Record float GrossPay(float payRate, float hours) { if (hours > REG_HOURS) payRate = (hours - REG_HOURS) * OVER_TIME * payRate + REG_HOURS * payRate; else payRate = hours * payRate; return payRate; } int main() { float hours, rate, gross; GetInput(rate, hours); gross = GrossPay(rate, hours); . . . } 45 10 ? hours: rate: gross: payRate: 10 hours: 45 Return Address 475 475

  5. Activation Record Out InOut In ? ? // Parameters; ( , , ) void Final(int& x, int& y, int z) { int temp; temp = z / x; z = 2 * temp - 5; x += z; y = z - x; return; } ? int main() { int num1 = 5, num2 = 9, x = 10;   Final(num1, num2, x + num2); return 0; } &x : 5 (num1) &y : 9 (num2) z : 19 Temp: ? Return Address 3 1 6 -5 num1: 5 num2: 9 X : 10 6 -5

  6. Array and typedef float Scores[9]; // an array variable typedef float arrayType[9]; // a (new) data type // a nick name for array of // 9 float elements

  7. 2-D Array and typedef typedef float arrayType[9]; arrayType Scores; // Array of float with 9 elements arrayType allScores[10]; // Array of arrays // 2-D array // Same as float allScores[10][9];

  8. 2-D Array as Function Parameter float rowAverage(const float nums[][MAX_COLS], int rowIndex, int numCols); // Must specify MAX_COLS! // nums[] is an array // Data Type of array elements: // an array of MAX_COLS floats

  9. 2-D Array as Function Parameter const int MAX_COLS = 9; typedef float arrayType[MAX_COLS]; float rowAverage(const arrayType nums[], int rowIndex, int numCols); // nums[] is an array // Data Type of array elements: arrayType // an array of MAX_COLS floats float rowAverage(const float nums[][MAX_COLS], int rowIndex, int numCols); // Must specify MAX_COLS! // Must specify data type of array elements!

  10. 2-D Array and Array of Array typedef float arrayType[9]; arrayType allScores[10]; // To understand float allScores[10][9]; // To code

  11. 2-D Array and Array of Array float rowAverage(const float nums [], int numCols); float arrayAverage(const float nums [][MAX_COLS], int numRows, int numCols); float nums[MAX_ROWS][MAX_COLS]; float Average; Average = rowAverage(nums[row], cols); // Passing one row as an array Average = arrayAverage(nums, rows, cols); // Passing the entire 2-D array

  12. Schedule • Quiz9-4: 5 points Due 5 pm, Monday • Prog6 Due Wednesday Grace Friday Fix Prog5 errors C-String for C++ String Selection Sort

  13. Final Exam • 7:00 – 8:52 PM • Thursday, May19, 2011 • Doudna 103 • 100 Points • Comprehensive • #2 pencil

More Related