CS 101 Introduction to computer programming and utilization

  • Slides: 23
Download presentation
CS 101: Introduction to computer programming and utilization Abhiram Ranade

CS 101: Introduction to computer programming and utilization Abhiram Ranade

Course Overview How to represent problems on a computer and solve them Programming examples

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:

Course Resources Textbook: Cohoon & Davidson, C++ Program Design. Lecture slides on course homepage: www. cse. iitb. ac. in/~cs 101 Other resources from the web Previous years' course pages. Teaching Assistants, and me!

Grading 10 % : Quiz 1 25 % : Midterm 10 % : Quiz

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

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

Lectures Students divided into 4 divisions. Each lecture first to Divisions 1, 2, and again to Divisions 3, 4. Div 1, 2: Slot 3 A, 3 B. Tue: 11: 30 -12: 30 Div 3, 4: Slots 2 A, 2 C Mon 10: 30 -11: 30, Mon 9: 30 -10: 30, Thu: 11: 30 -12: 30 Venue: PC Saxena Auditorium

Lab 10 batches, each with about 70 students.

Lab 10 batches, each with about 70 students.

Which batch are you in? You will receive an e-mail telling you which batch

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

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/4 th 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

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.

This week’s assignment Use a “Turtle Simulator” developed by your TAs. You can drive

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!

Program to draw a square procedure turtle. Main(){ forward(10); right(90); forward(10); }

Program to draw a square procedure turtle. Main(){ forward(10); right(90); forward(10); }

Procedures and Procedure Calls turtle. Main : Procedure you wrote. The simulator will execute

Procedures and Procedure Calls turtle. Main : Procedure you wrote. The simulator will execute this procedure after it sets up 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.

How to run this program Log in to an OSL computer. Open an editor

How to run this program Log in to an OSL computer. Open an editor and type in the program call it turtle 1. cpp Compile it. Run it Click the “X” to remove the picture.

How to draw a square 2 procedure turtle. Main(){ repeat(4){ forward(10); right(90); } }

How to draw a square 2 procedure turtle. Main(){ repeat(4){ forward(10); right(90); } }

How to draw a polygon procedure turtlec(){ cout << “How many sides? ” int

How to draw a polygon procedure turtlec(){ cout << “How many sides? ” int nsides; cin >> nsides; repeat(nsides){ forward(10); right(360/nsides); } }

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

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.

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

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

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(4){ repeat(3){ forward(10); penup(); forward(10); pendown(); } right(90); }

Repeat within repeat(4){ repeat(3){ forward(10); penup(); forward(10); pendown(); } right(90); }

A necessary Mantra Put following lines in your file #include <turtlesim>; This allows you

A necessary Mantra Put following lines in your file #include <turtlesim>; This allows you to use the turtle simulator.

Homework Draw a 5 pointed star. Draw a 7 pointed star. How many different

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 4 x 4 array of tiles slightly separated from each other.