CS 101: Introduction to computer programming and utilization Abhiram Ranade.

23
CS 101: Introduction to computer programming and utilization Abhiram Ranade

Transcript of CS 101: Introduction to computer programming and utilization Abhiram Ranade.

Page 1: CS 101: Introduction to computer programming and utilization Abhiram Ranade.

CS 101: Introduction to computer

programming and utilization

Abhiram Ranade

Page 2: 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.

Page 3: CS 101: Introduction to computer programming and utilization Abhiram Ranade.

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!

Page 4: CS 101: Introduction to computer programming and utilization Abhiram Ranade.

Grading

10 % : Quiz 1

25 % : Midterm

10 % : Quiz 2

40 % : Final Examination

7 % : Lab assignments

8 % : Lab Project

Page 5: CS 101: Introduction to computer programming and utilization Abhiram Ranade.

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

Page 6: CS 101: Introduction to computer programming and utilization Abhiram Ranade.

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

Page 7: CS 101: Introduction to computer programming and utilization Abhiram Ranade.

Lab

10 batches, each with about 70 students.

109Friday

87Thursday

65Wednesday

43Tuesday

21Monday

8:30-10:306:30-8:30

Page 8: CS 101: Introduction to computer programming and utilization Abhiram Ranade.

Which batch are you in?

You will receive an e-mail telling you which

batch you are in.

Please check your e-mail.

Page 9: CS 101: Introduction to computer programming and utilization Abhiram Ranade.

Labs Begin This Week

Venue: “Old Software Lab”, Ground Floor of 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.

Page 10: CS 101: Introduction to computer programming and utilization Abhiram Ranade.

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.

Page 11: CS 101: Introduction to computer programming and utilization Abhiram Ranade.

This week’s assignment

Use a “Turtle Simulator” developed by your 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!

Page 12: CS 101: Introduction to computer programming and utilization Abhiram Ranade.
Page 13: CS 101: Introduction to computer programming and utilization Abhiram Ranade.

Program to draw a square

procedure turtleMain(){

forward(10);

right(90);

forward(10);

right(90);

forward(10);

right(90);

forward(10);

}

Page 14: CS 101: Introduction to computer programming and utilization Abhiram Ranade.

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,

“procedure you called”.

Other numbers can be given instead of 10. Turtle

moves forwards that many steps.

right(90): turn right 90˚. Another procedure.

Page 15: CS 101: Introduction to computer programming and utilization Abhiram Ranade.

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

Click the “X” to remove the picture.

Page 16: CS 101: Introduction to computer programming and utilization Abhiram Ranade.

How to draw a square 2

procedure turtleMain(){

repeat(4){

forward(10);

right(90);

}

}

Page 17: CS 101: Introduction to computer programming and utilization Abhiram Ranade.

How to draw a polygon

procedure turtlec(){

cout << “How many sides?”

int nsides;

cin >> nsides;

repeat(nsides){

forward(10);

right(360/nsides);

}

}

Page 18: CS 101: Introduction to computer programming and utilization Abhiram Ranade.

Explanation of statements

“int nsides;” : Reserve a cell for me in memory in

which I will store some integer value, and call that cell

“nsides”.

“cout << ...”: Print that message on the screen.

“cin >> nsides;” Read an integer value from the

keyboard and put it in the cell nsides.

nside: Variable taking integer values. Can be used

wherever numbers may appear.

Page 19: CS 101: Introduction to computer programming and utilization Abhiram Ranade.

Repeat Statement

repeat (x) { ... } : causes the instructions inside

{ } to be executed x times.

Page 20: CS 101: Introduction to computer programming and utilization Abhiram Ranade.

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.

Page 21: CS 101: Introduction to computer programming and utilization Abhiram Ranade.

Repeat within repeat

repeat(4){

repeat(3){

forward(10); penup(); forward(10); pendown();

}

right(90);

}

Page 22: CS 101: Introduction to computer programming and utilization Abhiram Ranade.

A necessary Mantra

Put following lines in your file

#include <turtlesim>;

This allows you to use the turtle simulator.

Page 23: CS 101: Introduction to computer programming and utilization Abhiram Ranade.

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.