einrichtungsideen für kleines bad

einrichtungsideen für kleines bad

>> [music playing] >> david malan: all right this is cs50and this is the end of week one. so i'd like to introduce my formeradvisee, andel duff, who not only makes iphone 5 stands, as well as thislectern, he also makes cars. ansel duff: how's it going, everybody? i just want to tell you a littlebit about formula sae, of which i am the captain. it's an mit team. i just want to tell youguys a little bit about it

and hopefully generate some interest. >> so let me just run through acouple things about our team. so we're completelystudent run, wherein all of the members design, simulate,test, and manufacturer a subsystem of the car. we have our own machine shopand garages, and n52-- or sorry, n51-- which is the same buildingas the mit science museum. and we are the peoplethat drive the car. there's a national competitionin the beginning of the summer,

and then there are smaller shootoutcompetitions throughout the year. and then we do driver trainingdays to get new members acquainted. >> our build days are onsaturdays from 11 am to 8 pm. lunch and dinner are taking careof, from bertucci's and beantown respectively. we have a weekly meeting andseminar, which is for course credit. which is new as of this semester, andit will also be for next semester, so you can cross-reg for that. and then we have designing, shop,and cad days during the week,

whereas members will independentlycad parts, order stock et cetera. >> so for electricalengineering at the team we have our tractive,high voltage system, which runs at a nominal300 volts, which includes motors, motor controllers,and battery packs. then we have a lowvoltage system, which runs at 12 volts, which includescontrols, can nodes, the brain box, and the dashboard. as far cs goes, we dohave website maintenance

that we need done for events, membershipchanges, new pictures, and pr material. and then we have code that controls thecar for our traction control, launch control, dash control, torque vectoring,and regenerative braking systems, which run typically in matlab,simulink, and labview. >> tell you a little bit about the car. so it's about 500 pounds. it's rules limited to 85 kilowatts. it has 2 emrax 207 motors in theback, one for each rear wheel. it has custom-built battery packsfrom prismatic a123 pouch cells,

totaling 300 volts and5.6 kilowatt hours. and it's direct drive witha 2.64 to 1 drive ratio. here are some pictures wetook of it at competition. here's the back, nose cone,and here are the motors, those big black disksunderneath the et mens manus. here's a slide that i pulledout of our competition scheme. and this is just comparing our car to acouple of commercially available cars, like the ktm xbow, arielatom, and caterha m 7-280. if you're familiar with price, powerpull weight, dollars per horsepower,

dollars per torque, and our carblows them all out of the water. if you have any questions,jot down this email address. shoot us an email at fsae@mit.edu. >> we're happy to talk aboutanything you'd like. harvard students are kindof the minority on the team. if you have any questions aboutthat please do shoot us an email, happy to talk, and i'm goingto head back over to david. thanks. i appreciate it, guys.

[applause] >> david malan: ansel spent the summerworking with us here on campus in cs50 this summer. and in addition to working onthings like the binary bulbs, he actually really opened oureyes-- and mine in particular-- to what really the intersection ofnot of hardware and software can be. in fact a lot of the things he justtoured you through are ultimately created first in software,and then ultimately fabricated in the real world in hardware.

so if you're interested inexploring that intersection, perhaps take up that group. >> now meanwhile, those of youwho are fans of technology, and apple products inparticular know that there were a couple ofannouncements yesterday. but we thought we'd showyou one that came out a few days prior thatyou might not have seen. >> jorgen eghammer: you know,once in awhile something comes along thatchanges the way we live.

a device so simple and intuitiveusing it feels almost familiar. introducing 2015 ikea catalogue. it's not a digital book oran e-book, it's a book-book. >> the first thing to note is nocables, not even a power cable. the 2015 ikea cataloguecomes fully charged, and the battery life is eternal. the interface is 7.5 by 8 inches,but can expand to 15 by 8 inches. the navigation is based on tactile touchtechnology that you can actually feel. >> content comes pre-installedvia 328 high-definition pages

of inspiring home furnishing ideas. to start browsing,simply touch and drag. right to left to move forward,left to right to move backwards. >> notice something else? that's right. no lag. each crystal clear pageloads instantaneously, no matter how fast you scroll. if you want to get a quick overview,just hold it in the palm of your hand,

and using just your thumb,speed browse the content. >> if you find something you want to savefor later, you can simply bookmark it. and even if you close the application,you can easily find the bookmark again. amazing. >> [laughter] so that brings us tothe end of week one. a few announcements now. so sectioning is now in progress. go to this url here sometimebetween now and friday at noon

to actually specify whether you areamong those less comfortable, more comfortable, or somewhere in between. >> this is typically one of thosethings that you just kind of know. and in fact those of you who are lesscomfortable probably know as much, those of you who are morecomfortable know as much, and again if you aren't quite sure whichof those buckets you fall into you're probably somewhere in between. but rest assured you can swapafter a couple of weeks if need be. >> meanwhile, for the coming weekwe don't start sections per se,

but super sections, whichare open to all students. this coming sunday at a location tobe announced on the course website we will have one forthose less comfortable, as well as one forthose more comfortable. and those somewhere in betweencan choose which of those two, or both if you'd like, to sit-in on. and the focus of thosewill be ultimately on c, which we'll continue ourconversation of today. >> problem set 0 meanwhile ishopefully in your hands.

