COMP104B Introduction to Comp Sci 2 Introduction and Revision 1.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 5 Array and Collections.
Advertisements

Chapter 9 – One-Dimensional Numeric Arrays. Array u Data structure u Grouping of like-type data u Indicated with brackets containing positive integer.
Introduction to Programming Lecture 39. Copy Constructor.
AU/MITM/1.6 By Mohammed A. Saleh 1. Introducing the string Class  Instead of using a character array to hold a string, you can use a type string variable.
1 Arrays Chapter 9. 2 Outline  The array structure (Section 9.1)  Array declaration  Array initialization  Array subscripts  Sequential access to.
Monday, 11/11/02, Slide #1 CS 106 Intro to Comp. Sci. 1 Monday, 11/11/02  Questions? HW 04 due today at 5.  Today – Lists and an introduction to searching.
Beginning C++ Through Game Programming, Second Edition by Michael Dawson.
C Strings. The char Data Type for Storing Characters The char data type can is used to declare a variable that can hold a single character. Examples:
Dale/Weems/Headington
What Data Do We Have? Sections 2.2, 2.5 August 29, 2008.
1 Lecture-4 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
1 Lecture 20:Arrays and Strings Introduction to Computer Science Spring 2006.
Chapter 8. 2 Objectives You should be able to describe: One-Dimensional Arrays Array Initialization Arrays as Arguments Two-Dimensional Arrays Common.
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.
COMP2004 Programming Practice Sam Holden Department of Computer Science University of Sydney.
General Computer Science for Engineers CISC 106 Lecture 34 Dr. John Cavazos Computer and Information Sciences 05/13/2009.
Chapter 9: Arrays and Strings
Chapter 9: Arrays and Strings
Chapter 8 Arrays and Strings
Lecture 5 of Computer Science II Arrays Instructor: Mr.Ahmed Al Astal.
Week 7 – String. Outline Passing Array to Function Print the Array How Arrays are passed in a function call Introduction to Strings String Type Character.
CPS120: Introduction to Computer Science Arrays. Arrays: A Definition A list of variables accessed using a single identifier May be of any data type Can.
 2006 Pearson Education, Inc. All rights reserved Arrays.
