LAB-10 1-D Array I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.

Slides:



Advertisements
Similar presentations
Introduction to arrays
Advertisements

Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
An Array A sequence of elements of a particular type Each element in the array has an index which gives its position in the sequence An array is declared.
1 Various Methods of Populating Arrays Randomly generated integers.
VB PROJECT “PROJECT SAMPLES”. For Next Loops Design a VB program that displays in a picture box the first N multiples of an input integer Input 3 exam.
Need for Arrays Exercise Read the IDs and the grades for all ICS 101 students. Compute and print the average of the students. Print the grades and IDs.
LAB-04 IF Structure I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.
ITC 240: Web Application Programming
1 ICS 101 – LAB 2 Arithmetic Operations I Putu Danu Raharja kfupm.edu.sa Information & Computer Science Department CCSE - King Fahd University.
LAB-03 Logical Operations I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum.
Chapter 8 Introduction to Arrays Part II Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul.
1 ICS102: Introduction To Computing King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science.
Computer Science 1620 Multi-Dimensional Arrays. we used arrays to store a set of data of the same type e.g. store the assignment grades for a particular.
LAB-05 Function I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.
1 11/8/06CS150 Introduction to Computer Science 1 Arrays Chapter 8 page 477 November 13, 2006.
Computer Science 1620 Arrays. Problem: Given a list of 5 student grades, adjust the grades so that the average is 70%. Program design: 1. read in the.
Arrays Chapter 8 page /24/07CS150 Introduction to Computer Science 1 Arrays (8.1)  One variable that can store a group of values of the same.
Arrays.
LAB-03 Logical Operations I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum.
LAB-12 2-D Array I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.
CMSC 104, Version 8/061L22Arrays1.ppt Arrays, Part 1 of 2 Topics Definition of a Data Structure Definition of an Array Array Declaration, Initialization,
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C.
ReAl :: x OK CHARACTER :: name OK, a 1 character name! CHARACTER(LEN=10) :: name OK, string length 10 REAL :: var-1 cannot have -1 in a declaration var_1.
Fortran- Subprograms Chapters 6, 7 in your Fortran book.
CS1101: Programming Methodology Aaron Tan.
A First Book of ANSI C Fourth Edition
Problem: A company employs a group of fifty salespersons (with reference numbers ) who are paid commission if their individual sales exceeds two-thirds.
Chapter 8 Arrays Part II J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National Taipei University of.
Computer Science 210 Computer Organization Arrays.
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
1 nd Semester Module7 Arrays Thanawin Rakthanmanon Create by: Aphirak Jansang Computer Engineering Department Kasetsart.
More While Loop Examples CS303E: Elements of Computers and Programming.
CHAPTER 9 SUBPROGRAMS Subprograms are useful in the following cases: long complicated program  Subprograms make it readable and simple by dividing it.
Week 2 Lab2 Practice Dina A. Said
Advanced Computer Science Lesson 4: Reviewing Loops and Arrays Reading User Input.
CSE 232: C++ memory management Overview of Arrays Arrays are the simplest kind of data structure –One item right after another in memory (“contiguous range”
Function Overloading Two different functions may have the same name as long as they differ in the number or types of arguments: int max(int x, int y) and.
CS 121 – Quiz Feb 17 th. Question 2 We want to count how many days there were such that the temperature is at least degrees lower than the.
Structuring Data: Arrays ANSI-C. Representing multiple homogenous data Problem: Input: Desired output:
LAB SESSION ONE DIMENSIONAL ARRAY.
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
Functions Structured Programming. Topics to be covered Introduction to Functions Defining a function Calling a function Arguments, local variables and.
Midterm 2 Review. Stars and why we use nested loops  Matrix problems (stars)  Other problems involving multiple dimensions  Loops within a process.
Arrays. Topics to be Covered... Arrays ◦ Declaration ◦ Assigning values ◦ Array manipulation using loops Multi-dimensional arrays ◦ 2D arrays ◦ Declaration.
LAB-09 DO WHILE loop I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.
Why Repetition? Read 8 real numbers and compute their average REAL X1, X2, X3, X4, X5, X6, X7, X8 REAL SUM, AVG READ *, X1, X2, X3, X4, X5, X6, X7, X8.
© Janice Regan, CMPT 128, January CMPT 128: Introduction to Computing Science for Engineering Students Introduction to Arrays.
For Friday Read No quiz Program 6 due. Program 6 Any questions?
CHAPTER 6 ARRAYS IN C 1 st semester King Saud University College of Applied studies and Community Service Csc 1101 F. Alakeel.
Introduction to programming in java Lecture 21 Arrays – Part 1.
CSC 211 Java I for loops and arrays.
Some Assignments  Write a program which prints the following information about at least 5 persons: NAME MAIL-ID EMPLOYEE-CODE PHONE Eg. Umesh
Arrays Declarations CSCI N305
Subroutine Comp 208 Yi Lin.
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays An Array is an ordered collection of variables
Chapter 8 Arrays Objectives
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
LAB-06 IF + Functions I Putu Danu Raharja
Arrays, Part 1 of 2 Topics Definition of a Data Structure
INC 161 , CPE 100 Computer Programming
Chapter 8 Arrays Objectives
Repetition (While Loop) LAB 9
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
REPETITION Why Repetition?
Presentation transcript:

LAB-10 1-D Array I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals

ICS101-LAB10-Term073 2 Background We’d like to develop a program to calculate student’s grades. How is it to store 5 grades? What if we have 100 grades? Simple variables are cumbersome for large number of values Array can store many values with one name Each value is identified by its index

ICS101-LAB10-Term073 3 Simple Variables vs 1-D Array INTEGER GRADE1, GRADE2, GRADE3, GRADE4, … OR INTEGER GRADE(100)

ICS101-LAB10-Term073 4 Declaring a 1-D Array TYPE ARRAY_NAME (DIMENSION) The index will be from 1 to DIMENSION For character values, specify the length: CHARACTER NAMES(10)*20 TYPE ARRAY_NAME(RANGE1:RANGE2) The index will be from RANGE1 to RANGE2 REAL X(-15:35) DIMENSION ARRAY_NAME(DIMENSION) DIMENSION ARRAY_NAME(RANGE1:RANGE2)

ICS101-LAB10-Term073 5 Accessing a Value in 1-D Array Use the index Do not use index outside the range of the array e.g.: INTEGER QUIZ1(10) QUIZ1(20) = 87 Above example does not cause error so be careful

ICS101-LAB10-Term073 6 Initializing Values In our IDE, the values are set to 0 for INTEGER and REAL We can use a loop to initialize the values DO 100 I = 1, 10 QUIZ (I) = CONTINUE We can also initialize it without mentioning the index QUIZ = 60

ICS101-LAB10-Term073 7 Using READ with 1-D Array Single line input Without index READ*, QUIZ Using implied loop READ*, (QUIZ(J), J = 1, 4) Multi-line input Using DO…CONTINUE or DO WHILE…END DO

ICS101-LAB10-Term073 8 Using PRINT with 1-D Array Single line output Without index PRINT*, QUIZ Using implied loop PRINT*, (QUIZ(J), J = 1, 4) Multi-line output Using DO…CONTINUE or DO WHILE…END DO

ICS101-LAB10-Term073 9 Questions When do we use array? How are the elements accessed? What happens if we give an index which is out of the range of the array? In what condition we need to use loop instead of mentioning the array name without index in reading or printing array values?

ICS101-LAB10-Term Exercises 1. Write a program to get 5 values and store them in an array. Calculate the sum and average of those values. Show them. 2. Check if the all of the values in the array are the same and show a message. 3. Write a program to store maximum 30 students. We have mid-term and final exam marks. Get the number of students N and then ask for the grades (only accept 0<=grade<=100). Mid-term and final exam get 40% and 60% weight respectively. Calculate the final marks and determine the minimum, maximum and average. Print the final marks, the min, max, and average.

ICS101-LAB10-Term Exercises 4. Now, we also have 3 quizzes. The weight for each quiz is 10%. Mid-term and final exam get 30% and 40% weight respectively. Print the final marks, the min, max, and average.

ICS101-LAB10-Term Lab 11 Exercises (1) Write a program to ask for REAL values. Use -99 as stopping value. The maximum number of values is 20. Keep the values in a 1-D array, excluding the stopping value. Calculate and show the following: total, average, minimum and maximum of the values.

ICS101-LAB10-Term Using Array as Subprogram Argument An array can be sent to a subprogram by using its name The dimension should also be sent to accommodate different dimensions

ICS101-LAB10-Term Example REAL TOT, X(10) READ*, X; TOT = TOTAL (X, 10) PRINT*, x PRINT*, TOT END REAL FUNCTION TOTAL (A, N) INTEGER N REAL A(N) INTEGER I DO 100 I = 1, N TOTAL = TOTAL + A(I) 100 CONTINUE RETURN END

ICS101-LAB10-Term Lab 11 Exercises (2) Write a function to check if two arrays are identical. Write a program that reverses the elements of a 1-D array having 5 integer elements. Example: if the elements are 2, 5, 3, 10, and 7, they are reversed into 7, 10, 3, 5, and 2. Write a general function/subroutine that reverses a 1-D array of integers.