officially due tomorrow,thursday, at noon. unless you cash in oneof your 5 late days, which would bring ituntil friday at noon. problem set 1 meanwhile will beposted on the course's website. and this will be our firstforay as a class into c. and that problem set spec will walk youthrough a lot of the mechanics of what we started talking about on monday,and we'll continue talking about today. c, linux, the cs50appliance, all of that will await you in the specification.

>> office hours meanwhile are in progress,in the undergraduate dining hall. head to this url here to see theschedule for tonight and tomorrow, if you would like to partake. questions meanwhile, so that youhave opportunities to ask questions asynchronously, 24/7, realize you'renot limited to sections and office hours, but rather this toolhere, cs50 discuss at that url will be the course's onlinebulletin board software, via which you can ask questions ofclassmates and also staff. so keep in mind that resource as well.

meanwhile a traditionstarts this friday. as you may have glimpsed fromlast wednesday's teaser video, we have a tradition mostevery friday during term of taking some 50 students andstaff to a local restaurant called fire and ice, at which we'retypically joined by some alumni or friends from industryto generally aspire to make a large class feel smaller. so it's a completely casual lunch. a bunch of us, the staffespecially, will play musical chairs

and chat with students about50, life outside of 50, life in the future, the real world,i'm talking about job opportunities with friends in industry. >> so if you would like to join usthis friday, head to this url here. space is limited, but we'll do thisrecurringly throughout the term. head there to cs50.harvard.edu/rsvp. and if you don't get inthis time, not to worry. we will do it again inthe coming weeks as well. >> so this is the picturewe painted last week,

and you've probably beendabbling in thus far. but let's try to connect this nowto what we're going to do today and onward. could i have one volunteer? all right, or several. how about here on theend, in the blue shirt. come on up, what's your name? alana: alana. david malan: alana.

so alana, for just amoment-- nice to meet you-- is going to play the roleof this function here. the purple block we'vecalled thus far a function. so what i'm going to goahead here and offer alana is a little name tag, to makeclear what role you're playing. >> so you shall be the say block. if you want to go ahead and put that on. and we're going tokeep this super simple. if the goal at hand is simplynow to implement with alana,

this so-called say block,here's how it's going to work. i have-- let's call itan argument or parameter, it's really just a blank sheet of paper. and it's white to kind of be reminiscentof the white box into which you can write words. >> meanwhile i'm going to go here. i'm going to go ahead andwrite h-e-l-l-o comma world. and now i, as say the programmer, don'tactually know how to say something. i can come up with the words,but i don't necessarily

know how to express myselfverbally or on the screen. and so what i'm goingto do is take this piece of functionality, whose input--or argument, as we'll call it, i've written on this piece of paper--and i'm going to outsource it. >> and indeed that's the role thatfunctions in a programming language can play. something like the sayblock can be outsourced to someone who really knowswhat she or he is talking about. so if you'll step overhere for just a moment,

i am going to pass this input toalana, and ask that you say this input. >> alana: hello, world. david malan: that's it. so that there is a function. now we can take it a little more,we can take a step forward here. because that was clearly underwhelming. so let's now convert this tosomething a little more sophisticated. >> so this of course is our c version. so now if you want to take thatone off, that name tag off,

and let's have you put on a new name. but fundamentally you'replaying the same role, it just so happens tobe called printf now. >> the story is, of course,going to be-- probably just as underwhelming-- isgoing to be the following. you are now the function printf. i am the caller, or theprogrammer, who wants to stand on the shoulders ofpeople in the past like you, who've already figured out howto actually write something down.

and so this time,rather than say it let's actually use our screen over here. so if you'd like to stepover here, i'm going to pass again this asinput to my printf friend. if you could go ahead andprint that on the screen, simply by drawing with yourfinger on the black screen. excellent. all right, so lots of suspense forhow that was going to play out. >> so now let's take things up onefinal notch, if we could, as follows.

so this is a c programas we said last time. and this just does what you did, itprints out to the screen, hello, world. even though there's clearly a lotof distracting stuff up there. but let's take things up a notch andintroduce this version, which recall was the third version thatwe ended up with last time. >> and now there's clearlytwo uses of printf. there's 2 calls to alanain this case for printf, but there's also a callto another function. what's that function clearly?

getstring. >> can we get one more volunteer? ok, come on up. what's your name? >> javier: javier. >> david malan: javier, come on up. so javier's role is onthis piece of paper. which i'm going to call generically s. now this is a variable, it'sof type string, as implied

by that second line in the middle there. and i'd like you to go get me a string. specifically head down to the orchestrasection and get me the name of someone, and come back with a variablecontaining that value. it can be anyone you want. >> here we go. all right, javier iswriting down the name. all right. we can all probably guess howthis is going to play out.

we're perhaps belaboringthe point of what a function is doing, butnonetheless thank you very much. >> so javier has returned this stringhere, which, can't quite see, jonathan is the stringthat we've gotten. so now what i'm actually goingto provide to alana though is something a little different. because in this version of theprogram, first there's state your name. so the very first argumenti need to provide alana with is going to beliterally state your name.

all right, so simple as thati would hand this to you. and as i write up thenext argument, if you want to go ahead and write thison the board, let's go ahead and do the final example here to makeclear what's ultimately got to happen. so state your name,write it toward the top if you don't mind, just so thatwe have room for one second line. because the last thing i'm goingto now provide you with is not one, but two pieces of paper. >> all right.

