Final Review Ying Wu Electrical Engineering & Computer Science Northwestern University EECS 230 Lectures Series.

Slides:



Advertisements
Similar presentations
Lecture 6 Sept 11, 2008 Goals for the day: Linked list and project # 1 list class in STL (section 3.3) stack – implementation and applications.
Advertisements

Constructor. 2 constructor The main use of constructors is to initialize objects. A constructor is a special member function, whose name is same as class.
Introduction to Programming Lecture 39. Copy Constructor.
Pointers Revisited l What is variable address, name, value? l What is a pointer? l How is a pointer declared? l What is address-of (reference) and dereference.
1 Linked List (II) Ying Wu Electrical Engineering & Computer Science Northwestern University EECS 230 Lectures Series.
1 Pointers A pointer variable holds an address We may add or subtract an integer to get a different address. Adding an integer k to a pointer p with base.
1 Classes with Pointer Data Members (II) Ying Wu Electrical Engineering & Computer Science Northwestern University EECS 230.
CS 106 Introduction to Computer Science I 12 / 04 / 2006 Instructor: Michael Eckmann.
Wrap Up and Misc Ying Wu Electrical & Computer Engineering Northwestern University ECE230 Lectures Series.
@ Zhigang Zhu, CSC212 Data Structure - Section FG Lecture 8 Dynamic Classes and the Law of the Big Three Instructor: Zhigang Zhu Department.
1 Array, Pointer and Reference ( III ) Ying Wu Electrical Engineering & Computer Science Northwestern University ECE230 Lectures.
CIS 101: Computer Programming and Problem Solving Lecture 8 Usman Roshan Department of Computer Science NJIT.
Dynamic Objects. COMP104 Dynamic Objects / Slide 2 Memory Management * Static Memory Allocation n Memory is allocated at compiling time * Dynamic Memory.
1 String Library and Stream I/O Ying Wu Electrical Engineering & Computer Science Northwestern University ECE230 Lectures Series.
Reviews for Exam 1 Chapter 1-4 CS 211 Data Structures MHC, 2007.
1 Array, Pointer and Reference ( IV ) Ying Wu Electrical Engineering & Computer Science Northwestern University EECS 230 Lectures.
Array, Pointer and Reference ( V ) Ying Wu Electrical & Computer Engineering Northwestern University ECE230 Lectures Series.
1 Midterm Review Ying Wu Electrical Engineering & Computer Science Northwestern University EECS230 Lectures Series.
1 Constructors and Destructors Ying Wu Electrical Engineering & Computer Science Northwestern University ECE230 Lectures Series.
1 Dynamic Memory Allocation Ying Wu Electrical Engineering & Computer Science Northwestern University EECS 230 Lectures Series.
1 Array, Pointer and Reference ( I ) Ying Wu Electrical Engineering and Computer Science Northwestern University EECS 230 Lectures.
Review on pointers and dynamic objects. Memory Management  Static Memory Allocation  Memory is allocated at compiling time  Dynamic Memory  Memory.
Department of Computer Science and Engineering, HKUST 1 HKUST Summer Programming Course 2008 Linked List and Namespace ~ include dynamic objects.
COMP1170 Midterm Preparation (March 17 th 2009) Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education.
Linked List (I) Ying Wu Electrical & Computer Engineering Northwestern University ECE230 Lectures Series.
ECE230 Course Introduction Ying Wu Electrical & Computer Engineering Northwestern University ECE230 Lectures Series.
More Classes in C++ Bryce Boe 2012/08/20 CS32, Summer 2012 B.
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look.
Lecture No.01 Data Structures Dr. Sohail Aslam
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Custom Templatized Data Structures.
This set of notes is adapted from that provided by “Computer Science – A Structured Programming Approach Using C++”, B.A. Forouzan & R.F. Gilberg, Thomson.
Game Programming in Java Dr. Jeyakesavan Veerasamy CS faculty, The University of Texas at Dallas Website:
1 Debugging: Catching Bugs ( II ) Ying Wu Electrical Engineering & Computer Science Northwestern University EECS 230 Lectures.
CS212: Object Oriented Analysis and Design Lecture 7: Arrays, Pointers and Dynamic Memory Allocation.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 26: Exam 2 Preview.
March 6, 2014CS410 – Software Engineering Lecture #10: C++ Basics IV 1 Structure Pointer Operator For accessing members in structures and classes we have.
Constructors CMSC 202. Object Creation Objects are created by using the operator new in statements such as… The following expression invokes a special.
Array, Pointer and Reference ( I ) Ying Wu Electrical & Computer Engineering Northwestern University ECE230 Lectures Series.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures C++ Review Part-I.
CS Midterm Study Guide Fall General topics Definitions and rules Technical names of things Syntax of C++ constructs Meaning of C++ constructs.
Lists II. List ADT When using an array-based implementation of the List ADT we encounter two problems; 1. Overflow 2. Wasted Space These limitations are.
Data Structures Using C++1 Chapter 3 Pointers and Array-Based Lists.
Pointers and Dynamic Memory Allocation Copyright Kip Irvine 2003, all rights reserved. Revised 10/28/2003.
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
CPSC 252 The Big Three Page 1 The “Big Three” Every class that has data members pointing to dynamically allocated memory must implement these three methods:
Function ( I ) Ying Wu Electrical & Computer Engineering Northwestern University ECE230 Lectures Series.
Introduction to C Programming Lecture 6. Functions – Call by value – Call by reference Arrays Today's Lecture Includes.
Edgardo Molina, CSC212 Data Structure - Section AB Lecture 8 Dynamic Classes and the Law of the Big Three Instructor: Edgardo Molina Department.
1 EECS230 Course Introduction and a First Program Ying Wu Electrical Engineering and Computer Science Northwestern University
CMSC 202 Advanced Section Classes and Objects: Object Creation and Constructors.
LECTURE LECTURE 11 Constructors and destructors Copy constructor Textbook: p , 183.
Xiaoyan Li, CSC211 Data Structures Lecture 8 Dynamic Classes and the Law of the Big Three Instructor: Prof. Xiaoyan Li Department of Computer Science.
1 2 2 Call The Project Dynamic-Memory 4 4 # include "Utilities.hpp" int main(int argc, char * argv[]) { short int *PtrNo; (*PtrNo) = 5; printf ("(*PtrNo)
Data Structures in C++ Pointers & Dynamic Arrays Shinta P.
Memory Management in Java Mr. Gerb Computer Science 4.
Pointers and References. Pointers & Memory 0x000x040x080x0B0x100x140x180x1B0x20.
On dynamic memory and classes ● We previously had only discussed dynamic memory in regards to structs and dynamic arrays. ● However, they can be used (to.
CISC181 Introduction to Computer Science Dr
Chapter 1-4 CSc 212 Data Structures, Sec AB CCNY, Spring 2012
Pointers Revisited What is variable address, name, value?
Memberwise Assignment / Initialization
This pointer, Dynamic memory allocation, Constructors and Destructor
The Bag and Sequence Classes with Linked Lists
Indirection.
Summary: Abstract Data Type
Dynamic Objects.
Data Structures & Algorithms
CS410 – Software Engineering Lecture #5: C++ Basics III
Dynamic allocation (continued)
Instructor: Dr. Michael Geiger Spring 2019 Lecture 23: Exam 2 Preview
Presentation transcript:

Final Review Ying Wu Electrical Engineering & Computer Science Northwestern University EECS 230 Lectures Series

About EECS 230 The goal –Getting a good glimpse of C/C++ programming –Learning a real useful programming language –Understanding software design –Accumulating experience –Becoming a junior programmer What I want to concentrate –Familiarizing C/C++ syntax –Understanding important and core C/C++ concepts –Grasping a tool, i.e., the Debugger –Finding the best way for further study What are beyond –Data structure –Compiler and OS –Algorithms –Architecture

Grading Scale MPs and exams [MPs Midterm Final] [30% 30% 40%] The weights for MPs [MP#1, MP#2, MP#3, MP#4, MP#5, MP#6, MP#7, MP#8] [ 3% 3% 3% 5% 4% 4% 4% 4% ] Grade scale A/A-> 40% B+/B/B-> 45% C+/C/C-< 15% Dyou can figure it out!

CTEC survey Please fill the CTEC survey Our course number: EECS Instructor: –Professor Ying Wu TAs are: –Ming Yang –David Choffnes –Yao Zhao

What we’ve learned (I) Basic C/C++ syntax –Data type –Control if, if/else, switch, while, do/while, for –Pointer, array, reference –Function –C++ Class

What we’ve learned (II) Basic C/C++ concepts –Function Call-by-value vs. call-by-reference What can be returned and what can not be return? –Array and pointers Relationship? (similarity and dissimilarity) Data in memory –Local variable and scope (life-cycle) –Pointers and references What is reference? Why is it special? Point arithmetic –static –Const

What We’ve learned (III) Advanced C++ concepts –Dynamic Memory Allocation –Classes with pointer data members –Copy constructor –Operator overloading –Constructors/destructors When constructors and destructors are called –Linked list

About Final exam Date: March 16 th (Fri) 9 – 11 am Place: Tech LR4 Content: –Several straightforward problems –Read code and write results –Write code For your benefits –Be extremely careful –Write down your intermediate results (as more as you can) for partial credits

Let’s Warm up … Questions 1: int a = 2, b = 4, c; c = (++a >= 3 ? b -- : b ++); Then a = ? b = ? c = ? Questions 2: int a = 2, b = 0, c = 0; While ( a < 4){ b += c ++; a ++; } Then a = ? b = ? c = ?

2D pointers Important Concepts int *p1; –p1 is a pointer –What does p1 point to? Can be an integer Can be an integer array and we can index by p1[n]. Here p1[n] is an integer int **p2; –p2 is a pointer –What does p2 point to? Can be a pointer pointing to an integer Can be an array of pointers and we can index by p2[n]. Here p2[n] is a pointer! Therefore, p2[n] can point to an integer or an integer array.

int a = 8; int *pa = &a; int **ppa = &pa; Question: [1] (*pa) = ? [2] (**ppa) = ?

int *pa = new int [3];

int **ppa = new int* [3]; for(int k=0;k<3;k++) ppa[k] = new int [3]; Question: (1) ppa[1] = ? (2) ppa[1][2] = ? (3) ppa + 2 = ?

Example: Table I want to implement a general table class, which holds any size of row/column. How can I construct such a table? What should we do for the constructor and destructor?

class CTable() { int **m_pData; int m_nRow; int m_nCol; public: CTable(int r = 1, int c = 1); ~CTable(); … };

CTable::CTable(int r, int c) { assert(r>0 && c>0); m_nRow = r; m_nCol = c; m_pData = new int *[m_nRow]; assert(m_pData != NULL); for(int k=0; k<m_nRow; k++){ m_pData[k] = new int [m_nCol]; assert(m_pData[k] != NULL); }

CTable::~CTable() { for(int k=0; k<m_nRow; k++) delete [] m_nData[k]; delete [] m_nData; }

Local variable and scope int myfunc(int a, int& b) { int c; c = a + b; return c; } Questions: What are the exact stuff passed to the function? What happen to the memory when executing into the function ? What are the exact stuff return from the function? What can NOT be returned? What if a/b/c/t1/t2/t are not just int but objects? void main() { int t, t1 = 1, t2 = 1; t = myfunc(t1 + t2); } copy t t1=1 t2=1 a c c’ copy

An interesting question int *LocationOfAge() { int age; cin >> age; // missing code here } return &age; int *p = new int; *p = age; return p; return (new int(age));

When constr/desctr are called class M { public: M(); M(const M & ); ~M(); }; M::M() { cout << "call default constructor\n"; } M::M(const M & m) { cout << "call copy constructor\n"; } M::~M() { cout << "call destructor\n"; }

void myfun1(M t) { cout << "go inside myfunc1()\n"; } M& myfun4() { cout << “go inside myfunc4()\n”; M *temp = new M; return *temp; } void myfun2(M &t) { cout << "go inside myfunc2()\n"; } M myfun3() { cout << “go inside myfunc3()\n”; M temp; return temp; }

void myfun1(M t); void myfun2(M &t); M myfun3(); M& myfun4(); void main() { M a; M b = a; M c(a); myfun1(b); myfun2(a); a = myfun3(); b = myfun4(); M *d = new M; delete d; } call default constructor call copy constructor go inside myfunc1() call destructor go inside myfunc2() go inside myfunc3() call default constructor call copy constructor call destructor go inside myfunc4() call default constructor call destructor IMPORTANT! RUN this example by yourself!

Linked list class CNode { public: CNode( const int &d ) : data(d), nextPtr(0){}; int data; CNode *nextPtr; };

Linked list Question: how do you find 8 in the list? firstPtr Node* find(Node* firstPtr, int q) { ListNode *curPtr = firstPtr; // step I while (curPtr != NULL) // step II if (curPtr->data == q) // step III break; curPtr = curPtr->nextPtr; // step IV } return curPtr; } Question: how to allocate a node to hold 10? Question: how to insert the node of 10 after 8? (8 could be the last one in the list)