CS 101: Introduction to computer programming and utilization
Abhiram Ranade
Course Overview
How to represent problems on a computer and solve them
Programming examples to be drawn from CSE, Mathematics, Engineering, and anything fun! C++ programming language Not much on hardware.
Course Resources
Textbook: Cohoon & Davidson, C++ Program Design. Lecture slides on course homepage: www.cse.iitb.ac.in/~cs101 Other resources from the web Previous years' course pages. Teaching Assistants, and me!
Grading
10 % : Quiz 1
25 % : Midterm
10 % : Quiz 2
40 % : Final Examination
7 % : Lab assignments
8 % : Lab Project
Teachers
Lecturer: Abhiram Ranade.
10 Senior Teaching Assistants (Mtech 2)
5 lab supervisors
5 other duties
55 Junior Teaching Assistants. (Mtech 1)
40 lab supervisors 15 Consultants
Lectures
Students divided into 4 divisions. Each lecture first to Divisions 1,2, and again to Divisions 3,4.
Div 1,2: Slot 3A,3B.
Mon 10:30-11:30,
Tue: 11:30-12:30
Div 3,4: Slots 2A, 2C
Mon 9:30-10:30,
Thu: 11:30-12:30
Venue: PC Saxena Auditorium
Lab
10 batches, each with about 70 students. 6:30-8:30
Monday 1
8:30-10:30
2
Tuesday
Wednesday
3
5
4
6
Thursday
Friday
7
9
8
10
Which batch are you in?
You will receive an e-mail telling you which batch you are in.
Please check your e-mail.
Labs Begin This Week
Venue:“OldSoftwareLab”,GroundFloorof Math Building.
Show up at your batch time. Lab will be conducted by 1 senior TA and 4 Junior TAs.
Each junior TA will grade the work of 1/4th of each batch, called a section.
Sections: find out in the first session.
Lab Assignments
Assignment for this week: handout will be given when you go to the lab
how to log in,
how to use an editor to write a program,
how to compile the program and run it. General information about Unix
Lab assignments are meant more for you to practice than for us to grade you.
Thisweek’sassignment
Usea“TurtleSimulator”developedbyyour TAs.
You can drive around the turtle. Turtle has a pen, so it draws as it moves. To drive the turtle you write a simple C++ program. It is easy, you will all be driving your turtles in no time!
Program to draw a square
procedure turtleMain(){ forward(10); right(90); forward(10);
right(90);
forward(10); right(90); forward(10); }
Procedures and Procedure Calls
turtleMain : Procedure you wrote. The simulator will execute this procedure after it sets up the the window on the screen etc.
forward(10) : procedure you are asking to execute, “procedureyoucalled”.
Other numbers can be given instead of 10. Turtle moves forwards that many steps. right(90): turn right 90˚. Another procedure.
How to run this program
Log in to an OSL computer.
Open an editor and type in the program call it turtle1.cpp Compile it.
Run it
Clickthe“X”toremovethepicture.
How to draw a square 2
procedure turtleMain(){
repeat(4){
forward(10);
right(90);
}
}
How to draw a polygon
procedure turtlec(){ cout“<<Howmanysides?” int nsides;
cin >> nsides;
repeat(nsides){ forward(10); right(360/nsides); } }
Explanation of statements
“intnsides;”:Reserveacellformeinmemoryin which I will store some integer value, and call that cell “nsides”.
“cout:”...<<Printthatmessageonthescreen.
“cin>>nsides;”Readanintegervaluefromthe keyboard and put it in the cell nsides. nside: Variable taking integer values. Can be used wherever numbers may appear.
Repeat Statement
repeat (x) { ... } : causes the instructions inside { } to be executed x times.
More procedures for you
penup(): Causes the pen to be raised.
pendown(): Causes the pen to be lowered.
(): Unlike forward which needs one number to decide how much forward to move, penup/down does not need any numbers.
Repeat within repeat
repeat(4){
repeat(3){
forward(10); penup(); forward(10); pendown(); }
right(90);
}
A necessary Mantra
Put following lines in your file
#include ;
This allows you to use the turtle simulator.
Homework
Draw a 5 pointed star. Draw a 7 pointed star. How many different 7 pointed stars can you have? Draw 7 identical circles, with 6 touching the central circle. Circle = polygon of large no of sides, say 360.
Draw 4x4 array of tiles slightly separated from each other.