h-e-l-l-o comma and then a blank line. so what i'm about to hand alana nowis something a little different. not only is she getting this,where fill in the blank represents that percent-- what was theplaceholder we've been using? yeah, so percent s. meanwhile i'm going to passher in a second argument, which is precisely what javierretrieved from jonathan. >> so let me give you these two. if you'd like to, go aheadand print that effect.

what's ultimately happeningnow is, alana again is playing the role of printf. javier was playingthe role of getstring. so that will be your souvenir. and ultimately what's happening, despitethis hello-- yep go ahead and comma. alana: did i receive this yet or no? david malan: yep, youreceived them both at once. so the idea is that youcan now flip the page to handle the secondof those two inputs.

so this is only to hammer home thepoint that whereas alana executed this green line here, and thenjavier did this one for us and return to me somethingwe'll call s, but it was really just that piece of paper of his own. and now alana has done this third line. >> and even though all of this looksso incredibly cryptic perhaps at first glance, it reallyis as simple as that. passing inputs around,getting outputs, either being physically handed back something,or seeing a side effect like this.

something visuallywritten on the screen. so let's go ahead andthank alana and javier, who was down here, forjoining us up here. >> [applause] >> so now let's take for granted just howstraightforward all of that might be. and let's proceed to actuallydo something in actual code. so up on the screen here is a screenshotof the so-called cs50 appliance. and if you had to at, as a2:00 pm on wednesday afternoon, explain to some friendwhat the cs50 appliance is,

how would you define it in a sentence? any one sentence? yeah? student: it's like a programthat makes everyone's computer run with the same system. david malan: good! it's a program that enables everyone'scomputer to run with the same system. it's sort of your owncopy of an operating system that happens tobe called ubuntu linux.

and it runs effectively inside ofa window on your own mac or pc, so that this way right out of the gatein week 1, everyone here in the class has access to the same tools,the same configuration, and there's no learning curve specificto a mac or a pc in particular. >> now we opened up, inside of the cs50appliance on monday, this program here. it happens to be called gedit. but that's really justa graphical editor. it's something like notepad or textedit on windows or mac os respectively. and i proposed that there were reallythree important parts to this screen.

the top side is where youwould write your code. and that's where we spent much of ourthree examples in monday's lecture. the bottom we called what,this black window, yeah? >> student: compiler? >> david malan: compiler weaccessed by way of that window. but more generally. yeah, it was just a terminal window. this is an age old term that justdescribes essentially a blinking prompt, that years ago used to be onone of those big crt style monitors.

but nowadays it's sortof virtual in software. and the terminal windowslet's us type commands. it sort of the simplified versionof the user interface or ui. it's not a graphicaluser interface or gui, it's a text-based interfaceor a command line interface. >> and indeed that's where ultimatelyi was able to write some code. once i had written some code though,recall that i used this command. and as it the namekind of suggests, this allows me to make aprogram called hello.

but what was it really doing? well make was taking myinput, my source code, and converting it to what, ultimately? >> object code. and object code is just a fancyway of saying zeros and ones. and then once i wantedto run that object code, once i wanted to pass as input thosezeros and ones into my computer's brain, the so-called cpuor central processing unit, i had to run the program.

but it wasn't quite a simple on mondayas just double clicking some icon. what instead did i have todo in order to run a program? >> what was that second command? i'm hearing a little slashes? yes, yeah? >> student: dot slash andthe program's name. david malan: exactly. dot slash and the program's name. now what did this mean?

well dot is just an arcane wayof saying current directory. whatever folder you are in isreferenced as, is represented as dot. the slash is just what you've seenin mac os and windows for years, it's a separator between a directoryor folder and the rest of some name. in windows it happens to gobackwards, in linux and mac os it happens to go forwards. but it's just the separator, so it'sjust an uninteresting syntactic detail. >> the juicy part of course isthe name of the program, hello. and that's what make created for us.

it outputted that file for us. but how did we get to that point? let's now ask thequestion, what was really going on here, at least withregard to some of this syntax? >> so in an sentence or so,how did we explain away this first line that'shighlighted in green? what was that first line doing,with respect to my program? >> student: [inaudible]. david malan: say it again?

student: including and downloadingpast functions [inaudible]. david malan: good. including, i won't saydownloading, but let's say including functions that peoplehave written in the past. and those functions are implementedsomewhere in my computer. someone wrote a fileyears ago, and that file is somewhere inside of the cs50appliance, or on my hard drive more generally. and so this line is essentially saying,go find that file, standard i/o dot

h, and copy and paste its contentsright here on the top of my file so that i don't have todo that manually myself. >> and among the juiciest pieces inside ofthat file we claimed was what function? what function did we say was declaredor mentioned in standard i/o dot h most likely? printf, right? we did not write printf onmonday, it just existed. much like alana just cameup on stage and she just existed and knew how to drawsomething on the screen,

so does printf exist for many years. and so this is how we access it. now if we move on here,main was analogous we said to the puzzle piececalled when green flag clicked in the world of scratch. it's just sort of thedefault name that humans decided would represent thedefault entry point to a program. the chunk of programming codethat gets executed first. >> meanwhile these curly braces arekind of like the curved shape

