STARTING OUT WITH STARTING OUT WITH Class 2 2 Review of course requirements: Homework due Thursday at beginning of class-- no lates accepted Programs.

Slides:



Advertisements
Similar presentations
C Language.
Advertisements

Zhang Hongyi CSCI2100B Data Structures Tutorial 2
Array What it is. How to use it How to declare it How to initialize it.
1 Lab Session-VI CSIT-120 Spring 2001 Let us look at C++ syntax rules in brief Exercise VI-A (Demo Required) Lab Assignment#4 Due May 1st, 2001 (No Lab.
Starting out with C++1 Chapter 9 – Pointers Getting the address of a Variable Why do we have pointers? Indirection – difference between –Will you go out.
Chapter 7 Arrays C++ Programming, Namiq Sultan1 Namiq Sultan University of Duhok Department of Electrical and Computer Engineering Reference: Starting.
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
Administrative MUST GO TO CORRECT LAB SECTION! Homework due 11:59pm on Tuesday. 25 points off if late (up to 24 hours) Cannot submit after 11:59pm on Wednesday.
CS 117 Section 2 + KNET Computer accounts – ed to KNET students –Change password Homework 1 Lab Tutors –In lab for next 2 weeks –Will help you with.
Chapter 7: Arrays. Outline Array Definition Access Array Array Initialization Array Processing 2D Array.
Agenda What is Computer Programming? The Programming Process
1 CSE 2341 Object Oriented Programming with C++ Note Set #1.
CSE 1340 Introduction to Computing Concepts Class 2.
CS105 Lab 1 – Introduction Section: ??? TA: ??? ??? Announcements CITES Accounts Compass Netfiles Other Administrative Information CS105 Fall
CS102 Introduction to Computer Programming Chapter 7 Arrays.
Welcome to CS 3260 Dennis A. Fairclough. Overview Course Canvas Web Site Course Materials Lab Assignments Homework Grading Exams Withdrawing from Class.
1 Today’s Objectives  Announcements Turn in Homework #1 Homework #2 is posted and it is due on 21-Jun  Review Quiz #1  Pointers and C-style strings.
C++ Arrays. Agenda What is an array? What is an array? Declaring C++ arrays Declaring C++ arrays Initializing one-dimensional arrays Initializing one-dimensional.
CS161 Topic #21 CS161 Introduction to Computer Science Topic #2.
CHAPTER 07 Arrays and Vectors (part I). OBJECTIVES 2 In this part you will learn:  To use the array data structure to represent a set of related data.
CS 114 – Class 02 Topics  Computer programs  Using the compiler Assignments  Read pages for Thursday.  We will go to the lab on Thursday.
1 ITI 1120 Lab # 1 An Introduction to the Lab Environment Contributors: G. Arbez, M. Eid, D. Inkpen, A. Williams, D. Amyot.
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.
Starting Out with C++, 3 rd Edition 1 Chapter 7 – Arrays.
Overview of Programming and Problem Solving Textbook Chapter 1 1.
COP3502: Introduction to Computer Science Yashas Shankar.
CSE 1340 Introduction to Computing Concepts Class 1 ~ Intro.
ARRAYS Lecture 2. 2 Arrays Hold Multiple values  Unlike regular variables, arrays can hold multiple values.
Principles of Computer Science I Honors Section Note Set 1 CSE 1341 – H 1.
Data Structures and Debugging Dr. Nancy Warter-Perez June 18, 2003.
Lecture 4 Looping. Building on the foundation Now that we know a little about  cout  cin  math operators  boolean operators  making decisions using.
CHAPTER 7 arrays I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
Operating Systems Session 1. Contact details TA: Alexander(Sasha) Apartsin ◦ ◦ Office hours: TA: Sasha Alperovich.
Pointers: Basics. 2 What is a pointer? First of all, it is a variable, just like other variables you studied  So it has type, storage etc. Difference:
Welcome to the MTLC MATH 115 Spring MTLC Information  Hours of Operation  Sunday:4:00pm – 10:00pm  Monday – Thursday: 8:00am – 10:00pm  Friday:8:00am.
 2003 Prentice Hall, Inc. All rights reserved. 1 Arrays Outline Introduction Arrays Declaring Arrays Examples Using Arrays.
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)
STARTING OUT WITH STARTING OUT WITH Class 3 Honors.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Arrays. The array data structure Array is a collection of elements, that have the same data type Integers (int) Floating point numbers (float, double)
1 Getting Started with C++ Part 2 Linux. 2 Getting Started on Linux Now we will look at Linux. See how to copy files between Windows and Linux Compile.
Starting Out with C++, 3 rd Edition Introduction to the STL vector The Standard Template Library (or STL) is a collection of data types and algorithms.
CS Class 15 Today  More practice with arrays  Introduction to Multi-dimensional arrays Announcements  Programming project #4 due 10/23 by midnight.
Lecture 14: Arrays Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
Arrays Chapter 12. Overview Arrays and their properties Creating arrays Accessing array elements Modifying array elements Loops and arrays.
Dayu Zhang 9/10/2014 Lab03. Outline Brief Review of the 4 Steps in Hello.cpp Example Understand endl and \n Understand Comment Programming Exercise -
Extra Recitations Wednesday 19:40-22:30 FENS L055 (tomorrow!) Friday 13:40-16:30 FENS L063 Friday 17: :30 FENS L045 Friday 19:40-22:30 FENS G032.
CSE 1340 Introduction to Computing Concepts Class 1 ~ Intro.
+ DGM 3870 Web Graphics (Photoshop) Bryce Newell, J.D.
1 Lecture 4: Part1 Arrays Introduction Arrays  Structures of related data items  Static entity (same size throughout program)
ICS 151 Digital Logic Design Spring 2004 Administrative Issues.
Current Assignments Project 3 has been posted, due next Tuesday. Write a contact manager. Homework 6 will be posted this afternoon and will be due Friday.
Windows Programming Lecture 03. Pointers and Arrays.
Linux CSE 1222 CSE1222: Lecture 1BThe Ohio State University1.
Guide to Using MYIBS Online Course Repository System using Claroline For IBS Students Only.
Chapter 7 – Arrays.
Chapter 2 Assignment and Interactive Input
Arrays Part-1 Armen Keshishian.
CSE1320 INTERMEDIATE PROGRAMMING
CSE1320 INTERMEDIATE PROGRAMMING
CS 1430: Programming in C++ Turn in your Quiz1-2 No time to cover HiC.
Arrays An array is a collection of variables that all have the same name and the same data type. Each member of the array is known as an element of the.
CSE1320 INTERMEDIATE PROGRAMMING
Welcome to Intro to C/C++ CISC 192
CSE1320 INTERMEDIATE PROGRAMMING
CSCE 206 Lab Structured Programming in C
Welcome to Intro to C/C++ CISC 192
Array What it is. How to use it How to declare it How to initialize it.
Presentation transcript:

