Rs
Module 1Functions & Control FlowLesson 10 of 1025 min

Module 1 Practice Lab

Capstone mini-lab: mini blotter combining variables, functions, formatting, and loops.

Lab goals

Wire together everything from Module 1 into a tiny blotter printer:

  1. Store several trades as tuples (name, qty, price) in an array
  2. Function trade_notional(qty, px)
  3. Loop to print each line and a total

This is deliberately simple — no structs/Vec yet — so you feel fluent with basics before ownership.

Design sketch

trades: [("AAPL", 10, 190.0), ("MSFT", -5, 420.0), ...]
for each trade:
  print side from sign of qty
  print notional
sum absolute notionals or net cash

Stretch ideas (after you finish)

  • Flag any |qty| above a limit
  • Print running net notional after each line

Take your time — re-run often.

Challenge

Also compute net cash (sum of signed notionals) and print long vs short counts.

Tips
  • Array of tuples is fine for tiny labs
  • abs() on f64 for gross exposure style metrics
  • Next module: ownership will explain why String vs &str matters for symbols

Try it live

Module 1 Practice LabRust 2021
Loading editor…
Output
Press Run to compile and execute.