of a lot of those yellow scratch pieces. they kind of encapsulate a wholebunch of instructions together. so it just kind of binds togethersome related functionality. printf of course is a function thatprints the screen, as we just did. >> what about these parentheses? how would you define-- even if you'venever programmed before, but just based now on an increasinghopefully intuition, what are the parentheses doing for us here? or what are they surrounding?

>> student: they're saying whatyou're going to print with printf. >> david malan: yeah, they're saying whatyou're going to print with printf. or more generally, they aresurrounding the inputs to the function. so you can almost thinkof those parentheses as being like the metalclip on this clipboard. it's what's holding, it's what'sgoing to be used to provide arguments into the function, which inthis case is called printf. >> so in general almost anytime we call a function, we are going to see a pair parentheses.

maybe with something in it,like now, maybe nothing in it. but that's where you would putthe inputs or so-called arguments to a function. >> here's one such argument. i've highlighted everythingbetween the quotes, because it turns outin this language called c, when you want to represent astring-- that is a word or a phrase or even a paragraph-- you have tosurround it with double quotes. not single quotes, double quotes.

and that's exactly what i've done here. >> meanwhile there's a funkysymbol toward the end there. the backslash n. what did we say that represented? >> student: a new line. >> david malan: new line. right, you don'tgenerally hit enter when you want the programto spit out a new line. rather you tell it explicitlywith this admittedly arcane piece

of syntax, backslash n, thatyou want a new line to go there. finally the semicolon. we didn't really talktoo much about this, and by far this will be the bane of someof your existence for the first problem set, when you just failed to realizeyou've forgotten something as stupid as a semicolon. and generally putting itthere will fix that problem. but what's it doingfor us, would you say? >> david malan: sorry?

david malan: finishing a statement. it's sort of like the period atthe end of an english sentence, whereas in this languagec it's ending a statement. an instruction of programmingcode that you just want to say, i'm done with this. now notice that's the only one here. so you don't want to get ina habit of putting semicolons after every closed parenthesis. for instance there's nonenext to void, and we'll

come back in the futureto what void means. but in this case your printf is afunction, or a statement being used, and so we want to have thatterminus at the very end of it. >> and i'm intentionally picking on c. andfrankly a lot of languages like c, c++, java, javascript, and any number ofother languages have a lot of these sort of syntactic details. that certainly if you're new toprogramming can genuinely trip you up. and you will, mark mywords, some of you will have this experiencein office hours or late

at night working on some p-set, whereyour damn program just doesn't compile, it doesn't run, you haveno idea what's wrong, it seems completelylogically correct to you. and it's because you forgotsomething like hitting a semicolon at the end of some line. >> but these are the kinds of things you'regoing to immediately learn to see. and indeed these are the thingsthat the ca's and tf's have been sort of trained to seemuch more quickly than you. and so this is only to say, as youdive into problem set 1 especially,

don't get frustrated by this stuff. once you sort of acclimateto the world, you begin to see things that you might notsee at first glance this first week. >> so source code is something like that. we want to pass it intothe so-called compiler. and that compiler aswe said provides output known as object code, theso-called zeros and ones. but from there, what does that give us? well it gives us these patterns.

and again your computer,your intel inside, understands these patternsof zeros and ones. and sometimes the patternrepresents an actual decimal number as we saw last week, sometimesit represents a letter like we saw last week, sometimesit represents an instruction, like printing something to the screen. >> so printf for instance--but rather, let me rewind. we've been taking for grantedthat those zeros and ones are produced by this command make.

but make is not a compiler. make is not the thing in the middlethat's producing the zeros and ones. rather make is just a very convenientlynamed program whose purpose in life is essentially to figure outhow to compile your program. and we use it in thesefirst weeks because it just saves us a lot of trouble. >> but what make is reallydoing when you compile hello, is, as we said last time, it'slooking on your hard drive or in the current folder, forfile called what, apparently?

hello.c, right? that's just kind of a convention. it's arbitrary, butthat's the way things are. make, if you just specify the nameof a program that doesn't yet exist, it's going to look for the source codein a file, by default means hello.c. and if it finds it, great. it's going to convert that sourcecode into object code for you. >> but every time i've hit enterafter running make hello, do you recall seeing last time afairly long and cryptic sequence

of other white letters andcharacters on the screen? well that was the actual command, theactual compiler, that was running. so the actual compiler we'll use most ofthe semester is something called clang. some of you might have usedvisual studio before, or gcc, or any number of other compilers. we'll use clang. >> and clang allows us to actually convertthat source code to object code. what does this actuallymean in practice? well let me go into one ofmy folders from last time.

inside of the cs50 appliance. and let me go ahead and create thissame file, include standard i/o dot h. int main void. and we'll come back in the future asto what int means and what void means. but for now let's dohello world backslash n, just like we did on the board. >> let me save this file called hello.c. and now if i want to compile thisi could-- let me zoom in-- run make hello enter.

and this again wasthat very cryptic line. but now at least one wordprobably jumps out at you. clang is that line we saw before. now there's a lot of other stuff franklythat we'll wave our hands at for today. but there's a few subsets,a few characters in here that are of interest. but i'm going to go ahead and do this. i'm going to first runhello, just to prove that this is working as it was monday.

but now i'm going to delete the program. and much like we had theseshort names last time, the command for removingsomething is rm, remove, enter. you're going to get somefairly cryptic questions. hard to believe that you can makeeven this question hard to understand. but remove regular file hello justmeans do you want to delete hello. >> and i can go ahead and type y foryes, enter, and now it's gone. what this means now,if i clear my screen, is that instead ofdoing make hello-- you

