CISC 3142
Programming Paradigms in C++
Zoom Meeting of 10/06/25
Overview
We covered key C++ programming concepts including separate compilation, function headers, and parameter passing mechanisms, providing examples and demonstrations of various programming techniques.
The class concluded with discussions on method overloading, copy constructors, and upcoming assignments, with Gerald emphasizing the importance of semantic consistency and encouraging students to submit their work for review.
Next steps
- Students to complete Lab 3.1 on separate compilation, adding min, max, and ABS functions to the Infunks module.
- Students to complete Lab 3.2 on parameter transmission, implementing min-max function and variations on min function.
- Students to work on Java Rational class if not already completed.
- Students to attempt Lab 3.4 on C++ Rational class implementation .
- Students to submit something in Codelab for exercises they're working on in IntelliJ, even if incomplete.
C++ Separate Compilation Concepts
We discussed the concepts of separate compilation and function headers in C++. He explained how function headers are used in header files (.h) to provide information about function signatures to the compiler,
allowing functions to be defined in separate source files (.cpp) and used across multiple programs. Gerald emphasized the importance of including header files in source files for compilation and described how object files (.o) can
be distributed instead of source files to protect proprietary code. We also touched on the evolution of C++ compilers and the inclusion of predefined header files without the .h suffix.
C++ Header Files and Arrays
We explained the importance of header files and separate compilation in C++. He demonstrated how to write a simple average function and discussed the benefits of including the header file in the implementation file for consistency.
We also covered arrays and showed examples of functions like min, clear, and set. We mentioned that the array app needed some fixes and would review it later. We then introduced the concept of rational numbers and explained that
students would need to write a minimal module for rational numbers in C++, similar to what they did in Java. He also touched on parameter transmission in C++, noting that it uses true call-by-reference.
C++ Call-by-Value and Call-by-Reference
We explained the concepts of call-by-value and call-by-reference in C++, using a simple example with two functions: fval and fref. We demonstrated how passing parameters by value and by reference affects the original variable's value.
We also discussed the significance of the ampersand symbol in C++ for indicating reference parameters and compared this concept to Java's object and reference variable behavior.
Parameter Passing in Programming
We explained the different ways to pass parameters in programming, focusing on pass by value, pass by reference, and const reference. He emphasized that if a parameter needs to change, it should be passed by reference, while small primitive
types are typically passed by value for efficiency. We also discussed the use of const reference for objects of classes that should not be modified, highlighting the trade-off between performance and immutability. We concluded by noting that
there is no way to modify a class object and prevent it from changing after returning from a function, unless it is passed by constant reference.
C++ Rational Number Class Implementation
We demonstrated a simple implementation of a Rational number class/structure in C++, including methods for printing, multiplication, and error handling for zero denominators. He showed how to initialize structures without explicit constructors and
explained the use of const references for immutable parameters. The example code included basic arithmetic operations and demonstrated how to handle division by zero by throwing an exception that could be caught in the calling application.
C++ Lab Exercises Overview
We explained the requirements for two lab exercises involving C++ programming. He demonstrated how to write a min-max function with reference parameters and showed different ways to implement a min function that
indicates when numbers are equal. We also discussed the concept of semantic consistency in separate compilation and mentioned that some of the exercises might need to be adjusted or postponed until after Wednesday night.
Method Overloading: Benefits and Examples
We explained the concept of method overloading and its benefits, focusing on code efficiency and semantic consistency. We emphasized the importance of avoiding code repetition and potential errors by leveraging existing logic,
which ensures that related concepts are treated consistently. We also highlighted the significance of semantic consistency in future programming concepts, such as operator overloading, and provided examples of leveraging functionality
to define methods like isEmpty in terms of size.
Java Class Design and Assignments
We discussed the concepts of copy constructors, leveraging functionality, and the toString method in Java, emphasizing the importance of reusing logic across classes. He encouraged students to work on their Java Rational class assignments,
either as a structure or a class, and reminded them to submit something in Codelab to indicate progress.