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

lecture1_welcome

Uploaded by

omarmatin2024
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)
2 views

lecture1_welcome

Uploaded by

omarmatin2024
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/ 34

Welcome to OOP!

Lecturer: 陈笑沙, Xiaosha Chen


Email: pdcxs@outlook.com

1
Asking Questions
- We welcome questions!!
- Feel free to raise your hand at any time with a
question
- We’ll also pause periodically to solicit
questions

11
Asking Questions
- Welcome questions!!
- Feel free to raise your hand at any time with a
question
- We’ll also pause periodically to solicit
questions
- We’re not going to do audience “questions” in
lecture that are just showing off that you
know some jargon or advanced topic
12
Total Score

Total Score = 30% Usual Performance + 70% Final Exam Results

13
Community Norms
- Shame-free zone
- Treat your peers and instructors with kindness
and respect
- Be curious
- Communication is key!
- Recognize we are all in-process (humility,
question posing, avoid perfectionism)

14
Lecture
- C++ is a huge language. I want you to get
practice with some things, exposure to others,
and a lot is not covered.

17
Lecture
If you feel ill or are sick, for the wellbeing of
yourself and others please stay home, take care
of yourself, and reach out to us - we never want
you to feel that you must attend class if you
are not feeling well!
Similarly, if you have an emergency or
exceptional circumstance, please reach out to
use so that we can help

18
Learning Outcomes
- Practice using industry standard coding tools
such as ssh and VSCode
- Gain familiarity with powerful features of the stl
- Practice reading documentation to learn how to
use a new language feature
- Exposure to standard c++ syntax and norms
- Learn a few “advanced” features of classes

25
Questions?

26
Why C++?

30
C++ is still a very popular language

Tiobe Index, 2021

31
Many Cool Things Use/Were Made with C++

33
Why C++?
FAST Lower-level control
Ruby

Javascript
High
Level
Python

Java

C++

C
Low
Level Assembly

Machine Code
34
What is C++?

35
Some C++ Code

#include <iostream>

int main() {
std::cout << "Hello, world!" << std::endl;
return 0;
}

36
Also some C++ Code

#include "stdio.h"
#include "stdlib.h"

int main(int argc, char *argv) {


printf("%s", "Hello, world!\n");
// ^a C function!
return EXIT_SUCCESS;
}

37
Also (technically) some C++
code
#include "stdio.h"
#include "stdlib.h"

int main(int argc, char *argv) {


asm( "sub $0x20,%rsp\n\t" // assembly code!
"movabs $0x77202c6f6c6c6548,%rax\n\t"
"mov %rax,(%rsp)\n\t"
"movl $0x646c726f, 0x8(%rsp)\n\t"
"movw $0x21, 0xc(%rsp)\n\t"
"movb $0x0,0xd(%rsp)\n\t"
"leaq (%rsp),%rax\n\t"
"mov %rax,%rdi\n\t"
"call __Z6myputsPc\n\t"
"add $0x20, %rsp\n\t"
);
return EXIT_SUCCESS;
}

38
C++ History: Assembly
section .text
global _start ;must be declared for linker (ld)

_start: ;tell linker entry point

mov edx,len ;message length


mov ecx,msg ;message to write
mov ebx, 1 ;file descriptor (stdout)
mov eax, 4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax, 1 ;system call number (sys_exit)
int 0x80 ;call kernel

section .data
msg db 'Hello, world!' ,0xa ;our dear string
len equ $ - msg ;length of our dear string

39
C++ History: Assembly
Benefits:
- Unbelievably simple instructions
- Extremely fast (when well-written)
- Complete control over your program
Why don’t we always use Assembly?

40
Assembly looks like this
section .text
global _start ;must be declared for linker (ld)

_start: ;tell linker entry point

mov edx,len ;message length


mov ecx,msg ;message to write
mov ebx, 1 ;file descriptor (stdout)
mov eax, 4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax, 1 ;system call number (sys_exit)
int 0x80 ;call kernel

section .data
msg db 'Hello, world!' ,0xa ;our dear string
len equ $ - msg ;length of our dear string

41
C++ History: Assembly
Drawbacks:
- A LOT of code to do simple tasks
- Very hard to understand
- Extremely unportable (hard to make work
across all systems)

42
Next in C++ History: Invention of C
Problem: computers can only understand assembly!
- Idea:
- Source code can be written in a more intuitive
language
- An additional program can convert it into
assembly
- This additional program is called a
compiler!
- Take CS143 to learn more!
43
C++ History: Invention of C
- T&R created C in 1972, to much praise
- C made it easy to write code that was
■ Fast
■ Simple
■ Cross-platform
- Learn to love it in CS107!
Ken Thompson and Dennis
Ritchie, creators of the C
language.
44
C++ History: Invention of C
- C was popular because it was simple.
- This was also its weakness:
- No objects or classes
- Difficult to write generic code
- Tedious when writing large programs

45
C++ History: Welcome to C++!
- In 1983, the beginnings of C++ were created by
Bjarne Stroustrup.
- He wanted a language that was:
- Fast
- Simple to use
- Cross-platform
- Had high-level features

The man himself <3

46
C++ History: Evolution of We are here
C++

C++ C++03 C++14 C++20

1979 1983 1998 2003 2011 2014 2017 2020 ?

C with
C++98 C++11 C++17 C++23
Classes

47
Design Philosophy of C++

48
Design Philosophy of C++
- Only add features if they solve an actual problem
- Programmers should be free to choose their own
style
- Compartmentalization is key
- Allow the programmer full control if they want it
- Don’t sacrifice performance except as a last resort
- Enforce safety at compile time whenever possible

49
Design Philosophy of C++
- Only add features if they solve an actual problem
- Programmers should be free to choose their own
style
- Compartmentalization is key
- Allow the programmer full control if they want it
- Don’t sacrifice performance except as a last resort
- Enforce safety at compile time whenever possible

50
Design Philosophy of C++
- Only add features if they solve an actual problem
- Programmers should be free to choose their own
style
- Compartmentalization is key
- Allow the programmer full control if they want it
- Don’t sacrifice performance except as a last resort
- Enforce safety at compile time whenever possible

51
Questions?

52
But...What is C++?

53
C++: Basic Syntax + the STL
Basic syntax The STL
- Semicolons at EOL - Tons of general
- Primitive types (ints, functionality
doubles etc) - Built in classes like
- Basic grammar rules maps, sets, vectors
- Accessed through the
namespace std::

55
Standard C++: Basic Syntax + std library
Basic The STL
syntax
- Tons of
- Semicolons at general
EOL functionality
- Built
- Primitive in classes
types (ints, like maps, sets, vectors
- Accessed
doubles etc) through the namespace std::
- Basic- grammar
Extremely powerful and well-maintained
rules

56

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy