0% found this document useful (0 votes)
6 views32 pages

Lecture 1

The document outlines a C++ programming course (CSCI 3142) taught by Priyanka Samanta, detailing office hours, communication methods, grading structure, and course resources. It covers the basics of C++, including its advantages and disadvantages, how compilers and interpreters work, and various programming concepts such as data types, variables, and operators. The course utilizes open access resources and emphasizes practical coding skills through assignments and projects.

Uploaded by

Adnaan Syed
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)
6 views32 pages

Lecture 1

The document outlines a C++ programming course (CSCI 3142) taught by Priyanka Samanta, detailing office hours, communication methods, grading structure, and course resources. It covers the basics of C++, including its advantages and disadvantages, how compilers and interpreters work, and various programming concepts such as data types, variables, and operators. The course utilizes open access resources and emphasizes practical coding skills through assignments and projects.

Uploaded by

Adnaan Syed
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/ 32

Programming

Paradigms in C++
CSCI 3142

By

Priyanka Samanta
Office hours
By appointment (Preferably on Mon,
Tue, Wed)
Room number: 2122b Ingersoll
Through Blackboard

How to access All announcements will be


made on blackboard
the course Grades will be uploaded on
materials? the blackboard
Code links and PPTs will
be uploaded on blackboard
Course resource
• This course uses only open access educational resources and class notes
and codes provided in class.

• Books:
• C++ by Bjarne Stroustrup (advanced)
• Starting Out with C++ from Control Structures to Objects 8 Tony Gaddis
Grades

• Unit Test: 3 X 20%


• Final: 40%

• Question Types:
MCQ, True/False,
Guess the output,
Find the error, coding
Email
samanta@sci.brooklyn.cuny.edu.
Emails to other addresses will not
necessarily be seen or answered

Communication
Email subject header CISC 3142
must have the MW11– your
following: name – topic.
Why C++
"If there was a programmers party in
which all programming languages and
all programmers in the world are invited,
the C++ programmers would have their
own table".
Why C++
▪ Used to write fast code that performs well ->SIMULA+C
▪ General purpose language: Direct control on hardware
➢ Game industry ->Unity, Unreal, Frostbite
➢ Operating system
➢ Browser, compiler
➢ Embedded system/automation/dabase/photoshop
➢ Big data tensorflow library, Google’s MapReduce
Why C++
▪ Competitors: Rust, Go
▪ Code->compiler->Machine code->CPU executes
▪ Platform independent (Windows, MAC, Linux, IOS, Android, XBOX, Play-station)
▪ Available from 80’s, popular
▪ C++ is a native code (generates machine codes for target platform, no translation
required)
▪ Warning:
Cons of C++
• Complex
• Difficult to learn
• Using an object-oriented programming language like C++ comes with several security issues because of
features like pointers, friend functions and global variables.
• The pointers that are used in C++ take up a lot of memory which is not always suitable for some devices,
and using them incorrectly can cause your whole system to crash or behave strangely, which is a major
drawback.
• Bad C++ code is not fast (slower than C#, Java)
Why C++
This course Covers
▪ Basics of C++ (Briefly)
▪ Use of libraries to enhance performance
▪ Memory management and pointers
▪ Smart pointers
▪ Templates and how to use them properly
▪ Macros
▪ OOP in C++ (class, inheritance, polymorphism)
▪ Data structures using STL
How C++ compiler works
• Preprocessor read the source code (.cpp)
• Preprocessor searches for preprocessor derivatives
(line code starting with a # )
• Preprocessor changes your code by adding
libraries/header files (intermediate file)
• Compiler translates intermediate file line by line to
object file (.obj)
• Check for errors
• Linker combines object file with library files, header
files and create executable code (.exe)
• Loader loads the .exe file to RAM, so that CPU can
execute
• CPU provides output
How interpreter works
• Java script is an interpreted language and Chrome works as interpreter Source code

• It will translate the code line by line and execute


• Will not create a separate .exe file
• Every time you need interpreter to execute the code Interpreter

• Interpreter is slower but easy to run


Hybrid Language
• Java, C# are hybrid language as they use
both compiler and interpreter
• Compiler checks for error and generate byte
code (.class)
• JVM acts as interpreter, translates byte
code to executable file
• Different JVM designed for different OS
and byte code is able to run on different OS
Install Compiler and IDE for
Windows
• CodeBlock
• DevC++
• Visual studio
http://www.brooklyn.cuny.edu/web/academics/schools/naturalsciences/depar
tments/computers/resources.php
Install Compiler and IDE for
MAC
• Xcode
(https://www.youtube.com/watch?v=1E_kBSka_ec&list=PLlrATfBNZ98dud
nM48yfGUldqGD0S4FFb&index=3)
• CodeBlock
(http://www.brooklyn.cuny.edu/web/academics/schools/naturalsciences/de
partments/computers/resources.php)
Online platform Replit
https://replit.com/

Compile your code: clang++-7 -pthread -o program program.cpp


Skeleton of C++
What is namespace?
using namespace std: Why it is not a good practice?

A common problem of "using namespace std" is if you try to create your own
function and give it the same name that is already present in std namespace,
that can lead to name collisions and ambiguity.

Code link: https://replit.com/@SamantaPriyanka/variables1#namespace.cpp


Data types
Size and ranges
• The size of a type is
implementation
defined
• Can be obtained by
sizeof() operator
Ex:
char x;
cout<<sizeof(x)<<endl;

O/p: 1
Modifiers

The modifiers signed and unsigned can also be used as


prefix to long or short modifiers. For example, unsigned
long int.
Variables & Literals
Always initialize your Literal: Values which
variables, otherwise are self evident
stores garbage. known as literal
Integer literals
•decimal (base 10)
•octal (base 8)
•hexadecimal (base 16)

•Code link: https://replit.com/@SamantaPriyanka/variables1#int_literal.cpp


Floating point literals
-2.0
• Decimal point
0.0000234
• Exponent specified scientific notation
-0.22E-5

• Code link:
https://replit.com/@SamantaPriyanka/variables1#float_literal.cpp
Character and character
string literal
• A character literal is created by enclosing a single character inside single
quotation marks. For example: 'a', 'm', 'F', '2', '}' etc.
• A string literal is created by enclosing zero or more characters inside double
quotation marks. For example: "", "x“, "good“, "Earth is round\n“ etc.
Auto
• C++11 feature
• When defining a variable, you don’t actually need to state its type explicitly when it can be deduced from
the initialization.
• With ‘auto’ we use = syntax
• We write auto where we are not worried about precision or clear readability
• Use in generic program when it is hard to know exact object type or the name is quite long

• Code link: https://replit.com/@SamantaPriyanka/variables1#variables.cpp


Operators & Expressions
Operators & Expressions
Operators & Expressions
Operators & Expressions

You might also like