From 1dae9943642c5474d76bcf795d6e96d7e9a9fa14 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Thu, 5 Dec 2024 12:02:17 +0100 Subject: [PATCH] Bugfix 1 --- lab3/UserTable.cc | 3 +++ lab3/UserTableTest.cc | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/lab3/UserTable.cc b/lab3/UserTable.cc index b52f0c6..7e0dd1e 100644 --- a/lab3/UserTable.cc +++ b/lab3/UserTable.cc @@ -27,6 +27,7 @@ UserTable::UserTable(const std::string &fname) : UserTable{} { void UserTable::addUser(const User &u) { // gör tabellen större vid behov ensureCapacity(n + 1); + // 1. Hitta rätt plats int pos{0}; while ((pos < n) && (users[pos].getCardNbr() < u.getCardNbr())) { @@ -40,6 +41,8 @@ void UserTable::addUser(const User &u) { // 3. stoppa in den nya användaren i luckan users[pos] = u; + + ++n; } User UserTable::find(int c) const { diff --git a/lab3/UserTableTest.cc b/lab3/UserTableTest.cc index 6ec3a19..98ccacf 100644 --- a/lab3/UserTableTest.cc +++ b/lab3/UserTableTest.cc @@ -18,4 +18,8 @@ int main() { assert(u3.getCardNbr() != u4.getCardNbr()); UserTable ut1 = UserTable("users.txt"); + + ut1.addUser(u3); + User us = ut1.find(1200); + assert(us != UserTable::user_not_found); }