STARTING OUT WITH STARTING OUT WITH Class 2

2 Review of course requirements: Homework due Thursday at beginning of class-- no lates accepted Programs are due Monday at 6pm of the week listed in your outline (program1.cpp, program1.out, program1.ppt and program1.doc or.txt); see webct for dates

3 Review of course requirements: Homework due Thursday at beginning of class-- no lates accepted Programs are due Monday at 6pm of the week listed in your outline (program1.cpp, program1.out, program1.ppt and program1.txt) ; see webct for dates

4 Review of course requirements: Incentives for coming to class lecture on Tuesdays and Thursdays –Unannounced quizzes –Unannounced fun logical quizzes and bonus opportunities given for getting back points lost on turned in homework assignment for that week –Interactive Class notes for classes 4-28 distributed

5 Review of course requirements: Must enroll in a lab Lab sessions are mandatory Pop Quizzes cannot be made up Homework cannot be made up Programs can be turned in late for 10 points off with special permission Make-up exams only given if documented excuse has been submitted BEFORE exam

6 Communication Office hours via –Please identify yourself Webct address – (use your 8 digit smu id for your userid and password)

7 Synchronization of passwords You can change your password in webct by going to your homepage and clicking on “change password” in the upper right- hand corner of the window. In Unix, the command to change your password is passwd

