Download presentation
Presentation is loading. Please wait.
1
Final Review Ying Wu Electrical Engineering & Computer Science Northwestern University yingwu@ece.northwestern.edu EECS 230 Lectures Series
2
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
3
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!
4
CTEC survey Please fill the CTEC survey Our course number: EECS 230-0-20 Instructor: –Professor Ying Wu TAs are: –Ming Yang –David Choffnes –Yao Zhao
5
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
6
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
7
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
8
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
9
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 = ?
10
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.
11
8 10010000 10020008 10090080 int a = 8; int *pa = &a; int **ppa = &pa; Question: [1] (*pa) = ? [2] (**ppa) = ?
12
10010000 10020008 int *pa = new int [3];
13
10014006 10020008 int **ppa = new int* [3]; for(int k=0;k<3;k++) ppa[k] = new int [3]; 10020008 10090080 10010308 10010000 10010308 10014006 Question: (1) ppa[1] = ? (2) ppa[1][2] = ? (3) ppa + 2 = ?
14
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?
15
class CTable() { int **m_pData; int m_nRow; int m_nCol; public: CTable(int r = 1, int c = 1); ~CTable(); … };
16
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); }
17
CTable::~CTable() { for(int k=0; k<m_nRow; k++) delete [] m_nData[k]; delete [] m_nData; }
18
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
19
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));
20
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"; }
21
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; }
22
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!
23
Linked list class CNode { public: CNode( const int &d ) : data(d), nextPtr(0){}; int data; CNode *nextPtr; };
24
Linked list Question: how do you find 8 in the list? firstPtr 7983 5 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)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.