Code Monkey home page Code Monkey logo

daily-bite-course-05's Introduction

Modern-Only C++ Course - Homework

This repository contains the homework for Lesson 5.

Overdue books

Implement a function overdue_checkouts (in the file overdue/overdue.cc) that processes three database files containing information about users, books and book checkouts and returns a list of checkouts that are currently overdue for return.

Each book can be checked out for 30 days.

User db is in file users_db.txt, has one record per line, with each record consisting of a unique id (integer) and a quoted name of the user (separated by space).

Books db is in file books_db.txt, has one record per line, with each record consisting of a unique id (integer), a quoted name of the author and a quoted title of the book (separated by space).

Checkouts db is in file checkouts_db.txt, has one record per line, with each record consisting of the book id, user id and a timestamp representing seconds since epoch in UTC (separated by space).

bazel test //overdue/...
bazel test --config=addrsan //overdue/...
bazel test --config=ubsan //overdue/...

Duplicate file finder

Implement a function find_duplicates (in the file duplicates/duplicates.cc) that finds duplicate files, i.e. files with the same filename and content. The function should return a std::vector<DuplicateInfo>, where each record corresponds to one set of duplicates.

The returned paths should be relative to path the find_duplicates function was called with.

The goal is to have the following commands pass without any errors:

bazel test //duplicates/...
bazel test --config=addrsan //duplicates/...
bazel test --config=ubsan //duplicates/...

Tips

You will need to do a bit of searching on https://cppreference.com.

We did not talk about relative paths (there is a solution, but it isn't the obvious one).

There is data structure adjacent to std::unordered_map that you will find useful.

Fun with sorting (freeform)

This homework doesn't have an associated test suite or example solution.

Have some fun with sorts: https://en.wikipedia.org/wiki/Sorting_algorithm.

I have prepared a simple binary scafolding for you in the directory sortingfun. You can run the resulting executable using:

bazel run //sortingfun

Some ideas for you:

  • implement a couple of basic sorts, you can put each of them into a separate namespace, or even a separate header/implementation file (follow the other homework as template to construct the BUILD file)

  • measure using std::chrono how the performance differs across the different algorithms

  • try different sizes of inputs

  • try different containers (std::vector, std::array, std::list)

  • try special types of inputs (already sorted, sorted in oposite direction, almost sorted, rotated)

Tips:

You can fill a container with consecutive numbers using the following snippet:

#include <algorithm>
#include <ranges>
#include <vector>
#include <cstdint>

std::vector<int64_t> data;
std::ranges::copy(
    std::views::iota(1,32), // 1..31
    std::back_inserter(data));

You can randomly shuffle a container using the following snippet:

#include <algorithm>
#include <vector>
#include <cstdint>
#include <random>

std::vector<int64_t> data{...};

// The number passed-in is the seed.
// Change it to change the order of elements.
std::default_random_engine engine(0);
std::shuffle(data.begin(), data.end(), engine);

Solutions

If you wish to have a look at the solutions, you can find the commented code in the solutions directory.

daily-bite-course-05's People

Contributors

happycerberus avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.