know what, i'm getting good at this. i'm going to run the compiler myself. i don't need some program tofigure out what my file is called. i wrote hello.c, iknow what it's called, i'm clearly capable of typing that. so i'm going to go aheadand do clang hello.c enter. >> seems to work. and there's no additional output,because clang is the compiler. it's what's converting thesource code to zeros and ones.

so if i now do dotslash hello enter, hm. new error message today. so bash is just the name of theblinking prompt that we're using. that's a gross oversimplification,but for now that's all that is, it's the blinking prompt. and that's why it's yelling at us. >> no such file or directory isa little more straightforward. but surely i made that object code. but the catch is, thatif i type the command

to list the contents of thisdirectory, which is what? ls for list. there's a bunch of stuff in here,some of which came with the appliance, like my desktop folder, downloadsfolder, dropbox folder, and all that stuff. but what is interestingis hello.c, which i created a moment ago with gedit. and what's the weirdestlooking name in here, perhaps that we didn'tsee last time at all?

>> a.out, right? so back in the day, itwas just decided that when you compile a programfor the first time, and you don't specify the nameof a file, let's call it a. and a.out just means this wasthe output of the compiler. so it's a horrible name for a program. but by that logic, dot slash forcurrent directory, slash a.out, should mean there's in factmy hello world program. now a little warm up exercise, too.

if i want to rename thisfile, turns out that you move a file from one name to another. so mv a.out, and then ican call it hello enter. so this is a linux command. dos had this years ago,windows has a terminal window of some sort that lookslike this, linux and mac computers have this blinking prompt. even though most of us probablyrarely, if ever, use it. >> but what i've done is run aprogram, whose name is mv,

and i've provided it withtwo arguments, so to speak. two inputs. a.out is the original name. hello is the new name. so if i now do dot slashhello, enter, that exists. and if i do dot slash a.out,what do you expect i should see? >> bash, no such file or directory. because i just renamed it. so this takes a bit of getting used to.

but the problem set 1specification will truly hold your hand throughsome of this minutae. because this is a completeintellectual distraction from the more interestingideas at hand, which is actually creatingsomething out of code. but let's do one modificationnow to this program. >> recall that last time i did somethinglike this, printf state your name. and indeed we just did thison the big screen over there. and then i did string s getsgetstring open paren, close paren.

and paren just shorthandnotation for parenthesis. so does getstring take any arguments? no inputs no, but itneeds the parentheses, because that's what demarcatesthe calling of a function. >> so i'm going to go ahead and try torun the compiler on this program now. clang hello.c, because ididn't change its name for now. and i got a bunch of errors. let's zoom out here. if i scroll up again,like i said last time,

to the first, same errorthat i got last time. on line 6 of hello.c i had anundeclared identifier string, did i mean standard in? i didn't. because what mistake have i made in thisprogram, if you recall from last time? yeah, we need theso-called training wheels that we'll just use for a few weeks. but i need to specify that also,somewhere inside of the appliance, is a file that we wrotejust a few years ago.

inside of which are functionslike apparently getstring. so now if i go back down here,zoom in, and re-run clang hello.c. damn, another error. but we haven't seen this one before. >> this one's a little moreesoteric to figure out. but this is deliberately on the screen,because we wanted to tell this story. when you compile hello.c, just asthe picture from before suggested, you're only converting thatsource code to zeros and ones. now cs50 staff a few years ago wrotecs50.h, and a corresponding file,

cs50.c. and we, a few years ago,compiled those files into a file that happensto be called cs50.o. >> or it can be renamed afew different things. but that's a simple wayof thinking about it. so we compiled cs50'slibrary into zeros and ones. but nowhere have i specifiedthat i want to combine my zeroes and ones for my hello worldprogram with the zeros and ones that cs50 staff created a few yearsago into one complete program.

all i've specified by writingclang hello.c is compile hello.c. >> i've not told clang tolink in the zeros and ones that cs50 staff createdfor you some time ago. so it's an easy fix,dash l for link, cs50. and we'll again see thisbefore long again and again. but notice now there was no complaints. so now if i run dot slashhello, now it's working. although that's a bit misleadingsince i just recreated what file? a.out.

>> so let me rewind for just a moment. the program we just compiledhas the three lines of code. when i ran hello world, hello a momentago, i didn't see state your name. and that's because i ran theold version of the program. but if i do indeed run dot slash a.outenter, state your name, rob, hello, world. hm. that's kind of a bug. probably meant to say rob, right?

so what's the fix here in code. student: [inaudible]. so i just need to make that final tweakso that i'm passing in a placeholder, like a fill in the blank,like we did a moment ago. but percent s is nowthat fill in the blank. so lastly let's reveal one lastdetail so that there's no magic. i'm going to go aheadand get rid of hellow. i'm going to go aheadand get rid of a.out. so now i have no programs,just my source code.

and i'm going to run aslightly longer command, clang dash o hello hello.c dash lcs50. >> now this is starting to sort of goin one ear and out the other perhaps. but just tease apart what this is doing. clang is the compiler, dash lcs50deliberately at the very end does what in a sentence? links to the cs50 library. grabs the zeros andones that the staff made and crams them into my own program.

