37
Welcome to Solving Problems with Computers ICS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer Science, UCSB Image from agorolabs on slideshare.com

Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

Welcometo“SolvingProblemswithComputersI”

CS16:SolvingProblemswithComputersILecture#1

ZiadMatni

Dept.ofComputerScience,UCSB

Imagefromagorolabsonslideshare.com

Page 2: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

AWordAboutRegistrationforCS16

FORTHOSEOFYOUNOTYETREGISTERED:•  ThisclassiscurrentlyFULLandthewaitlistisCLOSED

4/3/18 Matni,CS16,Sp18 2

Page 3: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

YourInstructorYourinstructor:ZiadMatni (zee-ahdmat-knee)Email:[email protected]

Myofficehours:Mondays11:00AM–12:00PM,atSSMS4409

(orbyappointment)4/3/18 Matni,CS16,Sp18 3

Page 4: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

YourTAs

LABTAsShiyuJi

MuqsitNawazXiyouZhou

GRADER

AshwiniPatil

AlllabswilltakeplaceinPHELPS3525AllTAofficehourswilltakeplacein“OpenLab”TimeinPHELPS3525

4/3/18 Matni,CS16,Sp18 4

Page 5: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

4/3/18 Matni,CS16,Sp18 5

YOURLABSAREHERE

YOURLECTURESAREHERE

PROF’SOFFICEISHERE

Page 6: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

You!

Withashowofhands,tellme…howmanyofyou…A.  AreFreshmen?Sophomores?Juniors?Seniors?B.  AreCSmajors?Other?C.  Haveprogrammedbefore?Whatlanguage?D.  Haveprogrammedbefore“justforfun”?E.  Haveprogrammedbefore“forworkorschool”?F.  HaveusedaLinuxorUNIXsystembefore?

4/3/18 Matni,CS16,Sp18 6

Page 7: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

ThisClass

•  Anintermediate(notabeginner’s)classincomputerscience–  YouWILLneedtohavetakenabeginner’sclasssomewhere

•  Coversthebasicbuildingblocksforsolvingproblemsusingcomputers,ingeneral,andusingC++programmingspecifically

•  Enablesyoutogoontotakeotherexcitingclassesinprogramming!!!!!OMG!!!

4/3/18 Matni,CS16,Sp18 7

Page 8: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

WhyAreWeUsingC++inthisCourse?•  C++isoneofthemostwidelyusedandin-demandcomputerprogramminglanguages–  ForalistofcommercialapplicationswritteninC++,seehttp://www.stroustrup.com/applications.html

•  IfyoucanlearnC++,youcanmoreeasilylearn(oreventeachyourself)otherpopularP.L.s–  LikePython,Java,PHP,Ruby,etc…

•  Itlooksgreatonyourresume!–  Actually,it’samust-haveonany“decent”CSmajor’sresume…

4/3/18 Matni,CS16,Sp18 8

Page 9: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

HowIsThisClassTaught?•  Everyclasshasalecturebasedonthereadings:

YOUMUSTDOTHEREADINGSBEFORECLASS!!!•  YouwillbeinalabonMondays:

YOUMUSTREADYOURLABASSIGNMENTBEFOREYOUGOTOLAB!!!•  Youhavetodoalotofhomeworkandlabassignments

4/3/18 Matni,CS16,Sp18 9

BECAUSEPRACTICEMAKESPERFECT!!!(andalso,it’sactuallyfun)

Page 10: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

There’sactual“work”todo…

•  15-16(short)Homeworks 1xor2xaweek,allsolo•  8-9LabAssignments 1xaweek,somesolo/somepaired•  2MidtermExams•  1FinalExam

…andapartridgeinapeartree…

Whysomuchwork??BecauseProgrammingisaSkill…

4/3/18 Matni,CS16,Sp18 10

ALOTOF

Page 11: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

OnlineResources

ClassMAINwebpage–ALLTHEINFO!ALLTHETIME!https://ucsb-cs16-s18-matni.github.ioPiazzadiscussions/Q&AANDIMPORTANTANNOUNCEMENTS!:https://piazza.com/ucsb/spring2018/cs16GauchoSpace–ONLYFORHOMEWORKASSIGNMENTS!https://gauchospace.ucsb.edu/courses/course/view.php?id=240384/3/18 Matni,CS16,Sp18 11

Page 12: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

IfYouHaveQuestions……Ask!ButFirst,Check……

4/3/18 Matni,CS16,Sp18 12

Page 13: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

IfYouHaveQuestions……Ask!ButFirst,Check……

4/3/18 Matni,CS16,Sp18 13

Page 14: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

So…let’stakealookatthatsyllabus…

4/3/18 Matni,CS16,Sp18 14

Fullelectronicversionfoundat:http://cs.ucsb.edu/~zmatni/syllabi/CS16S18_syllabus.pdf

PLEASEREADIT!!!!

