Previous Lecture | lect03 | Next Lecture |
lect03, Thu 09/30
A bit more on structs and constructors
Slides: https://docs.google.com/presentation/d/1Y6HoYn0hvGll0_VqW4Qyyn47bhXUpUd-uLgvdGBklms/edit?usp=sharing
Extra Credit opportunity is up
Continuing our discussion of data types
- Last time we saw how to create a struct
- But initializing the fields was inconvenient
- Today we’ll discuss adding constructors to make that easier.
Code
-
REVIEW from Last time: defining a struct
https://replit.com/@phtcon/CS16-F21-09-27-DataTypes-1#main.cpp
-
New: Adding constructors
https://replit.com/@phtcon/CS16-F21-09-27-DataTypes-2#main.cpp
-
New: Adding a member function for print
https://replit.com/@phtcon/CS16-F21-09-29-MemberFunctions#main.cpp