8 Submitting assignments Print out instructions in webct under the link “instructions for submitting assignments” Before sending in first programming assignment, practice with your program1 folder Those folders will have to be reset by your instructor next week so don’t put your real program their yet. Caution: once a file has been placed in your folder and submitted, the link on the folder goes away and you cannot resubmit so DO NOT try to submit your 4 files at different times. Be sure what you submit is what you WANT to submit because you cannot correct it and resubmit.

9 Using Unix and the vi editor You must connect to a unix server Be sure to do the Unix tutorial located on webct ( lessons 1,2,3 and 13) by the end of next week’s lab. You can begin the vi tutorial if you have time Next week, there will be a unix and vi quiz icon on webct. You can take those quizzes any time you feel ready. They must be taken by the end of the lab of the third week. The icon will go away then. The quizzes are password protected; when you click on the quiz, you will need to ask your ta to type in the password for you.

10 Using Unix and the vi editor Additional tutorials available at: tutorial.html AND Unix/UnixBareMn.html

11 Using Unix and the vi editor The command in unix to compile a c++ program: at the unix % prompt type g++ program1.cpp -o program1.out This is assuming that you have used an editor to create the program1.cpp file which has been saved in your unix home directory. To execute the program, at the unix prompt, type program1.out

12 Objectives Understand the one-dimensional data structure. Declare and initialize a one- dimensional array Refer to individual elements of an array. Understand the use of arrays to store a list of values. Pass arrays to functions.

13 int n[5] One-Dimensional Arrays = {32, n[0]n[1]n[2]n[3]n[4] ,64,18,95}; & n[0] n sizeof n would equal 20

14 One-Dimensional Arrays int x[5] = {32, 27}; 3227???

15 One-Dimensional Arrays int y[5] = {0}; 00000

16 One-Dimensional Arrays int z[5]; ????? z[0] = 5; 5???? z[4] = 3; 5???3 z[5] = 10; 5???3 10 Overlaying code / data

17 int x[3] = {9,11,13}; cout << x[0] << endl; cout << x[1] << endl; cout << x[2]) << endl; int x[3] = {9,11,13}; for (int i = 0; i<3; i++) cout << x[i] << endl; One-Dimensional Arrays

18 int x[3] = {9,11,13}; cout << x[0] << endl ; cout << x[1] << endl; cout << x[2] << endl; int x[3] = {9,11,13}; for (int i = 0; i<3; i++) cout << x[i] << endl; One-Dimensional Arrays

19 int x[3] = {9,11,13}; cout << x[0] << endl; cout << x[1] << endl; cout << x[2] << endl; 9 int x[3] = {9,11,13}; for (int i = 0; i<3; i++) cout << x[i] << endl; One-Dimensional Arrays

20 int x[3] = {9,11,13}; cout << x[0] << endl; cout << x[1] << endl; cout << x[2] << endl; 9 11 int x[3] = {9,11,13}; for (int i = 0; i<3; i++) cout << x[i] << endl; One-Dimensional Arrays

21 int x[3] = {9,11,13}; cout << x[0] << endl; cout << x[1] << endl; cout << x[2] << endl; int x[3] = {9,11,13}; for (int i = 0; i<3; i++) cout << x[i] << endl; One-Dimensional Arrays

22 int x[3] = {9,11,13}; cout << x[0] << endl; cout << x[1] << endl; cout << x[2] << endl; Value of i int x[3] = {9,11,13}; for (int i = 0; i<3; i++) cout << x[i] << endl; One-Dimensional Arrays

23 int x[3] = {9,11,13}; cout << x[0] << endl; cout << x[1] << endl; cout << x[2] << endl; Value of i 0 int x[3] = {9,11,13}; for (int i = 0; i<3; i++) cout << x[i] << endl; One-Dimensional Arrays

