What If? Write a program that prompts for the names and locations of 1000 employees. Store the information in the program for later use.

Slides:



Advertisements
Similar presentations
Introduction to Programming Lecture 15. In Today’s Lecture Pointers and Arrays Manipulations Pointers and Arrays Manipulations Pointers Expression Pointers.
Advertisements

1 Arrays Chapter 9. 2 Outline  The array structure (Section 9.1)  Array declaration  Array initialization  Array subscripts  Sequential access to.
LECTURE 1 CMSC 201. Overview Goal: Problem solving and algorithm development. Learn to program in Python. Algorithm - a set of unambiguous and ordered.
1 CS 105 Lecture 11 Arrays Version of Wed, Apr 6, 2011, 6:20 pm.
While Loops Programming. COMP102 Prog Fundamentals I: while Loops/Slide 2 Shortcut Assignments l C++ has a set of shortcut operators for applying an operation.
Arrays Programming COMP102 Prog. Fundamentals I: Arrays / Slide 2 Arrays l An array is a collection of data elements that are of the same type (e.g.,
1 CS 105 Lecture 8 Strings; Input Failure Mon, Mar 7, 2011, 3:39 pm.
1 CS 105 Lecture 12 Pass- By-Reference, 2-D Arrays Version: Wed, Apr 20, 2011, 6:25 pm.
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
1 CS 105 Lecture 4 Selection Statements Wed, Jan 26, 2011, 6:05 pm.
Chapter 8. 2 Objectives You should be able to describe: One-Dimensional Arrays Array Initialization Arrays as Arguments Two-Dimensional Arrays Common.
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
1 11/8/06CS150 Introduction to Computer Science 1 Arrays Chapter 8 page 477 November 13, 2006.
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.
C++ for Engineers and Scientists Third Edition
CSE202: Lecture 14The Ohio State University1 Arrays.
Wednesday, 11/6/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 11/6/02  QUESTIONS?? – HW # 4 due Monday  Today:  Return HW #3  Arrays (Chap. 10)  Reading:
Loops Programming. COMP104 Lecture 9 / Slide 2 Shortcut Assignment l C++ has a set of operators for applying an operation to a variable and then storing.
Crypto Project Sample Encrypted Data: –Turing: CS Public\CryptoProjectData Crypto_Short_Keys_P_U.out Crypto_Long_Keys_O_R.out Bonus +10 points on.
1 CS 1430: Programming in C++. 2 Literal Values Literal values of int Literal values of float
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.
1 C++ Programming Basics Chapter 2 Lecture CSIS 10A.
1 CS 1430: Programming in C++. 2 IF Statement if (cond) statement //Next statement if (cond) { statement1 statement2 … } //Next statement.
Previously Repetition Structures While, Do-While, For.
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
C++ for Engineers and Scientists Second Edition Chapter 11 Arrays.
Current Assignments Start Reading Chapter 6 Project 3 – Due Thursday, July 24 Contact List Program Homework 6 – Due Sunday, July 20 First part easy true/false.
Monday, Mar 31, 2003Kate Gregory with material from Deitel and Deitel Week 12 Labs 4 and 5 are back File IO Looking ahead to the final.
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)
Section 5 - Arrays. Problem solving often requires information be viewed as a “list” List may be one-dimensional or multidimensional List is implemented.
Chapter 2: Introduction to C++. Language Elements Keywords Programmer-defined symbols (identifiers) Operators Punctuation Syntax Lines and Statements.
Introduction to C Programming Lecture 6. Functions – Call by value – Call by reference Arrays Today's Lecture Includes.
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.
Arrays. Related data items Collection of the same types of data. Static entity – Same size throughout program.
1 One Dimensional Arrays Chapter 11 2 "All students to receive arrays!" reports Dr. Austin. Declaring arrays scores :
1 Arrays and Strings Lecture: Design Problem l Consider a program to calculate class average Why?? ?
Before we get started…. First, a few things… Weighted Grading System Programming Style Submitting your assignments… The char and string variable types.
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 09/27/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 6 Arrays.
CMPSC 121- Spring 2015 Lecture 6 January 23, 2015.
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
Module 1: Array ITEI222 - Advance Programming Language.
Exam 2 EXAM 2 Thursday!!! 25% of Final Grade Know: loops, switch/case Files Input failure (e.g. scan.hasNextInt())
Computer Programming Arrays 1. Question #1 2 Question Choose the correct answer..
Chapter 4 Repetition Statements Program Development and Design Using C++, Third Edition.
Lecture 2 Arrays. Topics 1 Arrays hold Multiple Values 2 Accessing Array Elements 3 Inputting and Displaying Array Contents 4 Array Initialization 5 Using.
Introduction to programming in java Lecture 21 Arrays – Part 1.
Data Storage So far variables have been able to store only one value at a time. What do you do if you have many similar values that all need to be stored?
Objectives You should be able to describe: One-Dimensional Arrays
A FIRST BOOK OF C++ CHAPTER 7 ARRAYS. OBJECTIVES In this chapter, you will learn about: One-Dimensional Arrays Array Initialization Arrays as Arguments.
while Repetition Structure
Multi-dimensional Array
Quiz Next Monday.
What If? Write a program that prompts for the names and locations of 1000 employees. Store the information in the program for later use.
Variables with Memory Diagram
CS 1430: Programming in C++ Turn in your Quiz1-2 No time to cover HiC.
One-Dimensional Array Introduction Lesson xx
Know for Quiz Everything through Last Week and Lab 7
File Review Declare the File Stream Object Name
Arrays Syntax: type variableName[size];
CS150 Introduction to Computer Science 1
Let’s all Repeat Together
CS150 Introduction to Computer Science 1
(Dreaded) Quiz 2 Next Monday.
CS31 Discussion 1D Winter19: week 4
What If? Write a program that prompts for the names and locations of 1000 employees. Store the information in the program for later use.
Announcements Exam 2 Lecture Grades Posted on blackboard
Presentation transcript:

