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

lecture1

CS 101 is an introductory programming course for Spring 2024, focusing on C++ and computational thinking. The course includes lectures, labs, and evaluations, with a strong emphasis on good coding practices and debugging. Students will learn to write programs using simplecpp and will be introduced to programming concepts through practical exercises, including drawing shapes with a turtle simulator.

Uploaded by

Naitik Agarwal
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 views26 pages

lecture1

CS 101 is an introductory programming course for Spring 2024, focusing on C++ and computational thinking. The course includes lectures, labs, and evaluations, with a strong emphasis on good coding practices and debugging. Students will learn to write programs using simplecpp and will be introduced to programming concepts through practical exercises, including drawing shapes with a turtle simulator.

Uploaded by

Naitik Agarwal
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/ 26

Introduction to Programming (CS 101)

Spring 2024

Lecture 1:
- Introduction; Course Administration
- Start coding with simple programs Instructor: Preethi Jyothi

- Based on material developed by Prof. Abhiram Ranade and Prof. Manoj Prabhakaran
Computers

• Computers are an integral part of our daily lives:


• Cyber-physical systems in smart grids, medical device monitoring, ...
• Embedded systems inside your smart phones, TVs, home appliances, ...
• Computer systems grouped together in large networks: Internet, email, search, etc.

• Computers are machines that can be instructed (via programs or code) to carry out a
wide variety of tasks

Images from: https://www.aiwire.net/2014/08/04/beginnings-hyperscale-google/ and https://www.google.com/about/datacenters/data-security/


What will this course teach you?

• Computer programming: Involves writing instructions in a speci c computer language


for a computer to follow

• Ability to computationally think about problems

• Good coding/programming practices

Image from: https://xkcd.com/1513/

fi
Programming language for CS101: C++
• C Programming Language (created in 1970s by Dennis Ritchie)
• Developed to build the Unix operating system
• Consistently among the top four programming languages[1]

• C++ Programming Language (created in 1980s by Bjarne Stroustrup)


• Originally an extension of C, and signi cantly expanded over time
• Standards: C++98, C++03, C++11, C++14, C++17, C++20, C++23, ...

[1]Based on the TIOBE index: https://en.wikipedia.org/wiki/TIOBE_index


Image from: https://www.modernescpp.com/index.php/c26-the-next-c-standard/
fi
Programming language for CS101: C++
• C Programming Language (created in 1970s by Dennis Ritchie)
• Developed to build the Unix operating system
• Consistently among the top four programming languages[1]

• C++ Programming Language (created in 1980s by Bjarne Stroustrup)


• Originally an extension of C, and signi cantly expanded over time
• Standards: C++98, C++03, C++11, C++14, C++17, C++20, C++23, ...

• In this course, we will learn a subset of very important features of C++

[1] Based on the TIOBE index: https://en.wikipedia.org/wiki/TIOBE_index


fi
Programming environment

• Initial Weeks: C++ augmented with simplecpp

• simplecpp is a C++ library developed at IITB by Prof. Abhiram Ranade

• Convenient for beginners to programming:


• Easy-to-use wrappers to simplify syntax
• Graphics programming -- more visual, more fun!

• Download this le to set up simplecpp: https://drive.google.com/ le/d/


1nJMm1KwlXkqAKHIVDi-Xt3HrImMJM7Tx/view?usp=sharing (Will also be posted on Moodle/
Bodhitree)

• Later Weeks: Transition to C++


fi
fi
How do you get good at programming?

"The only way to learn a new programming language is by writing programs in it"
- Dennis Ritchie, Creator of the C programming language, Turing Award (1983)

• You will see your rst program in class today.

• Seeing programs is necessary but not suf cient.