Requiredtextbook:ProblemSolvingwithC++(10thEdition)byWalterSavitch(9thed.isok,butreferencesmaybedifferent)Lectures:Usesthereadings,butalsoaddsitowncomponents.Allassignmentsarebasedonwhatissaidinlecture.Slidesareplacedonwebsiteafterwards.Homework:1-2xaweek.Announcedonthewebsite,doneonGauchoSpace!Latepolicy:Afterduedate,youget20%offfor“late”(<24hrs)orZEROifafter24hrs.

Page 15: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

So…let’stakealookatthatsyllabus…

4/3/18 Matni,CS16,Sp18 15

Labs:Onceaweek.Descriptionsheetisplacedonwebsiteonweekend.LabisonWednesday.YOUMUSTUSEsubmit.csTOTURNINALLLABS.PLEASEFOLLOWINSTRUCTIONSONSHEET!MustbeturnedinbeforeMondayATNOON.Latepolicy:Afterduedate,youget20%offfor“late”(<24hrs)orZEROifafter24hrs.Mostlabsaresolo-work,butsomemustbedoneinpairs(i.e.groupsof2ppl).Exams:2Midterms+1Final(cumulative).Nore-dos,noearlytakes,nolatetakes(exceptforextremecases),nomake-ups.LaptopPolicy:Canonlyuseittotakenotes,doclass-relatedcodingwork(nosocialmedia!)CellPhonePolicy:Putthatthingbackwhereitcamefromorsohelpme…

Fullelectronicversionfoundat:http://cs.ucsb.edu/~zmatni/syllabi/CS16S18_syllabus.pdf

PLEASEREADIT!!!!

Page 16: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

SwitchingAboutInTheLabs…

…isfrowneduponL•  Pleasesticktothelabtimethatyouhaveperyourregistration

–  Thelabsareprettyfullandatcapacity

IFYOUWANTTOSWITCHLABSECTIONS,YOUMUST:1.  Findapersonintheotherlabtoswitchwithyou

2.  GettheOKfromBOTHT.A.sThisisbecausethelabshavelimitedspace

4/3/18 Matni,CS16,Sp18 16

Page 17: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

ShouldIBuy/DownloadaC++ProgrammingEnvironment/Suite??

•  ThereareafewGUI-basedIDEsoutthereforC++– YouareNOTREQUIREDtogetthemforthisclass!!!!!(so,no)

•  Regardless,youAREREQUIREDtobecomeproficientonourUNIX/LinuxCSILmachines’C++compilerandenvironment– “g++”and“makefile”,etc…

•  Realprogrammersusecommand-lines…!4/3/18 Matni,CS16,Sp18 17

Page 18: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

WhatYOUhavetodobeforeTHURSDAY’SLECTURE?

YOUHAVEALABonWEDNESDAY!!!That’sTOMORROW!!!!!!!!!!!!!!!!!!!•  LogintoPiazzaandhavealookaround

•  Gototheclassmainwebsiteandhavealookaround–  Goto:https://ucsb-cs16-s18-matni.github.io/

•  Readthelabassignment(lab01)beforeyougointoyourlab: BEPREPARED

4/3/18 Matni,CS16,Sp18 18

Page 19: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

AnythingElse???

YES!YOUHAVEANOTHERLECTUREONTHURSDAY!!!•  Dotherequiredreading!!!(Chapter1andstartChapter2)•  WAAAYbeforeyougotoclass,DOHOMEWORK#1

1.  Gototheclass’GauchoSpace2.  FindHomework#1module3.  Doit4.  Submitit5.  Profit?

4/3/18 Matni,CS16,Sp18 19

Page 20: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

ARefresheronComputers

4/3/18 Matni,CS16,Sp18 20

Page 21: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

ComputerSystems

•  Hardware– Thephysical

•  CPUandMemoryICs•  Printedcircuitboards•  Plastichousing,cables,etc…

•  Software– Theinstructionsandthedata

•  Programsandapplications•  Operatingsystems

4/3/18 Matni,CS16,Sp18 21

Page 22: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

Input

Secondary Data Storage

Keyboard (STANDARD) Mouse

Microphone Scanner

--or-- From a Program

Display screen (STANDARD) Speakers

Printer --or--

To a Program

AMapofComputerComponents(ModernComputerArchitecture)

CPU=CentralProcessingUnitRAM=Random-AccessMemoryROM=Read-OnlyMemoryHDD=HardDiskDriveSSD=SolidStateDriveOS=OperatingSystem

HDD and SSD CD-ROM Mini Flash Drive Tape Drive

CPU

Memory for instructions, etc…

RAM and ROM

Processing for calculations,

etc…

a.k.a.vonNeumannArchitecture

4/3/18 Matni,CS16,Sp18 22

1 2

3

Output 4

5

Page 23: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

5MainComponentstoComputers

1.  Processor2.  Mainmemory

–  Usuallyinsidethecomputer,volatile

3.  Inputs4.  Outputs5.  Secondarymemory

– Morepermanent(non-volatile)memoryformassstorageofdata

4/3/18 Matni,CS16,Sp18 23

Page 24: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

ComputerMemory

•  Usuallyorganizedintwoparts:–  Address

•  WherecanIfindmydata?–  Data(payload)

•  Whatismydata?

