0% found this document useful (0 votes)
15 views

Lecture 1

OOP Lecture 1

Uploaded by

Noor Ghazi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Lecture 1

OOP Lecture 1

Uploaded by

Noor Ghazi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Object Oriented Programming –

CS/CE 224/272
Nadia Nasir

Habib University, Fall 2023


Content
• My background

• W hy study this course

• Syllabus

• Course expectations

• Hello world!
Syllabus
Why C++
• C++ is more performant

• Particularly popular in graphics and scientific computing

• In the context of ML, most engines are written in C++ with Python used to
make calls to backend engine

• NOT the language for web or for UI!

• CS@HU decided C++ was the better choice


• Object oriented programming is not limited to C++. Python, Java, and other
languages also has this concept. But
Rules of the game

• Setup your environment as soon as possible


• Any problems, please ask help immediately

• Expect the pace of the course to be fast. This has been


a challenging course in the past.

• Just a warning. It will be a significant step up from PFun


• Don’t mean to scare you. Just being honest and setting the
expectations

• If you have any issues, difficulty, or want to discuss anything,


please feel free to discuss (via email/MS teams).
Please don’t expect to get response to your emails instantaneously
Please don’t expect replies over the weekend
Questions?
Object oriented vs procedural paradigms
• In procedural paradigms:
• program is divided to series of functions.
• It is great for small specific tasks
• Data is difficult to manage. If multiple functions need to access data, it
becomes a bit wieldy
• Think in terms of functions
Object oriented vs procedural paradigms
• In object oriented paradigms:
• A class defines a blueprint of an object
• What attributes should be visible to public and what should be
private
• There is data associated with an object and member functions to
access that data
Elements of OOP
• Objects

• Classes

• Inheritance

• Reusability

• … many other (which we will deal with later)


First program in C++
Tools you should install

• On linux, you can install latest version of gcc/g++ - a compiler

• On W indows, I would recommend using MinGW. If you download


Visual Studio IDE, then it has its own compiler
Hello C++!
• Your first C++ program
#include <iostream>

int main(int argc, char* argv[])


{
std::cout << "Hello c++!\n";
}

• C++ is a compiled language. So you need a compiler!


• There are many compilers. We use g++

• What can say about this code?


Hello C++!
• Your first C++ program
#include <iostream>

int main(int argc, char* argv[])


{
std::cout << "Hello c++!\n";
}

• It has a include statement -> similar to imports in Python

• A C++ must always have a ‘main’ function. This is the entry point of
the code

• ‘main’ takes 2 arguments.


• ‘argc’ counts how many arguments are given to the main function
• ‘argv’ what arguments are specifically provided
Hello C++!
• Your first C++ program
#include <iostream>

int main(int argc, char* argv[])


{
std::cout << "Hello c++!\n";
}

• cout is used to print to the console.


• cout is an object and hence it has other member functions.
• More on this later. For now, you can remember how to print to console
• It will useful for debugging!

• How does C++ know where to find cout?


• Hence the include statement. We are telling the compiler that
cout is present in iostream, go find there

• Curly braces denote a code block. Python uses indentation!


Compiled vs interpreted languages

The program written in any programming language must be translated into


machine language before it can be executed by the computer.

This is done by special programs called compilers, interpreters, or


assemblers that are built into the various programming applications.
The set of instructions that a programmer writes in any programming
language is often called the source code.

The source code translation can be done in two ways.


One way is for the computer to translate the source into executable
instructions line by line each time the program is run. Language of this
type are called interpreted languages.

The disadvantage of interpreted languages is that they are slow since the
translation is done at the each time the instructions are executed. Python,
and MATLAB are examples of interpreted languages.
Here is a simplified representation of the interpretation process
Another way to handle the translation is to compile the source into
machine readable programs once and save the machine language
instructions in a separate executable file.

When the executable file is run, the translation step is skipped and the
program runs much faster than if it were written using a interpreted
language.

Programming languages that use this scheme are called compiled


languages. Examples are C, C++, Java, and Fortran.
Concepts covered so far
• Building first C++ code
• Intro to OOP
• Preprocessor directives
• Header files
• Semicolon
• namespace std
• Function body
• Comments

You might also like