Lecture 1
Lecture 1
Autumn 2019
Lecture 1: Introduction
Clip art and quote credits: Various sources found through Google
Image Search
about these slides
• based on Chapter 1 of the book
– An Introduction to Programming
through C++
by Prof. Abhiram Ranade (Tata McGraw Hill, 2014)
• what is a computer?
• what is programming?
• the computer
– a machine in the automation world that has influenced almost
all aspects of our existence
– has some properties unique/different from other machines
vs.
• a computer
– is an electronic device with complex circuitry
– is a programmable device
Weather prediction
Help design physical systems: say water network
all of us have already used a computer!
– Calculator
– ATM
– Smartphone
(is a computer)
• Lecture slots
(Section S1) Slot 11
Tuesdays 3:30 PM – 5:00 PM & Fridays 3:30 PM – 5:00 PM
(Section S2) Slot 5
Wed 9:30 AM – 11:00 AM & Fridays 9:30 AM – 11:00 AM
• Lab sessions
Tuesdays, Wednesdays and Thursdays 8 PM until 11 PM
in SL1, SL2 and Basement lab (newCSE building)
• we already do this …
– which route to take to reach LA001?
– what time to wake up for class?
– how to book an ola/uber ride?
– how to prepare for an exam?
– …
#include <simplecpp>
main_program {
turtleSim();
forward(200); right(90);
forward(200); right (90);
forward(200); right(90);
forward(200);
}
The square drawing program
Some magic abracadabra: ignore
the program will use the
#include <simplecpp> simplecpp package.
turtleSim();
forward(200); right(90); This sequence of commands in
C++ is the program
forward(200); right(90);
forward(200); right(90);
Some commands need
forward(200); additional information called
arguments
wait(10); • 90 is the argument to the
} command right
• 200 is the argument to the
command forward
General Ideas (contd)
#include<simplecpp>
main_program{
turtleSim(); Commands are
forward(200); generally executed
right(90); from top to bottom, left
forward(200); to right.
right(90);
forward(200);
right(90);
forward(200);
wait(10);
}
how to draw an octagon?
#include <simplecpp>
main_program{
turtleSim();
repeat(8){
forward(100);
right(45);
}
}
repeat(8){ repeat(num_sides){
forward(10); forward(10);
right(45); right(360.0/num_sides);
} }
} }
#include <simplecpp>
main_program{
turtleSim(); Tell the computer: Reserve space in
your memory where I can store an
integer (int). I will refer to it by the
int num_sides; name num_sides
repeat(num_sides){
forward(10); We need some magic so that
num_sides can have the right
right(360.0/num_sides);
value
}
}
Divide the number 360 by the number stored in the
space named num_sides and pass the result as
an argument to this command
7/30/19 Autumn 2019 CS101@CSE IIT Bombay 31
Explanation
#include <simplecpp>
main_program{
turtleSim(); Print the sentence within the quotes
on the screen
cout è “Console out” (display)
int num_sides;
exterior_angle =
sum_exterior/num_sides;
repeat(num_sides) {
forward(side_length);
right(exterior_angle);
}
}
language syntax
• syntax = grammatical rules indicating how commands
must be written
repeat(4){
repeat(3){
forward(50); penUp(); It will draw a
forward(50); penDown(); square with dashed
lines
}
right(90);
}
#include <simplecpp>
main_program{
cout << “a”;
repeat(5){
cout << “b”;
repeat(2){ cout << “c”; }
cout << “d”;
}
}
what does the following program do?
#include <simplecpp>
main_program{
cout << “a”;
repeat(5){
cout << “b”;
repeat(2){ cout << “c”; }
cout << “d”;
}
}
abccdbccdbccdbccdbccd
curly braces group statements
• Compiling a program:
translating it into a form that a computer can
understand
Header
char, short, int, float,
iostream
files
string
math
double, if, switch, while, … Bash
shell
C/C++ execution environment
Precompiled
libraries
Operating system (Windows, Linux, Mac OS, …)
CPU
7/30/19 RAM Disk Keyboard
Autumn 2019 CS101@CSE IIT Display 50
Bombay
PC building blocks: motherboard
CPU with
cooling fan
Fast
electronic
memory
Magnetic
disk data
connectors
7/30/19 Autumn 2019 CS101@CSE IIT 51
Bombay
Storage and peripheral devices
Keyboard
Display
Rotating
magnetic
platters
Random access
Program that tells the memory (RAM)
CPU what to do and
how to do it
7/30/19 Autumn 2019 CS101@CSE IIT 53
Bombay