•  Thesmallestrepresentationofthedata–  Abinarybit(“0”sand“1”s)–  Acommoncollectionofbitsisabyte(8bits=1byte)– Whatinformationcanonestorein1byte?

Anumber?Aletter?Aprogram?Abook?Apicture?Amovie?

4/3/18 Matni,CS16,Sp18 24

ScalesofaByte…1B (byte)1kB (kilobyte)1MB (megabyte)1GB (gigabyte)1TB (terabyte)???

Page 25: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

WhatistheMostBasicFormofComputerLanguage?

•  Binarya.k.aBase-2

•  ExpressingdataANDinstructionsineither“1”or“0”– So,

“010101010100001101010011010000100010000100100001”

couldmeananinstructionto“calculate2+3”Oritcouldmeananumber(856,783,663,333)Oritcouldmeanastringof6characters(“UCSB!!”)

4/3/18 Matni,CS16,Sp18 25

Page 26: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

ComputerSoftware

•  Allthedata•  Alltheprograms•  Alltheapplications•  Theoperatingsystem(s)

•  Whatisfirmware?

4/3/18 Matni,CS16,Sp18 26

Page 27: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

TheOperatingSystem

•  Isitaprogram?–  Inageneralsense,yes!(ormoreprecisely,abunchofprogramsactinginconcert)

•  Whatdoesitdo?–  Allocatesthecomputer’sresourceslikememory–  AllowsustocommunicatewiththecomputerviaI/O–  Respondstouserrequeststorunotherprograms

4/3/18 Matni,CS16,Sp18 27

Page 28: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

Algorithmvs.Program

Completethis:“ComputerScienceisaboutstudyinghowto

use___________tosolveproblems”

•  Algorithms–  Sequencesofpreciseinstructionsthatleadstoasolution

•  Programs–  Algorithmsexpressedinalanguagethecomputercanunderstand

4/3/18 Matni,CS16,Sp18 28

Page 29: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

High-LevelComputerLanguages

•  Acomputerlanguagethatcloselymimics“naturallanguage”–  Asopposedtojustbeing0sand1s(that’s“machinelanguage”)

•  High-levellanguagesprovidehighabstractiontotheCPUInstructions–  Yourprogramsverymuchlooklikealgorithms

•  Aprogramthat“translates”aHighLevelLanguageintoLowLevelLanguage(likemachinelanguage)iscalledacompiler–  Whyarecompilersnecessary???–  BecauseCPUsONLYunderstandtheirinstructionsinMachineLanguage

4/3/18 Matni,CS16,Sp18 29

Page 30: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

Compilers

•  Language-specific–  CompilerforPythonwillnotworkforC++,etc…

•  Linux/UNIXOShavedifferentbuilt-incompilers–  e.g.g++forC++,clangforC,etc…

•  Sourcecode–  Theoriginalprograminahighlevellanguage(textfile)

•  Objectcode–  Thetranslatedversioninmachinelanguage(binaryfile)

4/3/18 Matni,CS16,Sp18 30

Page 31: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

IntroductiontotheC++Language

Whenwasitinvented? Inthe1980s…

Wasitbasedonanythingelse? TheCLanguage

Isitstillpopular? Yes!Inthetop-3ofmostusedtodaywithPythonandJava

4/3/18 Matni,CS16,Sp18 31

Page 32: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

ASampleC++Program

AcommonandsimpleC++programbeginsthisway:#include<iostream>usingnamespacestd;intmain() //Thisisacomment(optional){

Andendsthiswayreturn0;}

4/3/18 Matni,CS16,Sp18 32

Page 33: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

4/3/18 Matni,CS16,Sp18 33

Page 34: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

4/3/18 Matni,CS16,Sp18 34

1-4: Programstart5: Variabledeclaration6-20: Statements21-22: Programend

cout<<“somestringoranother”; //outputstreamstatement

cin>>some_variable; //inputstreamstatement

coutandcinareobjectsdefinedinthelibraryiostream

Notetheuseoftabbedspaces

Page 35: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

4/3/18 Matni,CS16,Sp18 35

1-4: Programstart5: Variabledeclaration6-20: Statements21-22: Programend

cout<<“somestringoranother”; //outputstreamstatement

cin>>some_variable; //inputstreamstatement

coutandcinareobjectsdefinedinthelibraryiostream

Notetheuseoftabbedspaces

Page 36: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

YOURTO-DOs

q  SignuponPiazzaq  Gototheclasswebsiteq  GototheclassGauchoSpaceq  ReadLab1TODAYanddoitTOMORROW(Wed.)

q  It’sduetobeturnedinbyMondayatNOON!q  DoHW1andsubmititBEFOREthestartofThursdaylecture

q  Solveworldhungerq  Reverseglobalwarming

4/3/18 Matni,CS16,Sp18 36

Page 37: Welcome to “Solving Problems with Computers I” · Welcome to “Solving Problems with Computers I” CS 16: Solving Problems with Computers I Lecture #1 Ziad Matni Dept. of Computer

4/3/18 Matni,CS16,Sp18 37