Chapter 8 Arrays and Strings
COIT29222 Structured Programming Slide 1 COIT29222-Structured Programming Lecture Week 06  Reading: Study Guide Book 2, Modules 9 & 10 Textbook (4 th.
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
1 DATA STRUCTURES: LISTS. 2 LISTS ARE USED TO WORK WITH A GROUP OF VALUES IN AN ORGANIZED MANNER. A SERIES OF MEMORY LOCATIONS CAN BE DIRECTLY REFERENCED.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 26: Exam 2 Preview.
1 C++ Syntax and Semantics, and the Program Development Process.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
C++ PROGRAMMING: PROGRAM DESIGN INCLUDING DATA STRUCTURES, FIFTH EDITION Chapter 10: Strings and string type.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems.
CHAPTER 7 arrays I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
Syntax and Semantics, and the Program Development Process ROBERT REAVES.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
CPS120: Introduction to Computer Science Lecture 15 Arrays.
Array Objectives To understand the concept of arrays To understand the purpose to which we use arrays. To be able to declare references to arrays. To be.
CS Class 03 Topics  Sequence statements Input Output Assignment  Expressions Read pages Read pages 40 – 49 for next time.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: One-Dimensional Arrays Array Initialization Arrays.
Arrays.
COIT29222-Structured Programming Lecture Week 08  Reading: Textbook (4 th Ed.), Chapter 4 Textbook (6 th Ed.), Chapter 7 Study Guide Book 2, Module 11.
1 Arrays and Strings Lecture: Design Problem l Consider a program to calculate class average Why?? ?
Review for Final Exam. Contents 5 questions (20 points each) + 1 bonus question (20 points) – Basic concepts in Chapters 1-4 – Chapters 5-9 – Bonus: Chapter.
1 CSC103: Introduction to Computer and Programming Lecture No 24.
Today’s Lecture  Literal  Constant  Precedence rules  More assignment rules  Program Style.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
CHAPTER 6 ARRAYS IN C++ 2 nd Semester King Saud University College of Applied studies and Community Service CSC 1101 By: Fatimah Alakeel Edited.
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.
Pointers in C++. Topics Covered  Introduction to Pointers  Pointers and arrays  Character Pointers, Arrays and Strings  Examples.
1 What is a Named Constant? A named constant is a location in memory that we can refer to by an identifier, and in which a data value that cannot be changed.
C++ Programming Lecture 19 Strings The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
CISC105 – General Computer Science Class 4 – 06/14/2006.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
Array and Pointers An Introduction Unit Unit Introduction This unit covers the usage of pointers and arrays in C++
Lecture 17: 4/4/2003CS148 Spring CS148 Introduction to Programming II Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
Two-Dimensional Data Class of 5 students Each student has 3 test scores Store this information in a two- dimensional array First dimension: which student.
C++ Programming Lecture 13 Functions – Part V By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Introduction to programming in java Lecture 21 Arrays – Part 1.
Arrays An array is a sequence of objects all of which have the same type. The objects are called the elements of the array and are numbered consecutively.
Objectives You should be able to describe: One-Dimensional Arrays
Variables with Memory Diagram
CS 1430: Programming in C++ Turn in your Quiz1-2 No time to cover HiC.
Review for Final Exam.
Review for Midterm Exam
Review for Final Exam.
CS1110 Today: collections.
COMS 261 Computer Science I
CS31 Discussion 1D Winter19: week 4
Presentation transcript:

COMP104B Introduction to Comp Sci 2 Introduction and Revision 1

Housekeeping Margaret Jefferies Consultations by appointment Other important information is in the course outline

Housekeeping Lecture notes will be handed out in lectures and will be available on the course web site. These are only a skeleton of the lecture You will need to be at the lecture to get the full story We will cover material for the practicals We will cover material for the exam and go over sample questions Most importantly you will learn how to program in C++

Revision One dimensional Arrays (1)What is an array? (2)When would you use an array? (3)Name two operations that are performed on arrays

One-dimensional arrays Say I want to store the points the Chiefs scored in each of its Super 12 Games Write down a declaration for an array to do this

One-dimensional Arrays We need to be able to assign values to each of the positions in this array. The Chiefs scores in order were: 7, 18, 18, 6, 16, 40, 45, 26, 37, 28, 31 Write the code (an assignment statement) that will assign the score for third game.

One Dimensional Arrays Initialisation Usually we should first initialise the array. That is give it some initial value that makes sense. This involves repetition, we repeatedly assign the same value to all the positions in the array. This means we use a ….. to do the initialisation Write the code that initialises all the values in the Chiefs’ score array to zero.

At the end of the super 12 competition the array will have the following values Use the following code to print out the values, one per line for (i = 0; i <= 10; i++) cout << chiefs_scores[i] << endl;

One dimensional Arrays Sometimes we need to know if a position in an array has been given a value or not We need to know if the position is used or empty How can we tell this?

Deleting an item from a One Dimensional Array say you stored your book collection in array using the ISBN number long int book_collection[]; What’s a suitable initialisation value

Deleting an item from a One Dimensional Array long int book_collection[MAX]; int i; for (i = 0; i <= MAX; i++) book_collection[i] = 0;

Deleting an item from a One Dimensional Array book_collection[0] = ; book_collection[1] = ; book_collection[2] = ; book_collection[3] = ; book_collection[4] = ; ….

Deleting an item from a One Dimensional Array for (i = 0; i <= MAX; i++) if (book_collection[i] != 0) cout << book_collection[i] << endl; Prints out:

Deleting an item from a One Dimensional Array Delete book 3 book_collection[2] = 0; ….

Deleting an item from a One Dimensional Array for (i = 0; i <= MAX; i++) if (book_collection[i] != 0) cout << book_collection[i] << endl; Prints out:

Strings - a special type of array See chapter 9 of Bronson char str[20]; str = “this is a string” \0 is the string terminating character thisisastring\0

Strings - a special type of array See chapter 9 of Bronson char str[20]; str = “this is a string”; ‘\0’ is the string terminating character the compiler inserts it for you thisisastring\0

One dimensional arrays Strings char str[20] means we can have strings up to length 19. Say we instead we had the declaration char str[16]; str = “this is a string”; this is not a valid string because it does not have a terminating character thisisastring