© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 14 – Student Grades Application: Introducing.

Slides:



Advertisements
Similar presentations
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 16 – Shopping List Application: Introducing.
Advertisements

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 10 – Enhancing the Wage Calculator Application:
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 13 – Salary Survey Application: Introducing.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 11 – Fundraiser Application: Introducing Scope.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 4 – Introducing Algorithms, Pseudocode and.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 6 - Arrays Outline 6.1Introduction 6.2Arrays.
11.3 Function Prototypes A Function Prototype contains the function’s return type, name and parameter list Writing the function prototype is “declaring”
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 17 – Payroll Application: Introducing Inheritance.
Chapter 5: Loops and Files.
1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 8 focuses on: array declaration and use passing arrays and array.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 8 - Interest Calculator Application: Introducing.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 15 – Digital Clock Application: Building Your.
Chapter 6 C Arrays Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc. Arrays are data structures.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Introduction to Programming with C++ Fourth Edition
C++ for Engineers and Scientists Third Edition
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 7 – Class Average Application: Introducing.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 9 – Income Tax Calculator Application: Introducing.
 Pearson Education, Inc. All rights reserved Arrays.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 6 – Car Payment Calculator Application: Introducing.
11 Chapter 8 ARRAYS Continued. 22 MULTI-DIMENSIONAL ARRAYS A one-dimensional array is useful for storing/processing a list of values. For example: –The.
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - HelloWorld Application: Introduction to.
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 11 - JavaScript: Arrays Outline 11.1 Introduction 11.2 Arrays 11.3 Declaring and Allocating Arrays.
Array Processing Simple Program Design Third Edition A Step-by-Step Approach 7.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 6 - Arrays Outline 6.1Introduction 6.2Arrays.
 2006 Pearson Education, Inc. All rights reserved Arrays.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 8 - Interest Calculator Application: Introducing.
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 10 – Enhancing the Wage Calculator Application:
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 4 – Wage Calculator Application: Introducing.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 5 – Dental Payment Application: Introducing.
 2005 Pearson Education, Inc. All rights reserved. 1 Arrays Part 4.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 9 Arrays.
 Pearson Education, Inc. All rights reserved Arrays.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
 2005 Pearson Education, Inc. All rights reserved. 1 Arrays.
 Pearson Education, Inc. All rights reserved Arrays.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 9 – Income Tax Calculator Application: Introducing.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 6 – Car Payment Calculator Application: Introducing.
Chapter 3 Assignment, Formatting, and Interactive Input C++ for Engineers and Scientists Third Edition.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 17 – Flag Quiz Application Introducing One-Dimensional.
Value and Reference Parameters. CSCE 1062 Outline  Summary of value parameters  Summary of reference parameters  Argument/Parameter list correspondence.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
C++ for Engineers and Scientists Second Edition Chapter 11 Arrays.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Class Average Application Introducing the Do...Loop While and Do...Loop Until.
Chapter 3: Assignment, Formatting, and Interactive Input.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 7 – Class Average Application: Introducing.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 18 – Student Grades Application Introducing.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 3 – Inventory Application: Introducing Variables,
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Looping.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Craps Game Application Introducing Random-Number Generation and Enum.
Chapter 3 Assignment, Formatting, and Interactive Input C++ for Engineers and Scientists Third Edition.
An Introduction to Programming with C++ Sixth Edition Chapter 12 Two-Dimensional Arrays.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 2.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 17.1 Test-Driving the Student Grades Application.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 11 GEORGE KOUTSOGIANNAKIS 1 Copyright: 2015 Illinois Institute of Technology_ George Koutsogiannakis.
 2005 Pearson Education, Inc. All rights reserved Arrays.
 2006 Pearson Education, Inc. All rights reserved Arrays and Vectors.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Flow Control (while) Outline 3.7The While Repetition.
