Skip to content
LAM
Read Home Blog
Make Projects HTML Tools Games
Touch grass Notes Resume Links
Home Blog HTML Projects
Tools Games Notes Resume Links
Back Final Exam Study Guide Programming
Download Open
Show description 2,385 chars · Programming

Final Exam Study Guide

Final Exam Study Guide







Final Exam Key Facts




C++ Concepts


Memory Management


Static Memory: Allocated when the program is compiled. Used for global and static variables. There is only one copy, and it persists for the entire program duration.

Stack Memory: Used for local variables inside functions. Memory is automatically allocated and deallocated as functions are called and return (Last-In, First-Out).

Heap Memory: Used for dynamic memory allocation with the new keyword or functions like malloc. This memory must be manually deallocated using delete or free to prevent memory leaks. The golden rule is: every new must have a matching delete.



Classes, Constructors, and Destructors


A Class is a blueprint for creating objects, defining both state (member variables) and behavior (member functions).

Access Specifiers: public (accessible anywhere), protected (accessible within the class and derived classes), and private (accessible only within the class). These enforce encapsulation.

Member functions can be defined inside the class (for short, convenient functions) or outside using the scope resolution operator (::) to keep class definitions cleaner.

A Constructor is a special function called automatically when an object is created to initialize it.

A Destructor is called automatically when an object is destroyed. Its primary purpose is to clean up resources, especially deallocating heap memory allocated by the object to prevent memory leaks and dangling references.



Inheritance and Polymorphism


Inheritance allows a new class (derived/child class) to be built from an existing class (base/parent class), promoting code reuse.

The "is-a" relationship signifies inheritance (e.g., a Student is a Person).

The "has-a" relationship signifies containment or composition (e.g., a Car has a Wheel).

Polymorphism ("many forms") allows a single interface to represent different underlying forms (data types). In C++, this is achieved with virtual functions.

A virtual function in a base class can be overridden by a derived class. When called through a base class pointer, the version in the derived class is executed, enabling dynamic behavior based on the actual object type.

Function Overloading means having multiple functions with the same name but different parameters (number or type of arguments).…

Final Exam Study Guide

14,231 bytes · HTML source
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Final Exam Study Guide</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap" rel="stylesheet">
    <style>
        :root {
            --bg-color: #0D1117;
            --container-bg: #161B22;
            --text-color: #C9D1D9;
            --header-color: #58A6FF;
            --accent-color: #3081F7;
            --border-color: #30363D;
        }

        body {
            font-family: 'Inter', sans-serif;
            background-color: var(--bg-color);
            color: var(--text-color);
            line-height: 1.7;
            margin: 0;
            padding: 2rem;
        }

        .container {
            max-width: 900px;
            margin: 0 auto;
            background-color: var(--container-bg);
            border: 1px solid var(--border-color);
            border-radius: 8px;
            padding: 2rem;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
        }

        h1, h2, h3 {
            color: var(--header-color);
            border-bottom: 2px solid var(--border-color);
            padding-bottom: 0.5rem;
            margin-top: 2rem;
        }

        h1 {
            text-align: center;
            font-size: 2.5rem;
            margin-top: 0;
        }

        h2 {
            font-size: 1.8rem;
        }
        
        h3 {
            font-size: 1.4rem;
            border-bottom: 1px solid var(--border-color);
        }

        ul {
            list-style-type: none;
            padding-left: 0;
        }

        li {
            background-color: rgba(48, 129, 247, 0.1);
            border-left: 4px solid var(--accent-color);
            padding: 1rem;
            margin-bottom: 0.75rem;
            border-radius: 4px;
        }

        code {
            background-color: var(--bg-color);
            color: var(--header-color);
            padding: 0.2rem 0.5rem;
            border-radius: 4px;
            font-family: 'Courier New', Courier, monospace;
            font-size: 0.95rem;
        }

        strong {
            color: var(--header-color);
            font-weight: 700;
        }

        .glossary-term {
            margin-bottom: 1rem;
        }

        .glossary-term strong {
            display: block;
            font-size: 1.1rem;
        }

    </style>