so the last question at hand is,what is dash o hello probably doing, even if you've neverseen this syntax before? >> outputting a program that'snot named the default a.out. rather it's named hello. so now there is no a.out. no such file or directory,because i explicitly said call this program hello, so thati can now type in a name like that and have it behave. >> now frankly, boy is thatuninteresting to have

to remember all of thatlittle minutia, right? so let's go ahead andget rid of hello again. and let's now return to a world inwhich it suffices to say make hello. but that's the magic thatmake is doing for you, that's the tedium thatit's doing for you. and as our programs andproblems get more complex, make will truly be your friend. because not too longfrom now we're going to have programs that are writtennot with one file, but several files,

and make will automate the process ofcompiling all of that for us together. >> so now print. printf is inside of this file, standardi/o dot h, that we've seen before, but there's more to printf than that. there's backslash n, but there's alsoa bunch of other escape sequences. and escape sequence is just afancy way of saying something that starts with a backslash,not a forward slash, a backslash, and does some special thing. and we won't dwell on most of these,but why is there backslash double quote,

do you think? why is there this weird sequence ofcharacters, backslash double quote, why might that be useful? david malan: exactly, right? think back to our hello world programthat we've seen quite a few times now, every time we've seen that hello worldprogram we've had double quotes inside of which is hello commaworld backslash n. but think to yourself,what if you actually wanted to print out a quotation mark?

your first instinct might be, i don'tknow why i might want to do-- here, we can be a little passiveaggressive, hello friend. we might want to do something like that. >> but why is this now problematic? ignoring the curly quotes aside thatkeynote made for us automatically. why is this problematic? >> exactly. because we have like 4 quotation marks. well the first one probablygoes with the second one,

and maybe the fourth onegoes with the third one, or, i mean i'm not even sure,nor is the computer going to be. computers again, compilersagain, are fairly dumb. they'll only do whatyou tell them to do. and if you're not unambiguous theyare probably going to throw an error. >> if you're not unambiguous as to how tomake a peanut butter and jelly sandwich strange things might arrive. it's the same idea. now suffice it to say there'ssome other escape sequences,

but we'll come to those before long. essentially these escapesequences represent something that you might not be abletoo easily at the keyboard, without confusing the computer. >> now meanwhile we haveplaceholders in printf. percent d, which can also be writtenin almost all cases as percent i, is a placeholder for what type of data? what type of value? a decimal number.

so actually we'll startusing percent i because it's a little simpler, like an integer. percent i. an integer that happens to be decimal. >> percent s we already said wasa placeholder for a string. which is just a word, a phrase,a paragraph, an essay, whatever. it's a sequence ofcharacters of some length. and we'll see before longsome of these others. but percent c is for a single character.

percent f is for afloating point number, like a real number that hasa decimal point in it, which is of course not an integer. and there's a wholebunch of others as well. >> meanwhile in c, andin a lot of languages, we have different data types. different types ofglass bowls if you will. the bowl i used last timewas for ping pong balls, but we can also store differentvalues like chars and strings

and integers in a container,like a variable, and c has these. char is the type of data,the type of variable, in which you can store a character. float is a type of variable inwhich you can store a real number. >> int is of course for an int. and rather ridiculouslynamed a long long is where you can store essentiallya really long number, with even more digits then atypical int might store. but we'll come back to that before long.

>> in cs50 dot h meanwhilethe other header file that we've seen a coupletimes in use, there's two other data types thatdon't exist in c typically. one is string, and we'll see ina few weeks what strings really are underneath the hood. and one is bool. and a bool is a variable thatcan only take on certain values. and just based on last week'sexplanation of scratch, and more recently c,what would you guess

are the two possible values forsome container that is of type bool? >> yes and no. one and zero. true or false. and indeed it's the last that tendsto be conventional in a programming language, saying somethinglike true or false. >> meanwhile the cs50 library comeswith a bunch of functionality that the staff wrote for you,besides just getting a string. we wrote in advance functions thatcan get an integer from the user,

get a single character,get a float, that is just a number with the decimal point. get a long long, a reallybig value from the user. so we've only seen this inaction in the form of getstring. but via these functionswill soon be able to write programs that get input from the user. >> meanwhile consider thisprogram, and consider how we might now start to addto it with new constructs. a quick whirlwind tourand then we'll look

at some writing someprograms manually ourselves. henceforth if we want toimplement a condition, it's not going to look like anice little pretty puzzle piece. it's going to look a little more arcane. but this is the canonicalstructure of a condition in c. >> the word if, twoparentheses, inside of which is going to be some kindof boolean expression. now the slash slashin the middle, this is at the moment sort of likepseudocode code placeholder.

but more properly, any line of codein c that starts with slash slash is a comment. >> it's like a sticky note that you mightput on an essay, printed on paper. it's a note to yourself. it has no functionalimpact on the program. it's sort of a reminder, it's your owndocumentation as to what's going on. so do this at the momentis sort of a placeholder for whatever's insideof those curly braces eventually is going to do something.

>> meanwhile you have two forks in theroad, an if else construct like this. you can if, elseif, else. now it's worth noting, especiallyif you've been googling around online for resources out ofcuriosity, or if you pick up one of the course'srecommended books on c, you will see that humans have lotsof different preferences for how to express themselves in code. some people like to put thecurly braces as i've done here. some people like to put the curlybraces for instance up here.

