Object-Oriented Programming

    Next >
  1. Procedural vs. Object-Oriented Programming
    • Think of a design problem.
    • What would a Procedural Programming implementation look like?
    • What would an Object-Oriented Programming implementation look like?
    • Share your example with a neighbor (or two).
  2. Does the following C++ code exemplify Procedural or Object-Oriented Programming?
    // From ADTs, Data Structures, and Problem Solving with C++, 2e by Larry Nyhoff
    #include <iostream>
    #include "Time.h"
    using namespace std;
    
    struct Time{
        unsigned int hour, minute;
        char AMorPM;        // 'A' or 'P'
        unsigned int milTime;   // military time equivalent
    };
    
    int main(){
        Time mealTime, goToWorkTime;
        set(mealTime, 5, 30, 'P');
        cout << "We'll be eating at ";
        display(mealTime, cout);
        cout << endl;
        set(goToWorkTime, 5, 30, 'P'); 
        cout << "You leave for work at ";
        display(goToWorkTime, cout);
        cout << endl;
        if (lessThan(mealTime, goToWorkTime)){
            cout << "If you hurry, you can eat first.\n";
        }else{
            cout << "Sorry you can't eat with us.\n";
        }
        advance(goToWorkTime, 0, 30);
        cout << "Your boss called.  You go in later at ";
        display(goToWorkTime, cout);
        cout << endl;
        if (lessThan(mealTime, goToWorkTime)){
            cout << "If you hurry, you can eat first.\n";
        }else{
            cout << "Sorry you can't eat with us.\n";
        }
        cout << endl;
    }