Professional Documents
Culture Documents
Lecture 01
Lecture 01
Lecture 01
Programming
INSTRUCTOR: JAWAD RASHEED
Why take COM252?
1. Discovery that language is a pattern of sounds that takes on meaning and purpose
3. Ability to self-reflect on the use of language and to see language as a “tool for thinking” and
communicating thoughts, even when not actively speaking or interacting with others
● A course that will give you practice with computational thinking skills through basic C++
coding
● A course that will teach you the specifics of the C++ language
Definition
object-oriented programming
A programming paradigm based on the
concept of “objects” that contains data
(attributes/properties) and code
(procedures/methods).
Definition
abstraction
Design that hides the details of how
something works while still allowing the
user to access complex functionality.
● Key idea: Through a simpler interface, users are able to take full advantage of a complex
system without needing to know how it works or how it was made.
● People are important part of defining classes/abstractions and defining the boundary between
usage and implementation (i.e. What should that simpler interface look like?)
● COM252 focuses on the design and/or use of classes and objects in computer science.
arrays,
Abstract data structures dynamic memory
(vectors, maps, etc.) management,
linked data structures
arrays,
Abstract data structures dynamic memory
(vectors, maps, etc.) management,
linked data structures
arrays,
Abstract data structures dynamic memory
(vectors, maps, etc.) management,
linked data structures
arrays,
Abstract data structures dynamic memory
(vectors, maps, etc.) management,
linked data structures
● C++ is gives us access to lower-level computing resources (e.g. more direct control over
computer memory)
○ This makes it a great tool for better understanding abstractions!
● C++ is gives us access to lower-level computing resources (e.g. more direct control over
computer memory)
● If you’re coming from a language like Java/Python, the syntax will take some getting used to.
○ Like learning the grammar and rules of a new language, typos are expected. But
don’t let this get in the way of working toward literacy!
● C++ is gives us access to lower-level computing resources (e.g. more direct control over
computer memory)
● If you’re coming from a language like Java/Python, the syntax will take some getting used to.
● C++ is a high-performance, robust (and complex) language built on top of the C programming
language (originally named C with Classes)
○ Bjarne Stroustrup, the inventor of C++, chose to build on top of C because it was fast, powerful, and widely-used
● C++ is a high-performance, robust (and complex) language built on top of the C programming
language (originally named C with Classes)
○ Bjarne Stroustrup, the inventor of C++, chose to build on top of C because it was fast, powerful, and widely-used
● C++ has been an object-oriented language from the beginning
○ We will spend the middle portion of this class talking about the paradigm of object-oriented programming
● C++ is a high-performance, robust (and complex) language built on top of the C programming
language (originally named C with Classes)
○ Bjarne Stroustrup, the inventor of C++, chose to build on top of C because it was fast, powerful, and widely-used
● C++ has been an object-oriented language from the beginning
○ We will spend the middle portion of this class talking about the paradigm of object-oriented programming
● C++ is quite mature and has become complex enough that it is challenging to master the
language
○ Our goal in this class will be to help you become literate in C++ as a second programming language
● C++ is a high-performance, robust (and complex) language built on top of the C programming
language (originally named C with Classes)
○ Bjarne Stroustrup, the inventor of C++, chose to build on top of C because it was fast, powerful, and widely-used
● C++ has been an object-oriented language from the beginning
○ We will spend the middle portion of this class talking about the paradigm of object-oriented programming
● C++ is quite mature and has become complex enough that it is challenging to master the
language
○ Our goal in this class will be to help you become literate in C++ as a second programming language
// The C++ compiler will look for a function # This function does not need to be called “main”
// called “main” def main():
int main() { print('Hello, world!')
cout << "Hello, world!" << endl;
return 0; // must return an int to indicate
// successful program completion if name == ' main ':
} # Any function that gets placed here will get
# called when you run the program with
# `python3 helloworld.py`
main()
● Single-line comments
cout << "Hello, World!" << endl; // everything past the double-slash i s a comment
● Multi-line comments
*/
● Utilizing code written by other programmers is one of the most powerful things that you can do
when writing code.
● In order to make the compiler aware of other code libraries or other code files that you want to
use, you must include a header file. There are two ways that you can do so:
○ #include <iostream>
■ Use of the angle bracket operators is usually reserved for code from the C++ library
○ #include "console.h"
■ Use of the quotes is usually reserved for code from the C++ libraries, or code in files that you have written
yourself
cout << "The answer to life, the universe, and everything is " << 42 << "." << endl;
252 classCode
94.7 mondayTemp
We will think of
a variable as a 252 classCode
named
container 94.7 mondayTemp
storing a value.
Note: C++
uses the 252 classCode
camelCase
naming 94.7 mondayTemp
convention
93
252
-5
"COM252"
"I student of
computer
engineering <3"
'c' '8'
○ char
'&'
int
a
int
a
char
5 'x'
int
char c = 'x'; // c is a char ("character")
a c
char
5 'x'
int
char c = 'x'; // c is a char ("character")
double
1.06
char
5 'x'
int
char c = 'x'; // c is a char ("character")
double
string
"this is a
1.06 C++ string"
d s
char
5 'x'
int
char c = 'x'; // c is a char ("character")
double
redefine a variable to be another type
string
"this is a
1.06 C++ string"
d s
char
5 'x'
int
char c = 'x'; // c is a char ("character")
double
redefine a variable to be another type
string
"this is a
int a = 12; // ERROR! You do not need the
1.06 C++ string"
s
type when re-assigning a variable
d
char
12 'x'
int
char c = 'x'; // c is a char ("character")
double
redefine a variable to be another type
string
"this is a
int a = 12; // ERROR! You do not need the
1.06 C++ string"
s
type when re-assigning a variable
parameters
/ arguments
Definition
parameter(s)
parameters One or more variables that your
/ arguments function expects as input
Definition
argument(s)
parameters The values passed into your
/ arguments function and assigned to its
parameter variables
Definition
return value
The value that your function return value
hands back to the “calling”
function
function
prototype
function name
input
expected
(parameters)
output
expected
(return type)
function
definition
returned value
int main(){
double mid = average(10.6, 7.2);
cout << mid << endl;
return 0;
}
Order matters!
double sum = a + b;
return sum / 2;
} A function
must always be
int main(){ defined before it
double mid = average(10.6, 7.2);
cout << mid << endl; is called.
return 0;
}
int main(){
double mid = average(10.6, 7.2);
cout << mid << endl;
return 0;
caller
} (calling function)
double
return sum / 2; 10.6 a
}
double
7.2 b
int main(){
double mid = average(10.6, 7.2);
cout << mid << endl;
sum
double
return 0; 17.8
}
double
return sum / 2; 10.6 a
}
double
7.2 b
int main(){
double mid = average(10.6, 7.2);
cout << mid << endl;
sum
double
return 0; 17.8
} These variables only
exist inside average()!
double
8.9 mid
int main(){
double mid = average(10.6, 7.2);
cout << mid << endl;
return 0;
}
double
8.9 mid
int main(){
double mid = average(10.6, 7.2);
int main() {
int myValue = 5;
int result = doubleValue(myValue); myValue: 5 result: 10
cout << "myValue: " << myValue << " ";