Skip to the content.

Intro

Back to Homepage
Back to Week 1


Types of Programming

Structured:

Object Oriented Programming:

Functional:


Uses

All are long-lived state frequently accessed


Classes


Encapsulation

  #include <iostream> // Allows us to read to or write from the console
  #include <istream>
  
  string readContnents(string filename);
  ifstream input(filename);
   
  int fileId;
  int readPos;
   
  int i;
  input >> i; 
  
  cin >> i;

Have classes to group and create simplier interfacee

##ifstream:


Cohesion vs Coupling

Minimum interactions needed, coupling is necessary, but want to minimuze it.
0% coupling is just a bunch of different functions that dont interact with each other at all.
Want to try to keep functions small (about 10 lines).

class Student {
  private:
  string firstName;
  string lastName;
  char middleInitial;
  long studentId;
  string major;
  
  public:
  string makeFormalName(){
    return lastName + ", " + firstName + " " + middleInitial + "."
  }
  
}


Class designer vs. Client