>> some people like to put the elsesup here and then this over here. there's any number of ways towrite code, and none of them are right per se. although there's a fewthat are pretty wrong. but there are no-- if this isultimately a very religious debate. in fact, one of the most annoyingthings about computer science is how opinionatedcomputer scientists can be. and you will find over time thateven you develop personal preferences as to how your code should look.

>> not just behave, not just create output,but how it should look aesthetically. so what we will do is guide you alongthe way toward, for now at least, a standard cs50 style that at leastkeeps things uniform and easy to read. but more on thosedistinctions before long. >> a boolean expression in c, if youwanted to say if this condition is true and this other condition istrue, you don't write the word and, as you would in english. you instead use ampersand ampersand,for reasons we'll come back to. if you want to say or you use twovertical bars, which on a us keyboard

is generally above the enterkey next to the backslash. and this just means if this conditionor this other condition is true do this. >> meanwhile there's thiscrazy thing, which you'll have occasionto use once in awhile. but it's just an alternativeway to express yourself. this, for now, let'sstipulate, it's just another funky way of expressingif, elseif, elseif, elseif, elseif. it's just formatted in termsof cases, where you literally enumerate the values thatyou might want to check for.

>> meanwhile loops. we saw a comparison ofscratch with a loop. and i'm going to wave my hand atwhat each of these things means. but notice that a loop will veryoften start with the keyword for. or it will start with the keyword while. or it will start with the keyworddo, and end with the keyword while. >> but what we're about to seeis things more like this. here is, in general in c, how you mightdeclare a variable and give it a value. in c it doesn't suffice,like in scratch, you just

say give me a variable called something. you have to tell c, and tellyour compiler, more specifically, what type of value do youwant to put in the glass bowl. >> is it an integer? if so, you have toliterally say int and then the name of the variable,then a semicolon. if you instead wanted string and calledit s like i did my code here today, you would say string s semicolon. once you want to give it a valueyou can then use the equal sign,

otherwise known as theassignment operator. and notice how eachof these lines of code has the semicolon at the end of it. >> but frankly this justlooks a little ugly. why can't i say to the computer, giveme a variable and initialize it to zero. that is, give me an empty glass bowl. while you can. and so one of the judgment calls you'llhave to make stylistically over time is, do you write your code like this, ordo you kind of clean it up and impress

people by writing two lines as just one. and this would be consideredgenerally a more elegant way of writing your code stylistically. >> functions we're of course seen. they're going to take this format. the name of a function, someparentheses, and then maybe some stuff inside. or you might see uses ofmultiple functions side by side, like something like this.

now as a tangent, doesthis joke now make sense? it doesn't mean it's funny, but itdoes perhaps make a little more sense. so now let's go into thecs50 appliance for a moment. and let me open up one teaser here. >> and indeed one of the reasonsfor introducing ikea catalog and flashing the pictureof the iphone a bit ago was to actually tie in together thefact that just a few years ago, in 2007, this piece of code wasreleased, which was one of the very first implementationof a piece of software

that does what's called jailbreaking. for those unfamiliar, jailbreakingsomething like a phone or an iphone means essentially figuringout how to do things with it that the companywho made it didn't intend. like you want to install certainsoftware that's not in the app store, jailbreaking your phone whichyou do things like that and more. but what was fun in2007-- and there's been dozens of different versionsof these things since then, in all sorts of languages-- is thatthis program here, called iunlock,

was actually written in c. and so ipulled up the source code for this, just to kind of show you some ofthe similarities with the constructs we've been discussing thus far. now there's way more complexity herethan we've seen already in class. let me scroll up just a little bit here. >> but notice these-- well we notice a fewthings-- but notice these lines here, including standard i/o dot h. and all-- line 24, please--notice standard i/o dot h and a whole bunch of otherfiles that apparently other people

have written. and if we scroll down throughthis, little arbitrarily, notice i don't know how to writeall of this myself necessarily yet, but there's if. so apparently this has a branch. >> and if i scroll down a littlefurther there's another if. if i scroll up, i thinkaround line 100 i saw for. so i'm not quite surehow this works yet, but this is a for loop that's going tolet me iterate some number of times.

and if i scroll allthe way to the bottom i see that there's afunction down here called main, and some additional creditsfor your reading pleasure. >> so this is only to say-- and we'll putthis online among the course's source code today-- that even some of thesedevices that we take for granted, at the end of the day you're stillusing these basic constructs that we've been introducing already thus far. that's enough of that one. all right, so now let'sactually build something.

>> let's go beyond something likehello.c, and open up this, let's write this program here. i'm going to go ahead andwrite a program called adder.c, whose purpose in life is going to belike my first super simple calculator that just adds a couple of numbers. not because that's a hardproblem, but because it allows me to now tietogether a few things. so i'm going to go ahead and includestandard i/o dot h and cs50 dot h. i'm going to say int main void.

and again in the futurewe'll come back to it into in this context and void means. >> and now i'm going to say somethinglike printf, give me an integer. and now on my second line,how do i express myself such that i want to declare a variablethat's going to store an int? literally what do i type if i want tocreate a variable that stores an int would you say? int a equals getint. sure, so that works.

and just for consistencywith the code you'll see online, let me changethis to x, just because x is a common variable nameto use, at least in algebra. now let me go ahead and do printf again. give me another integer. and now i'm going to kindof learn from that pattern, i'm going to say int y gets to getint. >> and we've not usedgetint before, but just like getstring goes and gets a string,like javier did from the audience,