© 2016 Pearson Education, Ltd. All rights reserved.
Presentation transcript:

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 14 – Student Grades Application: Introducing Two- Dimensional Arrays and References Outline 14.1Test Driving the Student Grades Application 14.2Two-Dimensional Arrays Student Grade Application

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Objectives In this tutorial, you will learn to: –Differentiate between one-dimensional and two- dimensional arrays. –Declare and manipulate two-dimensional arrays. –Understand applications of two-dimensional arrays. –Use the right stream manipulator to right justify output in a field.

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 14.1Test Driving the Student Grades Application

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 14.1Test Driving the Student Grades Application (Cont.) Figure 14.2 Inputting grades into the Student Grades application. Figure 14.4 Displaying test grades and averages.

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 14.1Test Driving the Student Grades Application (Cont.) Figure 14.3 Error message displayed after inputting invalid grade.

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 14.2Two-Dimensional Arrays Two dimensional arrays –Require two indices –Good for representing tables One index represents the row, the other represents the column –First row number and first column number are always zero Figure 14.5 Two-dimensional array with three rows and four columns.

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 14.2Two-Dimensional Arrays (Cont.) Initializing two-dimensional arrays Figure 14.6 Two-dimensional numbers array after initialization.

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. For each student in the class Prompt the user for and input three test grades While the user enters an invalid grade Prompt the user for and input the grade again Display a table header For each student Display each student’s test grades and average grade For each test Display the average grade on the test Display the class average Figure 14.7 Pseudocode for the Student Grades application. Student Grades Application getStudentGrades Function displayGrades Function

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Initialization Section When declaring a function prototype that specifies a two- dimensional array parameter –The number of rows is not required –The number of columns is required

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Initialization Section Figure 14.8 Defining constant variables. Define constants representing the number of students and tests Figure 14.9 Declaring function prototypes. Declaring function prototypes that specify two-dimensional array parameters Specify the number of row and columns for a two-dimensional array and define the function prototype

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Main – Line 1 If there are more array entries than initializers, the remaining entries are initialized to 0 –This statement: would initialize the entire array to 0 ’s Initialize the studentGrade two-dimensional array to Zero. Figure Defining and initializing a two-dimensional array. Declaring a two- dimensional array

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Main – Line 2 Figure Calling the getStudentGrades function to input test grades into the studentGrades array. Prompting the user for and inputting test grades Call the getStudentGrades function and pass studentGrade a two-dimensional array as its argument

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Main – Line 3+ Figure Formatting floating-point values and displaying a grade summary. Formatting floating- point values Displaying test grades and average grades Call the displayGrades function and pass studentGrade a two-dimensional array as its argument

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. getStudentGrades Function Figure Declare the getStudentGrades function. Defining the function getStudentGrades Figure 14.2 Inputting grades into the Student Grades application.

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. getStudentGrades Function (Cont.) Nested for loops are for loops enclosed inside another control statement (usually another for loop). Particularly useful when processing two-dimensional arrays Figure Declaring a for statement. Outside Loop Iterating once for each student Figure Using a nested loop to input each test grade. Inside Loop Prompting the user for and inputting each of the student’s three grades

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. getStudentGrades Function (Cont.) Figure while loop repeats until the user enters a valid grade. Ensuring that the user enters a valid test grade Figure 14.3 Error message displayed after inputting invalid grade. Add a nested while loop inside the inner for loop to check user- input.

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. displayGrades Function Figure Defining local variables in the displayGrades function. Defining local variables

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. displayGrades Function 1. Table Header 2. Display student number. Outside Loop 4. Calculate and display the student’s average grade Outside Loop 6. Calculate and display the class average. 5. Calculate and display the average grade for each test. 3. Output the student’s grades. Inside Loop

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. displayGrades Function (1) Table Header Figure Displaying descriptive text and a table header. Displaying a table header The right stream manipulator right justifies output in a field

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. displayGrades Function (2) Display student number. Beginning of the Outside Loop Figure Displaying a number corresponding to each student. Displaying a number corresponding to each student

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. displayGrades Function (3) Output the student’s grades. Inside Loop Figure Outputting the student’s grades and adding each grade to the total grades. Displaying a test grade, right justified in a field of width 8 Add the test grade to the student’s total and the class’s total

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. displayGrades Function (4) Calculate and display the student’s average grade. End of the Outside Loop Figure Calculating and displaying the student’s average grade. Calculating and displaying the student’s average Resetting the student’s average

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. displayGrades Function (5) Calculate & Display the Average Grade for Each Test Figure Calculating and displaying the average grade for each test. Displaying descriptive text for the row Summing each column of the table to find the total grade for each test Calculating and displaying the average grade for each test

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. displayGrades Function (6) Calculate and Display the Class Average. Figure Calculating and displaying the class average. Calculating and displaying the class average

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. StudentGrades.cpp (1 of 7) Define constants to represent the number of students and tests Declare function prototypes that specify two-dimensional array parameters

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. StudentGrades.cpp (2 of 7) Declare a two- dimensional array Prompt the user for and input test grades Format floating-point values Display test grades and average grades

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. StudentGrades.cpp (3 of 7) Iterate once for each student Prompt user for and input each of the student’s grades

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. StudentGrades.cpp (4 of 7) Ensuring that user enters a valid test grade

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. StudentGrades.cpp (5 of 7) Define local variables

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. StudentGrades.cpp (6 of 7) Displaying a test grade, right justified in a field of width 8 Add the test grade to the student’s total and the class’s total Calculate and display the student’s average Reset the student average

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. StudentGrades.cpp (7 of 7) Display descriptive text for the row Sum each column of the table to find the total grade for each test Calculate and display the class average for each test Calculate and display the class average

© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Lab and Homework Assignment Tutorial 13 − Salary Survey Application. Turn in annotated source file with your own comments. Answer and Turn-in Tutorial 12 Questions 12.4, 12.5, 12.9; Tutorial 13 Questions 13.3, 13.7, 13.9, 13.10; and Tutorial 14 Questions 14.1, 14.4, 14.7 with the following corrections… If an array is declared using int myArray[2][3]={{2,4,6},{1,3,5}}; the expression myArray[1][2] will return what value? For question Always write the question followed by the answer. Remember to highlight the answer. Exercises 12.11, 13.11, and For all exercises start with the provided templates. Due next Wednesday