</head>
<body>
    <div class="container">
        <h1>Final Exam Key Facts</h1>

        <!-- C++ Section -->
        <section id="cpp">
            <h2>C++ Concepts</h2>
            
            <h3>Memory Management</h3>
            <ul>
                <li><strong>Static Memory:</strong> Allocated when the program is compiled. Used for global and static variables. There is only one copy, and it persists for the entire program duration.</li>
                <li><strong>Stack Memory:</strong> Used for local variables inside functions. Memory is automatically allocated and deallocated as functions are called and return (Last-In, First-Out).</li>
                <li><strong>Heap Memory:</strong> Used for dynamic memory allocation with the <code>new</code> keyword or functions like <code>malloc</code>. This memory must be manually deallocated using <code>delete</code> or <code>free</code> to prevent memory leaks. The golden rule is: every <code>new</code> must have a matching <code>delete</code>.</li>
            </ul>

            <h3>Classes, Constructors, and Destructors</h3>
            <ul>
                <li>A <strong>Class</strong> is a blueprint for creating objects, defining both state (member variables) and behavior (member functions).</li>
                <li><strong>Access Specifiers:</strong> <code>public</code> (accessible anywhere), <code>protected</code> (accessible within the class and derived classes), and <code>private</code> (accessible only within the class). These enforce encapsulation.</li>
                <li>Member functions can be defined inside the class (for short, convenient functions) or outside using the scope resolution operator (<code>::</code>) to keep class definitions cleaner.</li>
                <li>A <strong>Constructor</strong> is a special function called automatically when an object is created to initialize it.</li>
                <li>A <strong>Destructor</strong> is called automatically when an object is destroyed. Its primary purpose is to clean up resources, especially deallocating heap memory allocated by the object to prevent memory leaks and dangling references.</li>
            </ul>

            <h3>Inheritance and Polymorphism</h3>
            <ul>
                <li><strong>Inheritance</strong> allows a new class (derived/child class) to be built from an existing class (base/parent class), promoting code reuse.</li>
                <li>The <strong>"is-a"</strong> relationship signifies inheritance (e.g., a Student <em>is a</em> Person).</li>
                <li>The <strong>"has-a"</strong> relationship signifies containment or composition (e.g., a Car <em>has a</em> Wheel).</li>
                <li><strong>Polymorphism</strong> ("many forms") allows a single interface to represent different underlying forms (data types). In C++, this is achieved with virtual functions.</li>
                <li>A <strong>virtual function</strong> in a base class can be overridden by a derived class. When called through a base class pointer, the version in the derived class is executed, enabling dynamic behavior based on the actual object type.</li>
                <li><strong>Function Overloading</strong> means having multiple functions with the same name but different parameters (number or type of arguments). The return type alone is not sufficient to overload a function.</li>
            </ul>
        </section>

        <!-- Scheme Section -->
        <section id="scheme">
            <h2>Scheme Concepts</h2>

            <h3>Syntax and Core Ideas</h3>
            <ul>
                <li>Scheme uses <strong>prefix notation</strong>, where the operator comes first, followed by operands, all enclosed in parentheses. Example: <code>(+ 3 2)</code>.</li>
                <li>Everything in parentheses is a "form" that gets evaluated.</li>
                <li>Names are bound to values using <code>define</code>. Procedures (functions) can be created with a named form or an anonymous <code>lambda</code>. Both forms are equivalent.</li>
                <li>Scheme blurs the line between code and data. A <strong>symbol</strong> is a value that represents code without executing it, allowing programs to manipulate other programs. Source code itself is just a data structure (a list of symbols).</li>
            </ul>

            <h3>Data Structures and Control Flow</h3>
            <ul>
                <li><strong>Pairs</strong> are the fundamental building block of lists, containing two slots: the <code>car</code> (the first element) and the <code>cdr</code> (the rest of the list).</li>
                <li>A proper list is a series of nested pairs ending with an empty list <code>'()</code>.</li>
                <li>Control constructs include <code>if</code> for binary choices and <code>cond</code> for multiple branching conditions (a cascade of cases).</li>
                <li><strong>Scope</strong> is managed through environments. <code>define</code> adds to the global environment, while <code>let</code> creates a temporary, local environment for its body, keeping temporary names tidy.</li>
                <li>A <code>let</code> expression is just syntactic sugar for a <code>lambda</code> call. They are interchangeable and understanding this conversion helps clarify scope.</li>
            </ul>

            <h3>Recursion and Higher-Order Functions</h3>
            <ul>
                <li>Recursion is a primary method for iteration. A common pattern involves identifying a base case (stopping condition) and a recursive step that solves a smaller version of the problem (e.g., operating on the <code>cdr</code> of a list).</li>
                <li>The <strong>Ackermann function</strong> is a classic example of a deeply recursive function that grows extremely fast.</li>
                <li><strong>Higher-Order Functions</strong> are functions that take other functions as arguments or return them as results.</li>
                <li>Key higher-order functions include: <code>map</code> (applies a function to every element in a list, returning a new list), <code>reduce</code> (collapses a list into a single value), and <code>filter</code> (selects elements from a list that satisfy a condition).</li>
            </ul>
        </section>

        <!-- Prolog Section -->
        <section id="prolog">
            <h2>Prolog Concepts</h2>

            <h3>Facts, Rules, and Queries</h3>
            <ul>
                <li>Prolog programs are built from <strong>facts</strong> (things that are true), <strong>rules</strong> (general relationships), and <strong>queries</strong> (questions about the facts and rules).</li>
                <li>Constants start with a lowercase letter, while variables start with an uppercase letter. The underscore <code>_</code> is an anonymous variable (a "don't care" placeholder).</li>
                <li>A fact is a rule with no body. A rule has a head and a body, where the head is true if the body is true. Example: <code>head :- body.</code></li>
                <li>The comma <code>,</code> means "and", the semicolon <code>;</code> means "or", and the period <code>.</code> ends a statement.</li>
            </ul>

            <h3>Unification and Execution</h3>
            <ul>
                <li>Prolog's reasoning engine is based on <strong>unification</strong>, which is a process of pattern matching goals with facts or rule heads.</li>
                <li>Unification succeeds if the predicates have the same name, the same number of arguments (<strong>arity</strong>), and all corresponding arguments can be made equal.</li>
                <li>Prolog explores solutions systematically through <strong>search and backtracking</strong>. When a path fails, it automatically backtracks to the last choice point to try an alternative.</li>
            </ul>
            
            <h3>Lists and Recursion</h3>
            <ul>
                <li>Lists are written with square brackets. The structure <code>[H | T]</code> is used to unify the head of the list with <code>H</code> and the tail (the rest of the list) with <code>T</code>.</li>
                <li>Recursion is fundamental to processing lists, using the base case of an empty list <code>[]</code> and a recursive step that processes the head and recurses on the tail.</li>
                <li>The <strong>cut</strong> (<code>!</code>) is an optimization tool that prunes the search space by committing to the choices made so far and preventing backtracking past that point.</li>
                <li>The <strong>"negation as failure"</strong> rule (often implemented with <code>not</code>) states that something is false if Prolog fails to prove that it is true. The cut is used internally to implement this efficiently.</li>
            </ul>
        </section>

        <!-- Glossary Section -->
        <section id="glossary">
            <h2>Glossary of Terms</h2>
            <div class="glossary-term">
                <strong>Arity:</strong> The number of arguments a function or predicate takes.
            </div>
            <div class="glossary-term">
                <strong>Backtracking:</strong> An algorithm used by Prolog to find all possible solutions. When a query fails, Prolog goes back to the previous choice and tries a different path.
            </div>
            <div class="glossary-term">
                <strong>Dangling Reference:</strong> A pointer or reference that points to a memory location that has been deallocated or freed. Using it can cause crashes or undefined behavior.
            </div>
            <div class="glossary-term">
                <strong>Encapsulation:</strong> The bundling of data (variables) and the methods (functions) that operate on that data into a single unit (a class), and restricting access to some of the object's components.
            </div>
             <div class="glossary-term">
                <strong>Heap Memory:</strong> A region of memory used for dynamic allocation, where memory is allocated and freed manually by the programmer.
            </div>
            <div class="glossary-term">
                <strong>Lambda:</strong> In Scheme, an anonymous (unnamed) function.
            </div>
            <div class="glossary-term">
                <strong>Memory Leak:</strong> A condition where a program allocates memory from the heap but loses the ability to free it, causing the program's memory usage to grow over time.
            </div>
            <div class="glossary-term">
                <strong>Polymorphism:</strong> A core concept in object-oriented programming that allows objects of different classes to be treated as objects of a common superclass.
            </div>
             <div class="glossary-term">
                <strong>Predicate:</strong> The name of a fact or rule in Prolog, which defines a relation.
            </div>
            <div class="glossary-term">
                <strong>Scope Resolution Operator (<code>::</code>):</strong> A C++ operator used to define a member function outside a class or to access static members of a class.
            </div>
             <div class="glossary-term">
                <strong>Unification:</strong> The pattern-matching process used by Prolog to determine if two terms can be made equal. It is the core mechanism for reasoning.
            </div>
        </section>

    </div>
</body>
</html>