What If? Write a program that prompts for the names and locations of 1000 employees. Store the information in the program for later use.

Program for Previous string empName1, empName2, empName3,… string empLocation1, empLocation2, … cout << “Enter employee name 1:”; cin >> empName1; cout << “Enter Employee name 2:”; cin >> empName2; … //Can we use a loop?

Arrays Syntax: type variableName[ size ]; Memory Is Set Aside for size Items of type Each Variable Location in Array Is Accessed by Offsetting into the Array with an Integer Expression Legitimate Offsets Are 0 to size-1 Example: lastname[0] = ‘H’;

Array Example char lastname[100]; lastname[0] = ‘H’; lastname[1] = ‘a’; lastname[2] = ‘\0’; cout << lastname[0]; cout << lastname;

Array Example int values[15], i = 0; values[i] = 150; values[i + 1] = 78; i = 2; values[i] = 16; cout << values[0]; values[3] = values[0] + 6;

Array Example const int ARRAY_SIZE = 100; int offset; int numArray[ARRAY_SIZE]; for(offset = 0; offset < ARRAY_SIZE; offset++) { numArray[offset] = 0; }

Array Example const int ARRAY_SIZE = 10; int offset, sum = 0, average; int numArray[ARRAY_SIZE]; for(offset = 0; offset < ARRAY_SIZE; offset++) { cout << “Enter Score ” << offset << “ : “; cin >> numArray[offset]; } for(offset = 0; offset < ARRAY_SIZE; offset++) { sum = sum + numArray[offset]; } average = sum / ARRAY_SIZE;

Exam 2 EXAM 2 Lecture Portion Next Monday 20% of Final Grade Know: –loops, switch/case –Files (.open(), >> and <<,.close() ) –Input Failure (cin, cin.clear(), cin.ignore()) –Functions –Arrays

Project Posted on blackboard under Tasks Due Wednesday of Finals week at Noon Central Time Hand in to your TA (NOT me!) –.cpp (source code), –.txt (Data file runwaycs105.txt), –.doc (Analysis) Pseudocode!!!!! Design before Coding!!!! Start *TODAY*!!!!

Project Do’s Start this week (read project at least) Write Pseudocode (EVERYBODY) Review All cs105 Concepts – Do Well on Final Exam Feel Good about Yourself Explore Your “Inner Geek”

Don’t’s No Working Together Write Your Own Code!!! Checked by Supercomputer May be Called in to Discuss Program Last Term – 10 Investigated, 7 0s, 1 probation Nine terms (74 investigated, 44 received 0s)

Initializing Arrays int main() { char cArray3[5] = {'a', 'b', 'c'}; int iArray[] = {1, 2, 3, 4}; int iArray2[10] = {10, 13, 15, 17}; double dArray[] = {3.4, 5.67e4}; double dArray1[5] = {6.7, 7.8, 9.5}; }

Initializing string Arrays #include using namespace std; int main() { string sArray[] = {"one", "two", "three"}; cout << sArray[0]; }

Two Dimensional Arrays char cArray[10][20]; int iArray[100][50]; cArray[0][0] = ‘a’; cArray[0][1] = ‘b’; cArray[9][19] = ‘x’; iArray[0][0] = 99; iArray[1][5] = 135; iArray[99][49] = 0;