24 int x[3] = {9,11,13}; cout << x[0] << endl; cout << x[1] << endl; cout << x[2] << endl; Value of i 0 9 int x[3] = {9,11,13}; for (int i = 0; i<3; i++) cout << x[i] << endl; One-Dimensional Arrays

25 int x[3] = {9,11,13}; cout << x[0] << endl; cout << x[1] << endl; cout << x[2] << endl; Value of i 0 9 int x[3] = {9,11,13}; for (int i = 0; i<3; i++) cout << x[i] << endl; 1 One-Dimensional Arrays

26 int x[3] = {9,11,13}; cout << x[0] << endl; cout << x[1] << endl; cout << x[2] << endl; Value of i 1 9 int x[3] = {9,11,13}; for (int i = 0; i<3; i++) cout << x[i] << endl; 11 One-Dimensional Arrays

27 int x[3] = {9,11,13}; cout << x[0] << endl; cout << x[1] << endl; cout << x[2] << endl; Value of i 1 9 int x[3] = {9,11,13}; for (int i = 0; i<3; i++) cout << x[i] << endl; 2 11 One-Dimensional Arrays

28 int x[3] = {9,11,13}; cout << x[0] << endl; cout << x[1] << endl; cout << x[2] << endl; Value of i 2 9 int x[3] = {9,11,13}; for (int i = 0; i<3; i++) cout << x[i] << endl; One-Dimensional Arrays

29 int x[3] = {9,11,13}; cout << x[0] << endl; cout << x[1] << endl; cout << x[2] << endl; Value of i 2 9 int x[3] = {9,11,13}; for (int i = 0; i<3; i++) cout << x[i] << endl; One-Dimensional Arrays

30 Write a for loop to initialize all the elements in a 20 integer array ‘values’ to zero. int values[20]; Begin for loop Initialize counter Set limit for counter Increment counter Initialize element in array ‘values’ for ( ) values[i]=0; int i=0;i<20;i++

31 Write a program that asks the user for the number of hours worked by 6 employees. Save these hours in an array. float Hours[6]; Begin for loop Initialize counter Set limit for counter Increment counter Read hours into next element of array for ( ) cin >> Hours[i]; int i=0;i<6;i++ cout << “enter hours for” << “six employees”; PG 402 ~ Pgrm. 7-2

32 Write a program that initializes an array to the days of each month and displays those days. int Days[12]={31,28,31,30, 31,30,31,31, 30,31,30,31); Initialize array Initialize counter Set limit for counter Increment counter Display each next element of array for (int i=0; i < 12; i++) { cout << “Month” << << (i + 1) << <<Days[i];} Begin for loop PG 408 ~ Pgrm. 7-6

33 char n[7]=“Warren”; n[0]n[1]n[2]n[3]n[4] WARRE & n[0] n sizeof n would equal 7 n[5]n[6] char Name1[ ]={‘W’,’A’,’R’,’R’,’E’,’N’,’\0’}; // OR N\0 One-Dimensional Arrays char Name1[ ]={‘W’,’A’,’R’,’R’,’E’,’N’,’\0’};

34 char n[7]=“WARREN”; cout << n; for (int x=0; x < 7; x++) cout << n[x]; ONE WAY TO DISPLAY WARREN ANOTHER WAY TO DISPLAY WARREN PG 412 ~ Fig One-Dimensional Arrays

35 Passing Arrays to Functions void ShowValue(int); int main() {int Collection[8] = {5,10,15,20,25,30,35,40}; } for (int Cycle =0; Cycle < 8; Cycle++) ShowValue (Collection[Cycle]); // pass by return 0; } // value void ShowValue(int Num) { cout << Num << “ “;} PG 425 ~ Pgrm. 7-13

