You are on page 1of 6

HO CHI MINH CITY – UNIVERSITY OF TECHNOLOGY

FACULTY OF COMPUTER SCIENCE AND ENGINEERING

Advanced Programming Assignment Report

Class: CC01

Instructor: Assoc. Prof. Trương Tuấn Anh

Submitted by: Phan Chí Vỹ

Student ID: 2252938

Ho Chi Minh City – 2024


1. UML diagram
This UML diagram is drawn using yuml.me
2. Explanation for Part 1.
- Instead of using a pointer array for storing the student object, a vector is used
instead.

- This allows easier data manipulation such as inserting or removing a student.


The time complexity for these processes are also reduced due to vectors having
dynamic size, which does not required manually moving elements like a normal
array would when try to remove or insert more students.

- Dynamic size also means we do not need to declare the size upfront because
vectors automatically resize themselves to accommodate the number of elements
they hold.

- Vectors also manage memory automatically, this helps simplify memory


management compare to an array, where we have to manually using ‘new’ and
‘delete’.
3. Explanation for Part 2.
- In part 2, I adapted the adapter pattern for the student management program.

- The two class with incompatible interface is UniStudent and CollegeStudent


we use Uni_adapt and Col_adapt as wrapper classes to translate the incompatible
interface into the expected interface Student.

- This allows the incompatible classes code to be reused without modifying


their code. Instead, the adapters can use these classes in new contexts to satisfy
the expected interface Student needs.

- New adapters can also be added if there is anymore classes that needed to be
adapted, allow more flexibility.

- This pattern also isolates changes to the adapter, making it easier to maintain
or fixing the code of the system without creating unnecessary errors.
4. Explanation for Part 3
- In part 3, I utilize smart pointers to improve my program.

- Smart pointers allow better memory management due to being able to


automatically release memory when no longer needed, preventing memory
leaks.
- These pointers also express ownership, in my example is the unique
relationship, this helps prevent double deletion because the system will generate
errors for violating the requirement of the pointers.
- It also helps in code readability since we can clearly see the lifespan of the
pointers.

- I also use auto and range for loop in the students’ information display
function.

- Auto provides quality of life utility since the type of student is


unique_ptr<Student> which can be long and repetitive to type the full name.
- Range for loop has a much simpler syntax and easier to read compare to the
normal for loop. It also prevent out of bound errors since this method
automatically handle iteration bounds.

You might also like