cs 101 computer programming and utilization
play

CS 101 Computer Programming and Utilization Puru with several - PowerPoint PPT Presentation

CS 101 Computer Programming and Utilization Puru with several CS101 TAs and CSE staff Course webpage: http://www.cse.iitb.ac.in/~cs101/ Lecture 1: Introduction Clip art and quote credits: Various sources found through Google Image Search


  1. CS 101 Computer Programming and Utilization Puru with several CS101 TAs and CSE staff Course webpage: http://www.cse.iitb.ac.in/~cs101/ Lecture 1: Introduction Clip art and quote credits: Various sources found through Google Image Search

  2. about these slides • based on Chapter 1 of the book – An Introduction to Programming through C++ by Prof. Abhiram Ranade (Tata McGraw Hill, 2014) • original slides by Abhiram Ranade – updates and contributions by Varsha Apte, Uday Khedker, Sunita Sarawagi, Umesh Bellur, Om Damani, Ganesh Ramakrishnan 7/30/19 3 Autumn 2019 CS101@CSE IIT Bombay

  3. some questions • why a computer? • what is a computer? • what is programming? 7/30/19 4 Autumn 2019 CS101@CSE IIT Bombay

  4. why computer? • yet another option on the human-machine axis • automation for doing work – efficiently, quickly, new discoveries/explanations etc. • 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 7/30/19 6 Autumn 2019 CS101@CSE IIT Bombay

  5. what is unique about a computer? vs. 7/30/19 7 Autumn 2019 CS101@CSE IIT Bombay

  6. what is a computer? • computer: a machine that can do (specified) work – … that can compute • compute : perform (elaborate) calculations – combination of mathematical and logical operations • a computer – is an electronic device with complex circuitry – is a programmable device 7/30/19 8 Autumn 2019 CS101@CSE IIT Bombay

  7. a computer can do many things Help book and manage tickets Store and search documents Weather prediction Help design physical systems: say water network

  8. all of us have already used a computer! – Calculator – ATM – Smartphone (is a computer) 7/30/19 10 Autumn 2019 CS101@CSE IIT Bombay

  9. how to do work with a computer? • tell it do work! • what work? and how to specify? what work => logic, calculations, sequence etc. how to specify => write a program using a programming language • this course: from users to programmers! 7/30/19 11 Autumn 2019 CS101@CSE IIT Bombay

  10. CS101 assessment/grading • Midterm exam: ~20% • 2 Quizzes: ~10% each • Final exam: ~30% • Lab sessions – Lab tests: ~20% weightage – Lab attendance: ~10% weightage • Mandatory to attend N-1 out of N labs • Every lab subsequently missed will cost 2% 7/30/19 12 Autumn 2019 CS101@CSE IIT Bombay

  11. CS101 schedule/logistics https://www.cse.iitb.ac.in/~cs101/ • 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) • Slides and videos on www.cse.iitb.ac.in/~cs101 and http://bodhitree2019.cse.iitb.ac.in 7/30/19 13 Autumn 2019 CS101@CSE IIT Bombay

  12. The TA tree Bodhitree/Web site CTA Lab scheduling STA STA STA JTAs JTAs JTAs Thu lab. Tue lab. Wed lab. batch batch batch Do not use personal email 7/30/19 Autumn 2019 CS101@CSE IIT Bombay 14

  13. additional help for CS101 • do not hesitate in contacting us if are facing problem due to English • आप अंग्ऱेजी क े कारण समस्रा का सामना कर रहे हैः तो हमसे संपक रॎ करने मेः संकोच न करेः • there will be one Teaching Assistant for every ~12 students – Help and support can provided in other languages 7/30/19 15 Autumn 2019 CS101@CSE IIT Bombay

  14. 7/30/19 16 Autumn 2019 CS101@CSE IIT Bombay

  15. let’s start programming! • what is a program? – logic/concept/idea/calculations … – sequence of instructions (that a computer can understand) that capture the logic • 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? – … 7/30/19 17 Autumn 2019 CS101@CSE IIT Bombay

  16. programs • program = a precise description of the calculations we want the computer to perform • by feeding different programs to a computer you can make it do different calculations • this course tells you how to construct (“write”) programs • special notation is to be used to write programs: “Programming Language”(C++ for this course) 7/30/19 18 Autumn 2019 CS101@CSE IIT Bombay

  17. goal for today • write some small programs using C++ programming language • the programs will draw pictures on the screen • we “drive” a “turtle” on the screen! • Turtle has a pen, so it draws as it moves • drawing pictures may seem be fun, but if you master it, you have mastered a lot of programming • will use simplecpp package developed by Prof. Abhiram Ranade, based on Logo 7/30/19 19 Autumn 2019 CS101@CSE IIT Bombay

  18. programming the turtle to draw instructions the turtle understands • forward (x): Move forward x pixels – E.g. forward(50) moves the turtle forward 50 pixels • right (x): turn right by x degrees • left(x): turn left by x degrees • penUp() – Will not draw while moving • penDown() – Will draw while moving 7/30/19 20 Autumn 2019 CS101@CSE IIT Bombay

  19. programming a turtle to draw a square • forward, right, left, penUp, penDown • With these instructions, make the turtle move in such a way that we will draw a square of length 200 • What facts do we need to know before we can program? • Note: By default, in the beginning, the turtle faces towards the east, and the pen is down 7/30/19 21 Autumn 2019 CS101@CSE IIT Bombay

  20. The square drawing program #include <simplecpp> main_program { turtleSim(); forward(200); right(90); forward(200); right (90); forward(200); right(90); forward(200); }

  21. The square drawing program Some magic abracadabra: ignore the program will use the #include <simplecpp> simplecpp package. Your commands within these braces {..}. main_program { turtleSim(); Start the turtle simulator (open a window) forward(200); right(90); Move forward 200 units forward(200); right (90); forward(200); right(90); Turn right 90 degrees forward(200); } Program exits

  22. General Ideas #include<simplecpp> Commands or statements main_program{ terminated by semicolon ";" 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

  23. General Ideas (contd) #include<simplecpp> main_program{ Commands are turtleSim(); generally executed forward(200); from top to bottom, left right(90); to right. forward(200); right(90); forward(200); right(90); forward(200); wait(10); }

  24. how to draw an octagon? 7/30/19 26 Autumn 2019 CS101@CSE IIT Bombay

  25. how to draw an octagon? #include <simplecpp> main_program{ turtleSim(); forward(100); right(45); • commands seem forward(100); right(45); quite repetitive? forward(100); right(45); forward(100); right(45); • there is a better way! forward(100); right(45); forward(100); right(45); forward(100); right(45); forward(100); right(45); wait(10); } 7/30/19 27 Autumn 2019 CS101@CSE IIT Bombay

  26. A Better Way repeat (n) { #include <simplecpp> some commands main_program{ } turtleSim(); repeat(8){ The instructions within {...} are forward(100); repeated n times right(45); Each round of execution is } called an iteration }

  27. How to Draw a Polygon? #include <simplecpp> main_program{ turtleSim(); repeat(8){ forward(100); right(45); } } 7/30/19 Autumn 2019 CS101@CSE IIT 29 Bombay

  28. How to Draw a Polygon? #include <simplecpp> #include <simplecpp> main_program{ main_program{ turtleSim(); turtleSim(); repeat(8){ repeat( num_sides ){ forward(10); forward(10); right(45); right( 360.0/num_sides ); } } } } 7/30/19 30 Autumn 2019 CS101@CSE IIT Bombay

  29. How to Draw a Polygon? #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 31 Autumn 2019 CS101@CSE IIT Bombay

  30. Explanation #include <simplecpp> main_program{ turtleSim(); Print the sentence within the quotes on the screen cout è “Console out” (display) int num_sides; cout << “ No. of sides? ” ; cin >> num_sides; Read the number that the user types and store it into the space in memory named num_sides repeat(num_sides) { cin ç “Console in” (keyboard) forward(200); right(360.0/num_sides); } Use the integer stored in the space in memory which is named } num_sides

Recommend


More recommend