36 void ShowValues(int [ ]); main() {int Collection[8] = {5,10,15,20,25,30,35,40}; } ShowValues (Collection); // pass by return 0; } // reference void ShowValues(int Nums[ ]) { for (int Index = 0; Index < 8; Index++) cout << Nums[Index] << “ “;} PG 427 ~ Pgrm Passing Arrays to Functions

37 void DoubleArray(int Nums[ ], int Size) { for ( int Index = 0; Index < Size; Index++) Nums[Index] * = 2; } Set int main() { int Set[12]={1,2,3,4,5,6,7,8,9,10,11,12}; DoubleArray(Set,12); return 0; } Passing Arrays to Functions PG 429 ~ Pgrm. 7-16

38 void DoubleArray(int Nums[ ], int Size) { for ( int Index = 0; Index < Size; Index++ Nums[Index] *=2; } Set int main() { int Set[12]={1,2,3,4,5,6,7,8,9,10,11,12}; DoubleArray(Set,12); rturn 0; } Passing Arrays to Functions Set &Set[0] PG 429 ~ Pgrm. 7-16

39 void modifyElement (int e) { e *= 5; cout << e;} a e No change in array in main int main () { int a[5]={0,1,2,3,4}; modifyElement(a[3]); return 0; } //pass 1 element by value Passing Arrays to Functions

40 void modifyElement (int e) { e *= 5; cout << e;} a e No change in array in main int main () { int a[5]={0,1,2,3,4}; modifyElement(a[3]); return 0; } //pass 1 element by value 15 Passing Arrays to Functions

41 PARALLEL ARRAYS int main() { int Hours[5]; float PayRate[5]; cout << “Enter hours worked” << “by 5 employess and their” << “hourly rates.\n”; PG 422 ~ Pgrm. 7-12

42 cout << “Enter hourly pay rate for employee #” cout << (Index +1); cin >> PayRate[Index]; } // end of for loop Hours PayRate for (int Index =0; Index < 5; Index++) { cout << “hours worked by employee #” << (Index + 1); cin >> Hours[Index]; PG 42 ~ Pgrm. 7-12

43 PARALLEL ARRAYS for (Index =0; Index < 5; Index++) { float GrossPay = Hours[Index] * PayRate[Index]; cout << “Employee #” << (Index + 1); cout << GrossPay << endl;} Hours PayRate PG 422 ~ Pgrm. 7-12

44 PARALLEL ARRAYS EXERCISE #7.13 P. 425 What is the output of the following program? void main(void) { int Time[5] = {1,2,3,4,5}, Speed[5] = {18,4,27,52,100}, Dist[5]; for(int Count =0; Count < 5; Count++) Dist[Count] = Time[Count] * Speed[Count]; for (Count = 0; Count < 5; Count ++) cout << Time[Count] << Speed[Count] << Dist[Count];

45 Copying arrays The wrong way: int array1[4] = {2,4,6,9}; int array2[4]; array2 = array1; // syntax error because // left side is a constant pointer // created when the array was declared

46 Copying arrays The right way, one element at a time: int array1[4] = {2,4,6,9}; int array2[4]; for (int I = 0; I < 4; I++) array2[I] = array1[I];

47 PARALLEL ARRAYS IN CLASS EXERCISE Forty students were asked to rate the quality of the food in the student cafeteria on a scale of 1 to 10 (1 means awful and 10 means excellent). Place the 40 responses in an integer array and summarize the results of the poll in another integer array.

48 int responses[40]; int frequency[11]; // do not use position 0 If 10 students respond with a 2 5 students respond with a respond with a 7 3 students respond with a 6 2 students respond with a 1 frequency array

49 int main() { int responses[40]; int frequency[11]; cout << “enter 40 student responses” << “ from 1 to 10” <<endl; for (int j=0; j< 40; j++) cin >> responses[j]; for ( j =0; j < 40; j++) ++ frequency[responses[j]];} for ( int k=1; k < 11; k++) cout << “rating #” << k << “had” << frequency[k] << “responses”;

STARTING OUT WITH STARTING OUT WITH Conclusion of Class 2