Small C and C++ exercises from an object-oriented programming course: hand-written containers, C string/file utilities, inheritance and templates.
Year: 2019-2020 · Language: C++ and C · Context: university coursework (KPI)
| Folder | What it does |
|---|---|
WorkWithMemory_C/ |
Re-implementation of the glibc argz API in C (argz_create_sep, argz_add, argz_delete, argz_insert, argz_replace, argz_next); test in argztest.c |
FilePractice/ |
Binary "database" of scanners in C: create_db from scanners.csv, add_scanner, del_scanner, per-field index files (make_index, reindex), select by field value |
Classes/ |
cArray, a growable int array (Add, Append, Copy, InsertAt, RemoveAt, FreeExtra, operator[]) with method names modelled on MFC CArray; test in carray_test.cpp |
ListImplementation/ |
List, a singly linked list of int with a std::list-like API (splice, merge, unique, sort, reverse, resize, copy constructor and assignment) |
VectorImplementation/ |
vector, a hand-written dynamic int array with std::vector-like API (assign, erase, insert, sort, unique, capacity) |
Inheritance/ |
Employee database: abstract Person -> Employee -> Manager (holds a list of subordinates), Database loads input.csv, hires/fires, prints departments, simple SQL(field, cond, value) filter |
Templates/ |
List<T> template with a custom iterator (Iterator.h), used for Bus records loaded from park.csv (bus park / route lists, splice, ChangeDriver) |
FilePractice/scanner.cstores records as a count header followed by fixed-sizeSCAN_INFOstructs, and builds a separate index per field (make_index) thatget_recs_by_indexlater reads.Inheritance/Manager.cppimplements the copy constructor andoperator=for a class holdinglist<Person*>;Database::ArrangeSubordinatesattaches loaded employees to each manager after reading the CSV.Templates/List.himplementssplicebetween two lists, andload()parses;-separated lines withstrtok.VectorImplementation/Vector.hdeliberately names its classvector(own filevector.his included byVector.cpp), so it shadows the standard name.
Tested with g++/gcc on Linux in a scratch copy, only partly working without edits (the code was written for Visual Studio):
ListImplementation:g++ -std=c++14 list.cpp list_test.cppbuilds and runs.Templates:g++ -std=c++14 -include cstring -include cstdlib Test.cpp Bus.cppbuilds and runs.VectorImplementation: needs a lowercasevector.hon case-sensitive file systems (cp Vector.h vector.h), theng++ Test.cpp Vector.cppbuilds and runs.Inheritance:g++ -std=c++14 Database.cpp Employee.cpp Manager.cpp Test.cppbuilds, prints the hierarchy, then aborts at theSQLstep (not investigated). Run from the folder, it readsinput.csv.Classes: does not compile with g++ (new int[double]incarray.cpp).WorkWithMemory_C:argztest.cpassesint*wheresize_t*is expected and segfaults on 64-bit; with that variable changed tosize_tall functions print correct results.FilePractice: usesitoaand a function namedselectthat clashes with the POSIX one; with both worked around it builds, createsresult.txtand then segfaults. Not re-tested beyond that.
Written in 2019-2020, before AI coding assistants. Kept as-is for history.