• In your rst lab, you will set up your system and start coding!
fi
fi
fi
Course Administration and Trivia
CS 101, 2025
Course personnel
• Instructor: Preethi Jyothi (Associate Professor, CSE@IITB, https://www.cse.iitb.ac.in/~pjyothi)

• Course Manager: Firuza Nageshrau Karmali ( [email protected])

• CS101 RAs: Sanchit Kadwe (24M0836), Mayur Pokharkar (24M0840)

• TAs: Large ≈100 strong team of TAs! Visit https://www.cse.iitb.ac.in/~cs101/team.html

fi
Course logistics
CS101 every week: Two lectures (3 hours), One lab (2 hours)

Lectures: Posted on Moodle right before/after class. Also, additional reading material (at times)

Course Website: https://www.cse.iitb.ac.in/~cs101/

Attendance: Follow institute policy and use SAFE. TAs will mark attendance in labs.

Bodhitree: Learning management system. All lab-related updates, submissions, exams.

Class Announcements: Made via Moodle or Bodhitree. Please check your emails.

Asynchronous Q&A: Approach your TAs or the course manager (Firuza, [email protected])

Extra Help Sessions: Schedule up on https://www.cse.iitb.ac.in/~cs101/

fi
Course resources

Textbook: "An Introduction to Programming through C++",


Abhiram Ranade, McGraw Hill Education, 2014.

Website: https://www.cse.iitb.ac.in/~ranade/book.html
Available in physical and online bookstores.
Integrated with use of simplecpp

Course Material: My slides, sample programs, links to additional reading (all on Moodle)

Online Course: Prof. Abhiram Ranade's NPTEL course


https://archive.nptel.ac.in/noc/courses/noc21/SEM1/noc21-cs38/
Evaluation (with schedule)
Theory Quiz 1 [Feb 5, 2025] ( 7% )
Lab Quiz 1 [Feb 15-16, 2025] ( 13% )
Midsem Exam [Feb 22 - Mar 2, 2025] ( 20% )
Theory Quiz 2 [Mar 26, 2025] ( 7% )
Lab Quiz 2 [Apr 12-13, 2025] ( 13% )
Endsem Exam [Apr 21 - May 1, 2025] ( 30% )
Participation [Weekly labs] ( 10% )

• Last date for showing answer sheets: May 5, 2025


• Plan your travel after May 5, 2025
• Make-up tests will be offered only for medical reasons. (Show doctor's note to avail of
this option.) This will be a mix of theory/lab, held after the endsem exam.
Academic integrity

Code of conduct:
Abide by the following honour code.

• Do not copy, give or receive code during quizzes and exams.

• Attempt lab exercises on your own. You can consult TAs, classmates, reference
material, but work on the submissions by yourself. Very useful to identify gaps in
understanding.

• If you need help, contact the personnel! (Recall: Extra help sessions.)

• If caught for copying or plagiarism, name of both parties will be handed over to
the Department Disciplinary Action Committee (DDAC)1.

1http://www1.iitb.ac.in/newacadhome/punishments201521July.pdf
Let's Get Coding!
CS 101, 2025
First program: Drawing pictures

• First few programs you will draw pictures on the screen

• Use "Turtle Simulator" contained in simplecpp


• Based on Logo: A language invented for teaching programming to children by
Seymour Papert et al.
• Give commands to a turtle to move around.
• To move the turtle, you write a C++ program.
• Turtle has a pen, so it draws as it moves.
The rst program: Draw a square

• Use simplecpp in the rst few lectures; invoked via


#include <simplecpp>

#include <simplecpp> • Main program starts with main_program and


main_program { enclosed within { }
turtleSim(); • turtleSim(): Starts the turtle simulator. Opens a
forward(100); right(90); window and a turtle at centre facing right
forward(100); right(90);
forward(100); right(90); • forward(n): Move the turtle n pixels in the direction
forward(100); it is currently facing
90 is an
getClick(); argument
• right(k): Turn the turtle k degrees to the right
}
• Note: Semicolons, used as punctuators in C++
• getClick(): Wait for a click
fi
fi
How to run the program?

if error

if error

Instruct your
Use an editor
Use a C++ OS to
(e.g., vim) or
compiler execute the
an IDE text le binary le
(e.g., g++) code (e.g.,
(e.g.,
via shell
VSCode)
commands)
Write Compile Run
fi
fi
Errors or Bugs

• A "bug" is a defect in the program (either in its syntax


or logic)
• Common bugs include syntax errors (e.g., missing
semicolon), runtime errors (e.g., divide by zero),
logical errors
• Debugging: Process of nding and xing bugs in
your code

Image from Reddit


fi
fi
Errors or Bugs

• A "bug" is a defect in the program (either in its syntax


or logic)
• Common bugs include syntax errors (e.g., missing
semicolon), runtime errors (e.g., divide by zero),
logical errors
• Debugging: Process of nding and xing bugs in
your code

• Small bugs can create havoc in large systems


• Recent example: Crowdstrike bug [1]

[1] https://en.wikipedia.org/wiki/2024_CrowdStrike-related_IT_outages
fi
fi
Redundancy in code?

#include <simplecpp>
main_program {
turtleSim();
forward(100); right(90);
forward(100); right(90);
forward(100); right(90);
forward(100);
getClick();
}
Use the repeat statement

repeat(n) {

body

} body consists of one or more statements

• What does this block of code do? body is executed n times

• This is a "loop" (other loop structures will be covered later on)

• Each execution of body within a loop is called an "iteration"


Draw a square using repeat
#include <simplecpp>
main_program {
turtleSim();
repeat(4) {
forward(100);
"Indentation"
right(90);
}
getClick();
}

• Indentation, with appropriate spaces, makes the code readable

• You can use 2, 3 or 4 spaces, but be consistent with this usage

• More about indentation later, as you learn more about conditional blocks, loops, functions, etc.
More simplecpp commands

• left(d): Turn left d degrees; equivalent to right(-d)

• penUp(), penDown(): Pen is raised or lowered, respectively. To get the turtle to draw as it
moves, the pen should be lowered.
• hide(): Pen visual (a triangle) is hidden

• sqrt(x): Square root of x

• sine(x), cosine(x), tangent(x): x should be in degrees

• Refer to the book for more commands


Code to draw a hexagon, polygon, dotted line

Demo in class and code shared on Moodle


Exercises to try on your own

Draw a circle. Draw a square of side 100 and


inscribe a square inside it.

Hint: Draw a regular polygon with a Hint: Use Pythagoras’ theorem to


large number of sides nd the length of the inscribed square
fi
Next class: Variables, Operators, Data types
CS 101, 2025

You might also like