Teaching Notes: Module 00
Tutor Mindset
Section titled “Tutor Mindset”This is the student’s first exposure to C++. The goal is NOT to give answers, but to guide them toward understanding. Ask leading questions, let them struggle a bit, then help them connect the dots.
Exercise 00: Megaphone
Section titled “Exercise 00: Megaphone”What It Tests
Section titled “What It Tests”- Basic I/O with
std::cout - Command-line arguments (
argc,argv) - String manipulation (uppercase conversion)
- Loop iteration over strings
Common Mistakes to Watch For
Section titled “Common Mistakes to Watch For”-
Using
printf- Student habit from C. Gently remind: “What’s the C++ way to output?”
-
Using
toupper()incorrectly// WRONG - toupper returns intstr[i] = toupper(str[i]); // Works but implicit conversion// BETTER - explicit caststr[i] = static_cast<char>(toupper(str[i])); -
Forgetting the no-argument case
- Subject says: print
* LOUD AND UNBEARABLE FEEDBACK NOISE *
- Subject says: print
-
Not handling spaces between arguments
./megaphone "Hello" "World"should printHELLOWORLD(no space)- But
./megaphone "Hello World"should printHELLO WORLD
Guiding Questions (Don’t Give Answers!)
Section titled “Guiding Questions (Don’t Give Answers!)”- “How do you access command-line arguments in C++?”
- “What’s different about
std::coutcompared toprintf?” - “How can you convert a character to uppercase?”
- “What happens when no arguments are provided?”
Red Flags During Evaluation
Section titled “Red Flags During Evaluation”- Using
printf,scanf, or any C I/O - Complex code for a simple task (overengineering)
Exercise 01: PhoneBook
Section titled “Exercise 01: PhoneBook”What It Tests
Section titled “What It Tests”- Class design (two classes: PhoneBook, Contact)
- Encapsulation (private attributes, public methods)
- Arrays (fixed size, no dynamic allocation)
- Input validation
- Output formatting with
iomanip - Object lifecycle
Key Requirements (Easy to Miss!)
Section titled “Key Requirements (Easy to Miss!)”- Max 8 contacts - oldest replaced when full
- No dynamic allocation - fixed array, not pointers
- Fields: first name, last name, nickname, phone number, darkest secret
- No empty fields - must validate input
- Display format: 10-char columns, right-aligned, truncate with ’.’
- Commands: ADD, SEARCH, EXIT only
Common Mistakes to Watch For
Section titled “Common Mistakes to Watch For”-
Using vectors/dynamic allocation
- Subject explicitly forbids dynamic allocation
- Must use:
Contact _contacts[8];
-
Wrong display format
// WRONGstd::cout << name << std::endl;// RIGHTstd::cout << std::setw(10);if (name.length() > 10)std::cout << name.substr(0, 9) + ".";elsestd::cout << name; -
Not tracking the oldest contact
- Need an index to know which contact to replace
-
Empty field acceptance
// Need to reject empty inputwhile (input.empty()) {std::cout << "Field cannot be empty: ";std::getline(std::cin, input);} -
Not handling EOF (Ctrl+D)
std::getlinereturns false on EOF- Program should exit gracefully
-
Making attributes public
- Everything that can be private SHOULD be private
Class Design Guidance
Section titled “Class Design Guidance”PhoneBook├── Private:│ ├── Contact _contacts[8]│ ├── int _count (or _index, _oldest)│ └── (helper methods)├── Public:│ ├── PhoneBook() - constructor│ ├── void addContact(Contact c)│ ├── void search()│ └── Contact getContact(int index)
Contact├── Private:│ ├── std::string _firstName│ ├── std::string _lastName│ ├── std::string _nickname│ ├── std::string _phoneNumber│ └── std::string _darkestSecret├── Public:│ ├── Contact() - constructor│ ├── Setters for each field│ ├── Getters for each field│ └── bool isEmpty() - check if contact is setGuiding Questions
Section titled “Guiding Questions”- “What data does a Contact need to store?”
- “How will PhoneBook know when it’s full?”
- “Which contact should be replaced when the phonebook is full?”
- “How do you truncate a string that’s too long?”
- “What’s the difference between public and private?”
- “Why would you want to make attributes private?”
Red Flags During Evaluation
Section titled “Red Flags During Evaluation”- All attributes public
- Using vectors, lists, or dynamic memory
- Hardcoded magic numbers (use constants)
- No input validation
- Crashes on edge cases (empty input, EOF, invalid index)
Exercise 02: Account (Bonus)
Section titled “Exercise 02: Account (Bonus)”What It Tests
Section titled “What It Tests”- Reading existing code and matching behavior
- Static members and methods
- Understanding log output
- Reverse-engineering from header + tests
Key Insight
Section titled “Key Insight”Student must:
- Read
Account.hppto understand the interface - Run
tests.cpp(it won’t compile yet) - Look at the log file to understand expected output
- Implement
Account.cppto match the log (except timestamps)
Common Mistakes
Section titled “Common Mistakes”-
Not studying the log file carefully
- The log shows exact output format
- Order of destructor calls matters
-
Static member initialization
// In Account.cpp (NOT in header!)int Account::_nbAccounts = 0;int Account::_totalAmount = 0;int Account::_totalNbDeposits = 0;int Account::_totalNbWithdrawals = 0; -
Timestamp format
[YYYYMMDD_HHMMSS]- Use
<ctime>for time functions
-
Destructor order
- Objects destroyed in reverse order of creation
- Array elements: last created = first destroyed
Guiding Questions
Section titled “Guiding Questions”- “What’s the difference between static and non-static members?”
- “Where should static members be initialized?”
- “Why does the log show accounts being destroyed in reverse order?”
- “How can you format time in C++?”
General Teaching Tips for Module 00
Section titled “General Teaching Tips for Module 00”For Students Coming from C
Section titled “For Students Coming from C”- Mindset shift: “Objects have behavior, not just data”
- Memory safety: “std::string manages memory for you”
- Type safety: “Let the compiler help you catch mistakes”
Common Conceptual Struggles
Section titled “Common Conceptual Struggles”-
Why classes over structs?
- Encapsulation: hide internal details
- Behavior: methods operate on data
- Lifecycle: constructors/destructors
-
Why private attributes?
- Control: you decide how data is accessed/modified
- Validation: setters can check input
- Future-proofing: internal representation can change
-
Why
std::stringoverchar*?- No manual memory management
- No buffer overflows
- Convenient operations (concatenation, comparison)
How to Guide Without Giving Answers
Section titled “How to Guide Without Giving Answers”Instead of saying: “Use std::setw(10) for formatting”
Say: “Take a look at <iomanip>. There’s a function that sets field width. What does it do when the text is shorter than the width?”
Instead of saying: “You need to track the index of the oldest contact”
Say: “When the phonebook is full and you add a new contact, how will you know which one to replace? What information do you need to track?”
Evaluation Checklist
Section titled “Evaluation Checklist”- No forbidden functions (printf, malloc, etc.)
- No
using namespace std; - Include guards present
- Implementation not in headers
- Output ends with newline
- Classes properly encapsulated
- Memory properly managed (no leaks)
- Edge cases handled
- Code is readable and makes sense