Beginner level · Module 5: C++ Console Project · Lesson 2 of 3
Building the Menu and Features
Implement the menu and each feature one at a time, compiling and testing after every step.
In this lesson you will
- Implement a do-while menu calling feature functions
- Use a std::vector of objects to hold the program's data
Key concepts
menu loopstd::vector of objectsincremental buildseparation of input and logic
The lesson
Keep the data in a std::vector<WaterPoint> owned by main and pass it to functions by reference when they change it and by const reference when they only report.
Build one menu option at a time: add a reading, list, flag points for repair, weekly totals. Compile and run after each one, so any error comes from the last change.
Keep input and output in the menu functions and calculations in functions that take values and return results. Calculation functions are then easy to test with fixed values.
Step by step
- Write the menu loop with an Exit option.
- Implement adding and listing readings.
- Implement the repair flags and weekly totals.
- Test each option with sample data after adding it.
Practice activity
Implement all menu options of the Water Point Log.
Expected result: Each option works on the sample data and totals match a hand calculation.
Check your understanding
-
How should a function that only prints the vector receive it?
Show answer
By const reference.
-
Why compile and run after each feature?
Show answer
So any new error can be traced to the most recent change.
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.