Tutorial 3 More C++ and ADT 1

advertisement
Tutorial 3
More C++ and ADT
1
Admin
• Some students have moved to different class
– Changes have been reflected in the attendance list
• See the last few lines
– Compare this scenario with our question 2…
– If I put these students (who moved to different group) in
alphabetical order, I need to shift the rest downwards
» I do not want to print the attendance list again…
• No more swap request will be entertained
– Please try to achieve 100% attendance
in your respective class
2
Error Handling (in C++)
• When a (runtime) error happens…
– There are many ways to handle it…
• Print error message,
• Re-do the task,
• Quit program, etc
• Using “throw and catch”…
– We will see this in action later in Q1
– “throw and catch” is also available in Java
3
Abstract Data Type (ADT)
• Abstract Data Type
– Data + Operations (Algorithms) to organize that data structure
• Data Structure: “Structure of Data”, structure makes life easier
• Algorithm: Step by step way to solve certain problem
– Walls: We do not need to know the implementation details
– Examples: Complex Number, Sphere, ColoredSphere:Sphere, List, etc
• Wait! Contradictions?
– We are given so many implementation details here! Why bother?
• In fact, we are going to do that throughout this module 
– To give you a strong theoretical foundation…
– Later on, you will just use these ADTs for your programming tasks
• Like C++ STL
4
C++ Standard Template Library
• C++ has Standard Template Library (STL)
– This library can simplify your life…
• Reference:
– http://www.cppreference.com
• Today’s topic is STL Vector
– Your friend who do Q2 will show some ideas
– Throughout the semester, we will learn more
5
Classes in C++ to Implement ADT
• Basic pattern:
– In “header file”  *.h
class C {} {
public: // the opening in the wall…
// put constructor/destructor and public methods here (accessor/mutator/etc)
private:
// put hidden attributes or local methods here
};
– In “implementation file”  *.cpp
#include “header_file_name.h”
C::C() { // constructor here }
C::~C() { // destructor here }
C::methodname() { // implementation here }
6
Student Presentation (Q3 longer…)
• T5:
1. LAU WAI HOE AARON
2. LEONARDUS ADI PRASETYA
3. LI JIALONG
• T10:
1. HU FAN
2. IMANTHI UDESHINI D B
3. JIANG YONGBO
• T9:
1. HOO CHIN HAU
2. KALYANI IYER
3. KOAY ZI HAO
• T17
1. CHENG LULU
2. CHEW JIE BIN ELROY
3. CHONG LEE KEE
• T13:
1. FAN LANLAN
2. GAO MINMIN
3. HAO SHUAI
7
Download