Computer Science II Exam I Review Monday, February 6, 2006.

Slides:



Advertisements
Similar presentations
Chapter 7: User-Defined Functions II
Advertisements

C++ Programming: Program Design Including Data Structures, Third Edition Chapter 7: User-Defined Functions II.
VBA Modules, Functions, Variables, and Constants
Wednesday, 12/11/02, Slide #1 CS 106 Intro to Comp. Sci. 1 Wednesday, 12/11/02  QUESTIONS??  Today: CLOSING CEREMONIES!  HW #5 – Back Monday (12/16)
Wednesday, 10/9/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 10/9/02  QUESTIONS ??  Today:  Discuss HW #02  Discuss test question types  Review 
Chapter 6 C Arrays Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc. Arrays are data structures.
Monday, 11/18/02, Slide #1 CS 106 Intro to CS 1 Monday, 11/18/02  QUESTIONS??  Today:  Hand back, discuss HW #4  Discussion of Lab 10  Exam #2 Friday.
Chapter 11: Classes and Data Abstraction
C++ for Engineers and Scientists Third Edition
COMP1170 Midterm Preparation (March 17 th 2009) Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education.
Java Unit 9: Arrays Declaring and Processing Arrays.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
Programming Languages -1 (Introduction to C) arrays Instructor: M.Fatih AMASYALI
 2006 Pearson Education, Inc. All rights reserved Arrays.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Classes: A Deeper Look Part.