similarly does getintstart blinking the prompt. and effectively waiting for the userto give it an integer, by typing it in and hitting enter. now lastly i'm going to dothis, printf the sum of-- and let me get fancy now--percent i and percent i is present i exclamation point backslash n. and what do you think i'm going toput in now as the additional inputs to printf? >> i don't want to sayliterally quote unquote x.

i want to class in x andthen, and now let's get fancy and let's just assumewe can do what we want. what you want to say next? x plus y. and indeed that will work. it's minimally programming languagesdo understand basic arithmetic, and so this should in fact work. >> so let me go ahead and do makeadder in my black and white window down here, enter.

cryptic line but no errormessage, so that's good. dot slash adder, give me an integer, 1. give me another integer, 2. the sum of 1 and 2 is 3. >> all right, so a pretty trivialprogram, but what's it done? it's allowed me to use a functioncall here, call another function here, two calls to getint, athird call to printf, and then using these placeholders. so it's a little moresophisticated than last time.

but what if i want toget a little fancier? >> let me go ahead and now do this. let me go ahead and create anew file called conditions zero. and i'm going to savesome time for classes sake and just paste in thatcode as a starting point. and now i'm just going to putsomething new here in the middle. so printf i'd like an integer please. and all this code is availableon the course's website, you needn't type it all outin class if you'd rather not.

int, and now i'm going touse, instead of x and y, i'm going to use n, which isprobably the most common name for an integer in a computer program. and now i want to do alittle judgment here. i'm going to see if nis greater than 0, then i'm going to say printf-- whoops,printf-- you picked a positive number, exclamation point backslash n. close that. else i'm going to print out printfyou picked a negative number.

>> now before you yell at me,let's run this program. let me go down here. and how do i compile a programcalled conditions dash 0? make conditions dash 0. kind of a stupid name, but-- dammit. ok, good teaching moment. why did that break? >> what did i accidentally call this file? you can kind of inferfrom the tab up here.

so it's not bad that idid this, because this will happen perhaps to some of you. so i accidentally named mysource code condition 0. but my source code by convention shouldbe in a file called condition 0 dash c, or whatever dot c. >> so let me fix this. just like microsoft word i can go upto save as and do condition 0 dot c. now just to be tidy i'mgoing to go ahead and remove condition 0, which was my old version.

and now let's do makecondition 0, enter. ok, seems good. >> condition 0, enter. i'd like an integer please, 50,you picked a positive number. now how about negative 50? you picked a negative number. how about now, 0. pretty sure 0's not negative. >> so this is kind of a logical bug.

how do i fix this? else if n is less than 0, do this, elsewe can have a three way branch here, printf you picked 0. so now if i rerun thisprogram, after compiling it again with make, and now reruncondition 0, what i'll see here is 0 gives me that output. so where are we going with this? >> well it's very easy to lose sightof the forest for the trees. and so allow us to concludewith this 2 and 1/2 minute video

that ultimately is a bitof an ad from google, but that really is testament towhat even using these basic building blocks we can ultimately do oncewe have a bit of programming savvy under our belts. >> saroo brierley (voiceover):it was 26 years ago, and i was just about to turn 5. we got to the train station andwe boarded our train together. my brother just said i'llstay here, and i'll come back. and i just thought, well you know,i might as well just go to sleep

and he'll just wake me up. and when i woke up the nextday, the whole carriage was empty on a runaway train, a ghosttrain taking me i don't know where. >> i was adopted out to australia,to an australian family. and mom had decorated myroom with the map of india, which she put next to my bedside. i woke up every morningseeing that map, and hence it sort of kept the memories alive. people would say, you'retrying to find a needle

in a haystack, sarooyou'll never find it. >> i'd have flashed of the places that iused to go, the flashes of my family faces. there was the image of my mother,sitting down with her legs crossed, just watching her cry. life is just so hard. that was my treasure. and i was looking at google map andrealized there's google earth as well. in a world where you could zoom into,i started to have all of these thoughts

and what possibilitiesthat this could do for me. i said to myself, you know, you'vegot all those photographic memories and landmarks where you're from, andyou know what the town looks like. this could be an application thatyou can use to find your way back. >> i thought, well i'll put adot on calcutta train station, and a radius line, you know, that youshould be searching around this area. i sort of came acrossthese train tracks. and i started following it, andi came to a train station which reflected the same imagethat was in my memories.

everything matched. i just thought yep, iknow where i'm going. i'm just going to let themap that i have in my head lead me and take me back to my hometown. >> i came to the doorstep ofthe house that i was born. and walked around about 15meters around the corner, there was three ladies standingoutside, adjacent to each other. and the middle one stepped forward, andi just thought, this is your mother. she came forward, she hugged me, andwe were there for about five minutes.

>> she grabbed my hand andshe took me to the house and got on the phone, where sherang my sister and my brother to say that, you know,your brother has just all of sudden appeared like a ghost. and then the family was reunited again. everything's all good,i helped my mother out, she doesn't have to be slaving away. she can live the restof her life in peace. >> it was a needle in a haystack,but the needle was there.

everything's there. everything we have in the worldis at the tap of a button. but you've got to have the will andthe determination to wanting it. david malan: wonderfullysweet testimonial to just what you cannow do with technology. we will see you next week.

Subscribe to receive free email updates: