70 likes | 224 Views
Tutorial 3 More C++ and ADT. 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…
E N D
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% attendancein your respective class
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
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
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
Classes in C++ to Implement ADT • Basic pattern: • In “header file” *.hclass 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 }
Student Presentation (Q3 longer…) • T5: • LAU WAI HOE AARON • LEONARDUS ADI PRASETYA • LI JIALONG • T10: • HU FAN • IMANTHI UDESHINI D B • JIANG YONGBO • T13: • FAN LANLAN • GAO MINMIN • HAO SHUAI • T9: • HOO CHIN HAU • KALYANI IYER • KOAY ZI HAO • T17 • CHENG LULU • CHEW JIE BIN ELROY • CHONG LEE KEE