Chapter 6: User-Defined Functions
Project 1 Due Date: September 25 th Quiz 4 is due September 28 th Quiz 5 is due October2th 1.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 6 l Array Basics l Arrays and Methods l Programming with Arrays.
Chapter 11: Classes and Data Abstraction. C++ Programming: Program Design Including Data Structures, Fourth Edition2 Objectives In this chapter, you will:
Learners Support Publications Classes and Objects.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
C++ for Engineers and Scientists Second Edition Chapter 11 Arrays.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
1 Chapter Four Creating and Using Classes. 2 Objectives Learn about class concepts How to create a class from which objects can be instantiated Learn.
Chapter 9 Classes: A Deeper Look, Part I Part II.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
1 Chapter 7 Arrays. 2 Topics 7.1 Arrays Hold Multiple Values 7.2 Accessing Array Elements 7.3 No Bounds Checking in C Array Initialization 7.5 Processing.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 6 Functions.
 2003 Prentice Hall, Inc. All rights reserved. 1 Vectors.
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
EGR 2261 Unit 11 Classes and Data Abstraction  Read Malik, Chapter 10.  Homework #11 and Lab #11 due next week.  Quiz next week.
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessor Midterm Review Lecture 7 Feb 17, 2004.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Chapter Functions 6. Modular Programming 6.1 Modular Programming Modular programming: breaking a program up into smaller, manageable functions or modules.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 12: Classes and Data Abstraction.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 11: Classes and Data Abstraction.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 05: Classes and Data Abstraction.
CPS120: Introduction to Computer Science Lecture 16 Data Structures, OOP & Advanced Strings.
Array in C++ / review. An array contains multiple objects of identical types stored sequentially in memory. The individual objects in an array, referred.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
Chapter 1 C++ Basics Review (Section 1.4). Classes Defines the organization of a data user-defined type. Members can be  Data  Functions/Methods Information.
CSE 332: C++ pointers, arrays, and references Overview of Pointers and References Often need to refer to another object –Without making a copy of the object.
Struct s (7.4) Used as data aggregates for an entity can be different types of data e.g. for student id, name, GPA, address,... Similar to classes, but.
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.
C++ Programming Lecture 14 Arrays – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Lecture 4 – Function (Part 1) FTMK, UTeM – Sem /2014.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
SEQUENTIAL AND OBJECT ORIENTED PROGRAMMING Arrays.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Defining Data Types in C++ Part 2: classes. Quick review of OOP Object: combination of: –data structures (describe object attributes) –functions (describe.
Motivation and Overview
C Basics.
7 Arrays.
Andy Wang Object Oriented Programming in C++ COP 3330
Classes and Objects.
1-6 Midterm Review.
Andy Wang Object Oriented Programming in C++ COP 3330
Instructor: Dr. Michael Geiger Spring 2019 Lecture 13: Exam 1 Preview
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Review for Midterm 3.
4.1 Introduction Arrays A few types Structures of related data items
Presentation transcript:

Computer Science II Exam I Review Monday, February 6, 2006

Material Coverage - Lectures LectureDateCoverageReading 11/17 Intro & Background K&M: Chap 0 Malik: see Lec Notes 21/20 Background II Chap 0 31/24 Strings Chap 1,2 41/27 Vectors Chap 3 51/31 C++ Classes I Chap , Chap 9 62/3 C++ Classes II Chap , Chap 9

Material Coverage - Lab/HWDateCoverage Lab 11/18 Getting Started Lab 21/25 Strings, Files, and Command Line Arguments Lab 32/1 C++ Classes HW 1 Due 1/26 Getting Started HW 2 Due 2/2 Moire Strings Labs & HW

Background Review Know basic syntax comments included files (why?) main is necessary for all programs expressions (Chap 2 of Malik book) variables, objects, types, constants #include // asks compiler for parts of std lib int main( ) { std::cout << “Hello, world!” << std::endl; return 0; }

Statement single statement ending with ; structured statement (i.e. else if) compound statement delimited by {…} Review statements, expressions, and assignments

Arrays fixed consecutive sequence of objects all of the same type indexing starts at 0 are a fixed size programmer’s responsibility to prevent overflow constant arrays are similar to constant variables – once initialized they cannot be altered

Functions and Arguments Why use them? each has parameters and a return type (including main!) order of parameters matters

More Background Review Loop syntax for: for loops while loops Loop invariant logical assertion that is true at start of each iteration of a loop stated as comment helps analyzing code switch statements If and else statements &&, ||, %, and other operators

Background Review II What is the difference between a function prototype (declaration) and definition? What is one way to return multiple results from a function?

Parameters to Functions Value parameter local variable in function initial value is copy of argument value changes in function do not affect corresponding argument in calling function Reference parameter alias for corresponding argument (not a new variable) changes do affect corresponding variables in calling function

Arrays are tricky Changes made to an array are permanent, even if passed as value parameters Why? Pass by value the memory location of the base address of the array

Scope of an identifier (name) is the part of the program in which it has meaning { } establishes a new scope scopes may be nested identifiers may be reused as long as they are in different scopes those with same name in inner scope hide those in outer scope :: establishes scope as well

Order Notation Can compare why one algorithm is better than another (usually using worst case analysis) O(1) O(log n) O(n) O(n log n) O(n 2 ) O(n k ) O(2 n )

Strings object type defined in std lib to contain sequence of characters like all types, string type defines an interface construction (initialization) operations functions (methods) other types

More about strings Constructing string objects By default (create an empty string) string name; With a specified number of instances of a single character string stars(10, ‘*’); From another string string sentence = “I see stars ” + stars; string name(“Bettina”); L-value vs. R-value

Some member functions size() length() size_type vs. unsigned int vs. int + operator concatenates two strings to create a third = assignment operation overwrites current contents of string strings behave like arrays when using [] operator

Vector Ideal for storage of items when you don’t know how many values there will be in advance std lib container class acts like a dynamically-size 1D array holds objects of any type (must all be same type) starts empty unless otherwise specified no limit on size can use subscripting [] operator no automatic checking of [] bounds

Templated Container Class Vectors are an example <> are used to specify type of object (template type) to be stored in vector vector grades; vector names; vector temperatures;

Some member functions push_back() O(1) on average size() begin() end() [] operator (like with arrays)

More about vectors Constructing vectors By default an empty vector vector a; With a specified number of instances of a single object vector b(100, 3.14); With a specified number of instances with no initial value vector c(100); From another vector (of same type!) vector d(b);

Sort std lib function that deals with container classes Sorts values from least to greatest if no sorting function supplied sort(a.begin(), a.end()); uses < operator on objects in vector Can specify your own comparison function sort(a.begin(), a.end(), IsEarlierThan); sort(a.begin(), a.end(), IsLaterThan);

Vectors and Strings as Parameters Options: pass by reference pass by value (expensive!) pass by constant reference Note: This is unlike arrays which are never pass by value

Classes Defining a new type Structure of memory within each class object Set of operations defined C++ classes consist of: collection of member variables (private) collection of member functions (public) public: can be accessed directly from outside the class private: can only be accessed indirectly through public member functions

Classes Continued Each object of a class created has its own distinct member variables Call member functions using dot notation tomorrow.print(); main.cpp.cpp file for member function definitions (implementation file).h file for class declaration (header file) include.h file in the two.cpp files above

More on classes class scope :: member functions and variables are accessible without name of object constructors special functions that initialize values of member variables only called once per object default constructor has no arguments multiple allowed copy constructor automatically created

Member functions Defined within class scope Same as before but modify object’s member variables Can call member functions without using object name Functions which are not members of the class must use public member functions wrt an object of that class

Constant Member Functions Member functions that do not change the member variables should be declared as this bool Date::isEqual(const Date &date2) const; const must appear in both class declaration (.h) and member function definition (.cpp) const objects can only use const member functions

Struct What is it? Class where default protection is public, not private

Non-member operators not declared/defined in class scope but the arguments to the function are class objects Examples: operator< operator+ IsEarlierThan

Exam 1 Tomorrow, Tuesday February 7 10 – 11:50am West Hall Auditorium Closed book and closed notes except for 1 sheet of 8.5 x 11 paper Bring your RPI ID!!

Questions?