<@cmad> okay then <@cmad> 1 min lemme crash some bastard from some other channel * B_Billy shoots spitball at chalkboard <@cmad> okay back <@cmad> last time we talked about <@cmad> umm <@cmad> lemme see :P functions...correct? ___________________________ <@cmad> we stopped at input and output <@cmad> :\ <@cmad> billy did you read the rest of the log? <@cmad> you had to leave at some part of the class, remember? yup! <@cmad> nice :) <@cmad> functions <@cmad> i think they were pretty much covered for a beginner's level <@cmad> does anyone have any questions about functions before I go on asking? :P * Squibit has forgoten last week :( ummmm....can't think of any it was 2 week ago no <@cmad> nice <@cmad> so can anyone remember what we like to refer to as a function? -> [ozzcoz] PING -> [B_Billy] PING -> [Squibit] PING a bit of code that returns a value ? its like code all collected together to return a result, i think <@cmad> hmm i must be really lagging :\ not again ! yeah, what they said <@cmad> well <@cmad> A function is a grouped piece of code that is executed frequently and optionally returns a result, optionally again depending on the parameters passed to it -> [ozzcoz] PING -> [B_Billy] PING so if i only run it once it isnt a function then ? <@cmad> well <@cmad> usually <@cmad> you group things into a function <@cmad> to avoid typing them again and again or u mean just CAN be executed frequently <@cmad> if you'd just want that code for one time <@cmad> don't bother to put it in a function -> [Squibit] PING how do u do it without a function ? <@cmad> instead of putting the code in a function so the main use of functions is long and repeated code? <@cmad> you just type it inside the code block where the function call would have been <@cmad> ozzcoz: to *avoid* repeating code yeh, thats what i meant did we do a function lastweek ? <@cmad> a function example? Would ya quit pinging meh ! :P <@cmad> i wanna see if i'm lagging Session Start: Mon May 17 21:13:06 2004 Session Ident: #ja-cpp * Now talking in #ja-cpp * Topic is '4th class today' * Set by cmad on Mon May 17 20:09:30 at least he's not snog a in they age thing, we didnt do it there ? there <@cmad> less lag <@cmad> i hope <@cmad> hmm <@cmad> i don't remember -> [Squibit] PING seems quicker <@cmad> ozzcoz: can you try pinging Squibit? -> [ozzcoz] PING -> [B_Billy] PING <@cmad> is this is the lag lesson or what 10 secs :p lol! be back soon * Squibit has left #ja-cpp <@cmad> should we be trying freenode? <@cmad> ppl <@cmad> connect to irc.freenode.net what's that? <@cmad> and go to #ja-cpp <@cmad> a better IRC network <@cmad> connect like ok cya there <@cmad> ./server -m irc.freenode.net <@cmad> that will keep your qnet tab alive :) ./server -m irc.freenode.net * Squibit has joined #ja-cpp hehe ./server -m irc.freenode.net ok try that and if i still lag tough luck :P ok, no dot "." lol! ok... * Squibit has quit IRC (Read error: EOF from client) 1 sec huh? his ping was 1 sec, down from 10? <@cmad> he reconnected <@cmad> ;) then he quits? unknown host -m -> [B_Billy] VERSION :( <@cmad> umm <@cmad> oh lol <@cmad> [B_Billy VERSION reply]: Chatzilla 0.9.61 <@cmad> you don't have mIRC <@cmad> then connect to irc.freenode.net <@cmad> just like you'd connect to irc.quakenet.org <@cmad> (aka w/o the -m) lol! ok... whats the -m switch do? <@cmad> in mIRC it connects to another server using another tab <@cmad> so you can keep both connections Closing Link: B_Billy (Bad user info) :( <@cmad> you need non-caps user name <@cmad> (aka ident) k, lemme try again... <@cmad> we're not starting w/o you :) * B_Billy has quit IRC (Read error: EOF from client) * b_billy has joined #ja-cpp <@cmad> what's wrong -> [ozzcoz] PING i don't know...i'm retarded! <@cmad> well <@cmad> now that we've all reconnected <@cmad> our pings are restored :P lol! well, that was interesting lol! where's squibit? <@cmad> coming * b_billy thinks of a dirty joke where's zero? <@cmad> coming too it's right next to the 9 on your kbd ;) * Squibit has joined #ja-cpp i had a look at my age.cpp code, and i didn't use any "functions" <@cmad> age.cpp ? <@cmad> umm that thing from last week <@cmad> you always use at least on function in C and C++ <@cmad> ALWAYS, at least in an executable program oh you mean main <@cmad> yup <@cmad> age.cpp? <@cmad> hmm well, then one thats just what i called it <@cmad> oh <@cmad> well <@cmad> we can start w/o zero * Zero- has joined #ja-cpp yeh, he wsa l;ate anyway succes!!! maybe not! speak of the devil <@cmad> okay so functions are named pieces of code grouped together mainly to prevent from boring & pointless repeating of code hey! I'm not the devil <@cmad> ok everyone? * ozzcoz pays attention to cmad yep <@cmad> does anyone remember how we declare *variables*? A function is a contained block of code that accomplishes some task. It can be passed parameters and it can return a value. Functions that are part of a class are usually called members. 10 LET A=10 ;) right? <@cmad> b_billy: we're doing C++ here :P variabletype name; *variable type* *variable name* lol! <@cmad> yup <@cmad> correct <@cmad> var_type var_name; <@cmad> or <@cmad> var_type var_name = initial_val; <@cmad> someone give me an example :) int number int cmad = 1 <@cmad> .... float PI float pi = 3.14 * @cmad gets an apgry look <@cmad> *angry ; <@cmad> i can't even type :P ; on the end of all them <@cmad> yes! <@cmad> lol float pi = 3.14; is that correct cmad? <@cmad> b_billy: well you chose a bad example :p <@cmad> don't use floats <@cmad> but if you really wanna use'em <@cmad> do ? <@cmad> float pi = 3.14f; <@cmad> the compiler takes all decimal values as doubles <@cmad> not as floats double myiq = 0; <@cmad> int IQ = showSize; <@cmad> :P int idnumber; <@cmad> ok <@cmad> i see you all remember how to declare variable <@cmad> s <@cmad> what about functions? int transaction_number; so for a float, you would have to add an 'f' at the end of the number? bool myStatus = true; bool yourStatus = false; int function() { returnvaluetype func_name (sentvalue) { code here } ohoh is that bad or good? lol <@cmad> Zero-: that was variables int number_of_students = 30; <@cmad> that's variable too <@cmad> ozzcoz got it right <@cmad> Squibit missed a } <@cmad> ummm no ozzcoz forgot something :P i stopped as ozzcoz finished it for me nah, i put it there for him too :p how many exampels do you need? <@cmad> ret_type fun_name ( var_type param1, var_type param2, ..., var_type paramN ) { <@cmad> //code here <@cmad> //optionally do <@cmad> return ret_value; //e.g. return 1; <@cmad> } o yeh, forgot your too fussy :P <@cmad> something tells me you'd like an example :P nah, its important yay examples!!! 3.14f? <@cmad> double ArithmeticMean ( double a, double b ) { little slow there zero <@cmad> return (a + b) / 2; <@cmad> } <@cmad> now if we supply two values to out function <@cmad> for example 3 and 5 <@cmad> we'll get the arithmetic mean <@cmad> i.e. 4 how come? you just defined it to be a float <@cmad> me? -> [Zero-] PING -> [b_billy] PING i think Zero- may be lagging... <@cmad> yeah a huge lot :P -> [Squibit] PING <@cmad> do you wanna see how functions are used in a real program? <@cmad> i.e. how they're declared and called 4,1Squibit did a CTCP PING on you. yes please it would proberly say -10 in your case cmad, lol =) yeh <@cmad> ok zero is back here int IQ = showSize; <@cmad> i know <@cmad> :P <@cmad> ---------------------START (don't say anything till it's done) ------------------------- <@cmad> #include <@cmad> using namespace std; * Zero- has quit IRC (Read error: Connection reset by peer) <@cmad> double ArithmeticMean (double a, double b) { <@cmad> return (a+b)/2; <@cmad> } <@cmad> int main() { <@cmad> cout << "Enter 2 numbers seperated by a single space: "; <@cmad> int num1; <@cmad> int num2; <@cmad> cin >> num1 >> num2; <@cmad> int rslt = ArithmeticMean(num1,num2); <@cmad> cout << "The arithmetic mean is " << rslt << "\n"; <@cmad> return 0; <@cmad> } <@cmad> ------------------END----------------------------- <@cmad> now here's a program with many things to discuss :P * Zero- has joined #ja-cpp <@cmad> wb ahh..ok, so ArithmeticMean is alrady pre-defined? guess who's back <@cmad> we defined it, yeah you are Zero- <@cmad> otherwise, instead of ArithmeticMean(num1,num2); <@cmad> we'd have to write (num1+num2)/2; <@cmad> in every place we wanted to get the arithmetic mean <@cmad> ;) oh, never! <@cmad> ozzcoz <@cmad> imagine having to do that with a 300line function :o -> [Zero] PING ok, i gotcha -> [Zero-] PING where? -> [Zero-] PING what? LOL u missed half lesson so, it gets defined here: cmad double ArithmeticMean (double a, double b) { cmad return (a+b)/2; <@cmad> yeah minus the cmad part <@cmad> yup :P ok, cool got it! <@cmad> note that a function must be defined before used <@cmad> i mean <@cmad> declared <@cmad> note: declared is NOT defined <@cmad> by declaring you just specify the name of the function what are we talkin about? <@cmad> by defining you also specify the code zero u missed it <@cmad> b_billy: ozzcoz: Squibit: are you confident enough that you've got it? yep ill pm u enough for what ? :P <@cmad> to continue i think so <@cmad> i'm not going on till you've got it :P yeah :) well a practis excersize might help ? <@cmad> ok <@cmad> write a program <@cmad> that asks the user for 3 numbers <@cmad> and then prints the sum of them <@cmad> using a function of course I'll disconnect and read the log later do we put all this into the main function ? <@cmad> well make a function named GetSum() like the summing function is within main <@cmad> and then call it from main() <@cmad> no <@cmad> define the function outta main() <@cmad> just like I did in the example -> [Squibit] PING kk -> [b_billy] PING -> [ozzcoz] PING it's no use... I'll quit. later guys * Zero- has quit IRC (Read error: EOF from client) <@cmad> ozzcoz: b_billy: are you doing it? oh, yeah, sorry yep, im on it ok, i wrote it up in notepad, how should i show you? <@cmad> hmm i copied a little from the above program...i hope that's ok <@cmad> paste parts of it <@cmad> not all at once <@cmad> or you'll get flood-killed 2 C:\2 unable to run program file. ? lol! <@cmad> Squibit: don't run it <@cmad> just give the code <@cmad> ah billy <@cmad> plz do it in pm <@cmad> all three of you in pm <@cmad> or the channel will get screwed done <@cmad> ozzcoz got it 100% right * tarpman has joined #ja-cpp w00t * ozzcoz snogs tarpman * tarpman snogs everyone, including fishbot <@cmad> hey tarp <@cmad> there's no fish here :P there should be you fool <@cmad> no there shouldn't <@cmad> or i'd never get op again <@cmad> for there is no L heh true get L then :P * tarpman goes over to #nippledom to snog fishbot <@cmad> oh btw <@cmad> you don't need to do <@cmad> double a; <@cmad> double b; <@cmad> double c; <@cmad> you can do <@cmad> double a, b, c; <@cmad> (but not in param declaring) cool :) what like this? function () { double a, b, c; } <@cmad> no <@cmad> well <@cmad> in main() you all did <@cmad> double a; <@cmad> double b; <@cmad> double c; <@cmad> what i'm saying is that you could have done <@cmad> double a, b, c; ok i just noticed a typo in my code :p who we still waiting on? <@cmad> dunno <@cmad> :P me me mines pooped except i haven't started yet <@cmad> oh * ozzcoz slaps tarpman around a bit with a large trout <@cmad> i just noticed a bug in my code <@cmad> (thx BB btw) hahaha <@cmad> the function expects doubles as params <@cmad> and gives a double result lol! <@cmad> yet i declared int params <@cmad> lolol sry :P do we DCC it to you when it's done, or what? <@cmad> tarpman: pm <@cmad> but you know C++ <@cmad> cheater :P <@cmad> or as JJ likes to say <@cmad> WANKER :P :D review is always good and this is a bit simpler than MSDN <@cmad> ok i love my linux screensaver :P ozzcoz code wont run either isn't jj's new one, "bawbag" my compilers messed up :? why are you telling me in particular? <@cmad> ozzcoz: he wanted to pm it to me <@cmad> :) <@cmad> ok now cmad gave ,me your code to try but i cant run it either ok :) mine won't run either <@cmad> did you compile it? the } after return a+b+c gives an error :( yup <@cmad> billy you forgot a ; <@cmad> in the a+b+c <@cmad> <@cmad> double ArithmeticMean (double a, double b) { <@cmad> <@cmad> return (a+b)/2; <@cmad> <@cmad> } <@cmad> okay <@cmad> back to here aha!!! * tarpman tries to figure out a program to return the sum as 3D text in an OpenGL window <@cmad> instead of doing "return (a+b)/2;" except not i'm too lazy for that <@cmad> we could have done something really stupid like <@cmad> double result = (a+b)/2; <@cmad> return result; <@cmad> } <@cmad> that is, declare another variable whereas we could have avoided that <@cmad> and in the main() code <@cmad> where we did <@cmad> double rslt = ArithmeticMean(num1,num2); <@cmad> cout << ....... << rslt << "\n"; <@cmad> we could have just done (to avoid using "rslt") how about cout << (a+b)/2; ? oh, you're getting to that <@cmad> cout << ........ << ArithmeticMean(num1,num2) << "\n"; :P <@cmad> tarpman: no <@cmad> i'm teaching them about function, i'm showing'em what functions are for anyway, i'll leave you to it i have no idea what's going on <@cmad> i could have given them a 300 line function :P so i would just mess things up k i see optimizations are for another day are they :P <@cmad> yeah <@cmad> for the im-newbity day :P :S <@cmad> anyway derp * tarpman has quit IRC (Quit: i smell food! FOOOD!!!) <@cmad> does anyone have any questions on the Sum() code or the ArithmeticMean() code? mode code compiled and ran for me ok i think i got it now <@cmad> sure? i'm sure that i think i got it now :) <@cmad> ozzcoz? Squibit? what was tarpy saying? <@cmad> what one of you said that he smells food! FOOOD!!! <@cmad> that we could have just done "(num1+num2)/2"; <@cmad> instead of doing a whole function <@cmad> but i think you understand why i did all this function thing oh, yeh, der :p yup <@cmad> i don't think we should be moving on to if statements yet b4 we go on, how do you do the pause thingy again? <@cmad> so it would be better to revise what we've done <@cmad> system("pause"); ahhh...thx! <@cmad> ok <@cmad> REVISION hmmm...not working, i'll ask later <@cmad> b_billy: put system("pause"); right before "return 0;" in main() k, thx <@cmad> ok <@cmad> 1) What are header files and what are they good for? premade code you copy in good for commonly used code that you dont want to have to redesign ...no reinventing the wheel! <@cmad> ozz? yeh, what they said, premade code <@cmad> ok <@cmad> well <@cmad> correct <@cmad> and i like billy's phrase :P :) he always says it :) * b_billy reinvents the wheel cmad & orion said it 1st! <@cmad> 2) How do you include header files from the current directory, and how from the standard header file directory of the compiler? #include "headerfile" #include ,headerfile> ? doh <> for standard files and "" for current directory #include #include * <@cmad> right :) <@cmad> damn you're good at this :P we learnt from the beast *best best* LOL lol! lol <@cmad> 3) What header file is the one you have to include in order to be able to read/write from/to files cmad = beast! <@cmad> lolol :P <@cmad> omg rwstream ? <@cmad> then you guys say Virtue makes the worst typos ever :P iostream im not sure lol! <@cmad> Squibit - wrong <@cmad> b_billy - nope the heat/head one is hard to beat * @cmad looks at ozzcoz im not sure <@cmad> no <@cmad> it's........................... fstream ah...ok iostream is for input and output to and from the kbd ive never heard of it before but i assume it stands for File STREAM <@cmad> yeah <@cmad> ok done with header files <@cmad> 4) What are variables? a memory location where you can store a value with a given name a bit of memory that can change ? data stored in memory with identifying names <@cmad> a named piece of memory holding a value and treated in a way according to its type ...or 10 LET A=25 ;) <@cmad> ./amrename b_billy TheBASICman lol! Atari BASIC that is... <@cmad> ./amrename b_billy The*BASICman <@cmad> put w/e you want in * <@cmad> :P <@cmad> ok lol! <@cmad> 5) How are variables defined? type name = initialvalue; var_type var_name = initial value; double num = 25; that last bits optional <@cmad> right <@cmad> ./amrename The*BASICman TheExampleMan <@cmad> :P <@cmad> well to sum it up lol! <@cmad> ./amrename b_billy The*Man <@cmad> heh lol! will this be on the exam? <@cmad> aaaah dunno :P <@cmad> aka ain't tellin <@cmad> ok * ozzcoz notes that b_billy is the*man <@cmad> 6) What are functions? pop quiz next monday!!! in keeping with my * status... code thats defined in one place so you don't have to keep repeating it double Sum_it_up (double a, double b, double c){ grouped parts of code that are frequently repeated and optioanly return a value <@cmad> nice Squibit :) Woot i did a proper description thingy ! instead of a bit of summut that can be code :P lol! could you put a function in a header file, and use that in a number of programs? <@cmad> yeah OMG! i found the problem i changed name of folder :P LOL :P my code is floorless *flaw Squibit = silly wabbit ozzcoz = silly wabbit2 <@cmad> b_billy = still_tha*man <@cmad> :P lol! <@cmad> ok Woot ozzocz code works ;P <@cmad> that's it for today silly wabbits :P cmad = the beast lemme redo mine cmad = the uber teacher <@cmad> lol <@cmad> thx, i guess :P lol <@cmad> yeah ty too ozzcoz :P hehe bah lost mine thx beastman!