welcome to “solving problems with computers i” · welcome to “solving problems with computers...

Post on 14-Jun-2020

3 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Welcometo“SolvingProblemswithComputersI”

CS16:SolvingProblemswithComputersILecture#1

ZiadMatni

Dept.ofComputerScience,UCSB

Imagefromagorolabsonslideshare.com

AWordAboutRegistrationforCS16

FORTHOSEOFYOUNOTYETREGISTERED:•  ThisclassiscurrentlyFULLandthewaitlistisCLOSED

4/3/18 Matni,CS16,Sp18 2

YourInstructorYourinstructor:ZiadMatni (zee-ahdmat-knee)Email:zmatni@cs.ucsb.edu

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

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

YourTAs

LABTAsShiyuJi

MuqsitNawazXiyouZhou

GRADER

AshwiniPatil

AlllabswilltakeplaceinPHELPS3525AllTAofficehourswilltakeplacein“OpenLab”TimeinPHELPS3525

4/3/18 Matni,CS16,Sp18 4

4/3/18 Matni,CS16,Sp18 5

YOURLABSAREHERE

YOURLECTURESAREHERE

PROF’SOFFICEISHERE

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

ThisClass

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

•  Coversthebasicbuildingblocksforsolvingproblemsusingcomputers,ingeneral,andusingC++programmingspecifically

•  Enablesyoutogoontotakeotherexcitingclassesinprogramming!!!!!OMG!!!

4/3/18 Matni,CS16,Sp18 7

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

HowIsThisClassTaught?•  Everyclasshasalecturebasedonthereadings:

YOUMUSTDOTHEREADINGSBEFORECLASS!!!•  YouwillbeinalabonMondays:

YOUMUSTREADYOURLABASSIGNMENTBEFOREYOUGOTOLAB!!!•  Youhavetodoalotofhomeworkandlabassignments

4/3/18 Matni,CS16,Sp18 9

BECAUSEPRACTICEMAKESPERFECT!!!(andalso,it’sactuallyfun)

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

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

IfYouHaveQuestions……Ask!ButFirst,Check……

4/3/18 Matni,CS16,Sp18 12

IfYouHaveQuestions……Ask!ButFirst,Check……

4/3/18 Matni,CS16,Sp18 13

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.

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!!!!

SwitchingAboutInTheLabs…

…isfrowneduponL•  Pleasesticktothelabtimethatyouhaveperyourregistration

–  Thelabsareprettyfullandatcapacity

IFYOUWANTTOSWITCHLABSECTIONS,YOUMUST:1.  Findapersonintheotherlabtoswitchwithyou

2.  GettheOKfromBOTHT.A.sThisisbecausethelabshavelimitedspace

4/3/18 Matni,CS16,Sp18 16

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

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

AnythingElse???

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

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

4/3/18 Matni,CS16,Sp18 19

ARefresheronComputers

4/3/18 Matni,CS16,Sp18 20

ComputerSystems

•  Hardware– Thephysical

•  CPUandMemoryICs•  Printedcircuitboards•  Plastichousing,cables,etc…

•  Software– Theinstructionsandthedata

•  Programsandapplications•  Operatingsystems

4/3/18 Matni,CS16,Sp18 21

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

5MainComponentstoComputers

1.  Processor2.  Mainmemory

–  Usuallyinsidethecomputer,volatile

3.  Inputs4.  Outputs5.  Secondarymemory

– Morepermanent(non-volatile)memoryformassstorageofdata

4/3/18 Matni,CS16,Sp18 23

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)???

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

ComputerSoftware

•  Allthedata•  Alltheprograms•  Alltheapplications•  Theoperatingsystem(s)

•  Whatisfirmware?

4/3/18 Matni,CS16,Sp18 26

TheOperatingSystem

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

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

4/3/18 Matni,CS16,Sp18 27

Algorithmvs.Program

Completethis:“ComputerScienceisaboutstudyinghowto

use___________tosolveproblems”

•  Algorithms–  Sequencesofpreciseinstructionsthatleadstoasolution

•  Programs–  Algorithmsexpressedinalanguagethecomputercanunderstand

4/3/18 Matni,CS16,Sp18 28

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

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

IntroductiontotheC++Language

Whenwasitinvented? Inthe1980s…

Wasitbasedonanythingelse? TheCLanguage

Isitstillpopular? Yes!Inthetop-3ofmostusedtodaywithPythonandJava

4/3/18 Matni,CS16,Sp18 31

ASampleC++Program

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

Andendsthiswayreturn0;}

4/3/18 Matni,CS16,Sp18 32

4/3/18 Matni,CS16,Sp18 33

4/3/18 Matni,CS16,Sp18 34

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

cout<<“somestringoranother”; //outputstreamstatement

cin>>some_variable; //inputstreamstatement

coutandcinareobjectsdefinedinthelibraryiostream

Notetheuseoftabbedspaces

4/3/18 Matni,CS16,Sp18 35

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

cout<<“somestringoranother”; //outputstreamstatement

cin>>some_variable; //inputstreamstatement

coutandcinareobjectsdefinedinthelibraryiostream

Notetheuseoftabbedspaces

YOURTO-DOs

q  SignuponPiazzaq  Gototheclasswebsiteq  GototheclassGauchoSpaceq  ReadLab1TODAYanddoitTOMORROW(Wed.)

q  It’sduetobeturnedinbyMondayatNOON!q  DoHW1andsubmititBEFOREthestartofThursdaylecture

q  Solveworldhungerq  Reverseglobalwarming

4/3/18 Matni,CS16,Sp18 36

4/3/18 Matni,CS16,Sp18 37

top related