<@cmad> OK can we start? yup yes, lets gogo <@cmad> okie <@cmad> last time we stopped at variable naming if i'm not mistaken <@cmad> let's revise a bit i guess i am lagging...should i try to reconnect? <@cmad> B_Billy: yes <@cmad> OMFG [B_Billy PING reply]: 1min 42secs <@cmad> anyway <@cmad> now to revision <@cmad> does anyone remember what header files are? other files premade that you call into your program k, brb... * B_Billy has quit IRC (Read error: EOF from client) <@cmad> _call_? like paste automaticly <@cmad> first of all, who was here last time <@cmad> lol ME! * ozzcoz puts hand up <@cmad> okay let's wait for Billy k sorry this is my first class <@cmad> Blackwolf[JO]: you should read the logs of the other classes * B_Billy has joined #ja-cpp <@cmad> hey BB <@cmad> wb thanx <@cmad> ok <@cmad> we're doing a revision <@cmad> here we go <@cmad> Squibit, ozzcoz, B_Billy: anyone remember from last time what header files are? aren't header files what you "include" in your code? it's code that's already been written <@cmad> ys so you don't have to "reinvent the wheel" <@cmad> hah nice Billy :P :) ie: #include iostream; at the beginning of the code <@cmad> it's code already written giving extra functionality to the compiler, by including which you don't have to rewrite the whole thing <@cmad> ozzcoz: you mean #include uh...yeh <@cmad> ummmm i think i forgot to mention something about header files last time <@cmad> you can include header files in your code with two ways <@cmad> 1) #include <@cmad> 2) #include "name" <@cmad> the first name searches for the file with the name specified <@cmad> and returns an error if the file wasn't found <@cmad> *the first way <@cmad> the second way searches first at the current directory for the file specified I have a qeustion <@cmad> and if it's not found, it goes on the std header file directory <@cmad> yes BW? well i have know idea whats going on so was wonder if when you get to start things again then i should start the class <@cmad> that's SOME time from now, i assure you <@cmad> still, you can read the previous 2 logs <@cmad> and come to me or orion for any questions yes im sure i would like to start at begaining <@cmad> with any non-IE browser check out the site http://www.ja-cpp.tk and in the Classes section d/l the logs <@cmad> the new beginning is a long time from now <@cmad> since we just started ok when will that be <@cmad> dunno <@cmad> when this course is finished <@cmad> could be in a few months LOL, he doesn't know ok :P <@cmad> "few"... heh alright thats cool ill just keep in touch and start from the begining how do i get the program to stop at the end so it doesn't just flash ? yeah, just hang out and d/l the logs...that's what i'm doing for the 2nd part of 2days class pause in some format wasn't it ? <@`Orion> system("cls"); <@cmad> Squibit: add a line system("pause"); <@cmad> can we go back to the class <@cmad> ? ISO C++ forbids declaration of 'system' with no type <@cmad> squibit * Blackwolf[JO] has quit IRC (Quit) <@cmad> in the main() function <@cmad> before return 0; ah sry <@cmad> ok back to revision <@cmad> now as i said there are 2 ways of including header files <@cmad> one way with and other way with "name" <@cmad> is for files in the std header file directory <@cmad> "name" for files in the current directory <@cmad> let's say for example that you have made a header file named myheader.h <@cmad> and in the same directory, you make a source code file which uses that header file <@cmad> what would you do in the source code file? #include "myheader" #include "myheader.h" do u need the .h ? <@cmad> yes <@cmad> it's part of the filename iostream doesnt have it ? <@cmad> it doesn't <@cmad> iostream is NOT iostream.h so its no filetype? <@cmad> .h is header file filetype <@cmad> no extension is no filetype <@cmad> but the compiler doesn't care ah <@cmad> ok <@cmad> does everyone understand the difference between #include and #include "name"? yep we all do :) <@cmad> you speak for everyone? <@cmad> :P * ozzcoz nods -> [B_Billy] TIME indeed i understand <@cmad> ok <@cmad> then in the helloworld source code, we skipped the line that says "using namespace std;" <@cmad> then we went went on talking about variables <@cmad> who remembers what a variable is? ozzcoz :) 10 LET A=25 ;) <@cmad> brb phone yes Squibit? :) <@cmad> k bk ozzcoz remembers <@cmad> no-one remembers!? wait a tick <@cmad> a piece of memory assigned to store some data? <@cmad> GOOD! <@cmad> lol <@cmad> cheater lol! <@cmad> :P told you he remembered :P and there are different types of variables <@cmad> a named pieve of memory storing data which is treated in a special way according to the variable type <@cmad> :) damn you ctrl-v i wanted to edit that <@cmad> *piece <@cmad> yes <@cmad> as Billy said, there are different types of variables <@cmad> for example: int (integer), float (floating point decimal), double (double accuracy float), char (1-byte in length type) <@cmad> variables are declared like: ( = ); <@cmad> example <@cmad> int abc = 5; <@cmad> or <@cmad> int def; if i wanted A = Cmad rulez what vairiable type is this ? <@cmad> how would we declare a variable of type double, named my_double, how would we do it <@cmad> Squibit: that's more complex k :) <@cmad> in C++ it's string A = "cmad rulez"; <@cmad> in C it would be a pain in the ass <@cmad> if we wanted the string to be change-able <@cmad> otherwise we could do it like <@cmad> char *A = "cmad rulez"; double my_double = 5 double my_double = 3.234566; <@cmad> B_Billy: where did you find the 5? double my_double; <@cmad> yes <@cmad> nice i pulled it out of my butt :) <@cmad> lol <@cmad> ok <@cmad> now <@cmad> there are 2 categories of variables <@cmad> constant variables and normal variables easy and hard ? <@cmad> no darn <@cmad> lol LOL, constant variables ?.... that makes no sense <@cmad> with constant variables, they can only be given a value during initialization and never again constant variable = oxymoron then they aint variable are they :P <@cmad> they are why not just call them constants ? <@cmad> we do :P they are until you assign them a value, correct? <@cmad> it's the short name its the sensible name :P <@cmad> B_Billy: you assign them a value during their initialization <@cmad> you can never do it again right, that's what i meant <@cmad> to say that a variable is constant, you must put "const" before the type name during definition <@cmad> for example <@cmad> const int abc = 5; <@cmad> now abc is a variable of type int, holding the value 5 which can never be changed again during program execution why bother? why not have all normal ? and then change em if u want to <@cmad> change them to const? <@cmad> you bother esp. if you are a header file writer no why make it const ? <@cmad> if you try to change the value of a const, you get an error message <@cmad> for example you got a header file <@cmad> and a variable called MaxLines <@cmad> it should ALWAYS be set to 1000 (for example) ah so to make sure u dont change it by mistake ? <@cmad> yes <@cmad> that so why not just name it constabc instead of making whole new variable type? <@cmad> because constants ARE variables only idiot would change value of a variable called constabc incase sumone else is using your header <@cmad> and they have a type <@cmad> <@cmad> a named piece of memory storing data which is treated in a special way according to the variable type <@cmad> i never said the value can keep changing hmmm, thats not what i mean ... If i could just call it constabc , why not just do that instead of an acctualy constant type ? <@cmad> you mean "const abc" no i mean the name of the normal variable <@cmad> ah constabc <@cmad> why do that? so i dont chnage it ? <@cmad> const is there to prevent you from changing it 1 less button to press , no need for space ? <@cmad> cuz you get an error msg if you try to do so but im not gunna chnge a vairable i have named constabc even if i can <@cmad> maybe not you and hten if halfway thrught i do need to change it i can Squibit, it's there. deal with it! <@cmad> but if you write a header file <@cmad> and publish it <@cmad> ppl might wanna change it <@cmad> (the var's value) AH! <@cmad> and it will have BAD consequences ok missed that :) I wondered what ozzcoz meant by other people :P :P <@cmad> lol <@cmad> ok <@cmad> btw: we're gonna have a 10 min break at 8pm <@cmad> (GMT) * Squibit says that that is ok <@cmad> ok * Squibit wonders why i didnt just type ok without the /me says <@cmad> anyway <@cmad> now tell me <@cmad> would it be clever to do <@cmad> const int abc; <@cmad> ? no you need = ... or theres no point then you have a variable with no value that you can't give a value! <@cmad> yes :) lol! <@cmad> would there be a point to do ummm <@cmad> double my_double; <@cmad> ? maybe, yeh but i would put = ... cuase why do it otherwise ? even if it was = 0 you may want to use it in the prog later without the = you're not actually assigning anthing, right? <@cmad> you're not <@cmad> right <@cmad> but it gets a default value but if u sue it later whynot just define it later, ? <@cmad> most times the def val is 0 ah so it auto does the 0 didnt know that <@cmad> yes MOST time <@cmad> *times <@cmad> so <@cmad> i hope you understand the difference between const and normal vars as well <@cmad> do you? :P yep yup! <@cmad> Squibit? sorry had to gho afk 1 mo Squibit! stop surfing for pr0n!!! ;) <@cmad> LOL yup <@cmad> anyway i get it <@cmad> let's move on to functions <@cmad> anyone have any idea what a function is no :( somthing that does summut then sends back a value? <@cmad> well that too squibit <@cmad> but more generalized <@cmad> and more programming-related lol thought that was fairly general <@cmad> ok somthign that does summut :P <@cmad> a function is a way of grouping together your code and optionally return a value after doing the required processing <@cmad> a function can take parameters, just like in math * @cmad hopes everyone knows what function params are in math whats math? you mean like addition, multiplication, etc. math? :) <@cmad> well in math let's say you have <@cmad> f(x,y,z) = x^2 + x*y + y*z^2 <@cmad> x y and z are the parameters of the function f oh, ok, i get ya ahh, ok like calculas :P <@cmad> parameters are values a function needs in order to do what it's supposed to do haven't been in a math class in like 15-20 years <@cmad> lol <@cmad> ok we dont do functions till next year :P <@cmad> in C and C++, you declare a function in a similar with variables <@cmad> it's like <@cmad> ( ) <@cmad> { <@cmad> <@cmad> <@cmad> <@cmad> } <@cmad> i'm sure you want an example :P lol! yes please <@cmad> double GetSum ( double a, double b ) <@cmad> { <@cmad> return a + b; <@cmad> } <@cmad> double is the return value type of the function we named GetSum <@cmad> double a is the 1st parameter <@cmad> double b is the 2nd parameter <@cmad> in a function you return values like "return ;" * ozzcoz has quit IRC (Ping timeout) all the <> are confusing me :P <@cmad> even if the function has no parameters <@cmad> the ( ) next to the function name ARE MANDATORY <@cmad> in order to make a difference with a variable of course <@cmad> okay <@cmad> in the helloworld.cpp we got in the 3rd line <@cmad> int main() { so, the 4 lines below my "lol! yes please" are the actual code <@cmad> yes Billy <@cmad> now <@cmad> int main() { ... } <@cmad> is that a variable or a function? function function <@cmad> correct :) otherwise u wouldnt have just told us all that :P <@cmad> Squibit: there is absolutely no variable in the program <@cmad> but i told you about variables <@cmad> ;) <@cmad> well <@cmad> maybe there is a variable :P <@cmad> (it's cout) <@cmad> okay <@cmad> will we take the 10 min break now? ok, i gotta go i'll d/l the transcript l8r <@cmad> cya :) <@cmad> ok thanx cmad! * B_Billy has quit IRC (Quit: ChatZilla 0.9.52B [Mozilla rv:1.6/20040113]) * Squibit taps fingers on desk * ozzcoz has joined #ja-cpp * Squibit looks around * Squibit jumps up and down :P * Squibit tries to lick his elbow * Squibit is ready for more programing now sorry, sum1 ping spammed me :) whered they all go? break time oh, ok will we take the 10 min break now? ok * ozzcoz breaks <@cmad> 5 mins left <@cmad> ozzcoz: we went into functions ok <@cmad> well nah let's start again anyway ok <@cmad> why would someone want to categorize his code into functions? <@cmad> Squibit: are you here? sorta * @`Orion raises hand BB isnt back yet <@`Orion> he had to leave <@cmad> Squibit: he won't be back today <@`Orion> job interview oh :( ok well i guess im set then <@cmad> you're student again orion? :P ??? <@cmad> okay say orion :P orion why did u want me to say that ? <@cmad> ......... * @cmad pokes orion <@`Orion> to organize code <@cmad> there * @cmad gives orion an A+ <@cmad> :P <@`Orion> and so u can make the generic enough to reuse <@`Orion> and for readability <@cmad> `Orion: and to save you from more typing :P <@`Orion> dont want a one trillion line main function :P * @`Orion eats <@cmad> `Orion: imagine what JKA source would look like if everything was in main() :o <@`Orion> :/ <@`Orion> 30mb main file :o <@cmad> okay <@cmad> on to the next line <@cmad> cout << "Hello World\n"; <@cmad> cout is an output stream (ostream) variable <@cmad> that is, a variable that allows you to write stuff to the screen <@cmad> "<<" here is an operator which puts the right hand data, to the left hand variable <@cmad> so <@cmad> with cout << "Hello World\n"; <@cmad> "Hello World\n" is put into cout <@cmad> and the result is that you see "Hello World" in the screen <@cmad> \n is a special character called a newline character <@cmad> it's something like at the end of the line, to change to the next line <@cmad> tell me <@cmad> how would you output "I am a C++ program" to the screen cout << "I am a C++ program" <@cmad> you forgot a ";" there cout << ""I am a C++ program""; <@cmad> cout << "I am a C++ program"; <@`Orion> printf("I am a C++ program); :o <@`Orion> too many " Squibit ? but he put " <@`Orion> ony need one set of " <@cmad> b00000 @ orion's C code :P so to make the " you need "" ? <@`Orion> uu had "" <@`Orion> -u yeah cause cmad wanted "I am .... <@cmad> no i didn't <@cmad> i just used the quotes to say where the text begins and ends <@`Orion> lol oh :P derp <@cmad> Squibit: if you wanted to add the extra " " <@cmad> you'd have to do <@cmad> cout << "\"I am a C++ Program\""; <@cmad> ;) ah ok <@`Orion> all the \n, \" are called escape sequences <@cmad> you can display multiple data with cout too how would you get "\I am a C++ Program\" \\? <@`Orion> cout << "\"\\I am a C++ Program\\\""; <@cmad> ozzcoz: cout << "\"\\I am a C++ Program\\\""; <@cmad> yeah lol LOL <@`Orion> :P k ozzcoz only asked to make em do summut stupid ;P <@cmad> ok <@cmad> you can output multiple data like <@cmad> cout << "This " << "is " << "a " << "test\n"; <@cmad> this prints <@cmad> This is a test <@cmad> also <@cmad> cout << "The value of variable a = " << a << "\n"; <@cmad> so if in the program you had set a to be 7 <@cmad> the output would be <@cmad> The value of variable a = 7 <@cmad> okay let's make the level a bit higher :P <@cmad> paste here code that does the following <@cmad> set the value of variable x to 10 and variable y to 20 <@cmad> and output the values of both variables <@cmad> you don't have to write the #include and the using namespace std and the int main() hmmm, k int x = 10; int y = 20; cout << x << y; :P <@cmad> umm not exactly wiat <@cmad> that would output <@cmad> 1020 leeme think <@cmad> ;) errr, yeah what ozzcoz said <@`Orion> oo <@`Orion> can i show <@cmad> oo <@cmad> yeah orion :P <@cmad> don't gimme that stupid printf() solution :P 1020 is what we want ? oh you mean <@cmad> we want 10 20 <@cmad> what ozzcoz said would give us 1020 <@`Orion> cout << "x = " << x << ' ' << "y = " << y << '\n'; /*OR*/ printf("x = %i y = %i",x,y); <@cmad> orion or you nverer said with a space between them :P <@cmad> int *x = new int; int *y = new int; <@cmad> &x = 10; &y = 20; <@cmad> blah blah <@`Orion> lol <@cmad> cmon i've never said anything about double quotes and single quotes <@cmad> :P <@cmad> let's not give them a headache lol I had one since... <@cmad> well simpler wht does ' ' do? [19:17] ok <@cmad> cout << x << " " << y << "\n"; <@cmad> ' ' is for single characters <@cmad> " " is for multicharacter strings k :) <@cmad> for example you must use "abcdefg" <@cmad> but you can use 'a' <@cmad> or 'B' <@cmad> or '\n' so in what u just did in them iddle <@cmad> (\n is only 1 character) u could have done ' ' <@cmad> yes instead of " " kk <@cmad> and i could have done it in "\n" why tho? <@cmad> so i could have done <@cmad> cout << x << ' ' << y << '\n'; why bother to do ' ' ? <@cmad> cuz it's needed for chars <@cmad> (character variable types) ah kk <@cmad> okay <@cmad> inputing data is SIMILAR to outputing data <@cmad> for example <@cmad> cout << "What's your age: "; <@cmad> cin >> age; <@cmad> what would this program do? <@cmad> cin is an input stream variable, which reads data from the screen <@cmad> unlike cout, cin uses >> to store the values gotten from the screen to variables youd have to define the variable first right? <@cmad> yes cant u define it there ? cin >> int age; <@cmad> ummmm ? <@cmad> i'm not sure <@cmad> i think not <@cmad> _think_ <@cmad> `orion? LOL, orion u bothered comming here why ? :P <@`Orion> wha <@`Orion> no *cough * type *cough* * Squibit wakes up teachers <@cmad> yes? um, i just tries it <@cmad> okay and g++ gave me an error fo that line <@cmad> now let's do an excercize <@cmad> write a program <@cmad> that asks the user for his age <@cmad> reads the age and tells him how long till hes 50 ? <@cmad> and then says "Your age is " <@cmad> no kk <@cmad> remember <@cmad> your program should start like <@cmad> #include <@cmad> using namespace std; <@cmad> int main() { <@cmad> the code here <@cmad> and here <@cmad> and here and here <@cmad> return 0; <@cmad> } <@cmad> anyone even trying? #include using namespace std; int age; int main() { cout << "How old are you? \n"; cin >> age; yeh, wait cout << "Your age is " << age; system("pause"); return 0; } <@cmad> !!!!!!!!! * @cmad hates Global variables ? ? <@cmad> Squibit: move that "int age;" inside "int main()" <@`Orion> :P you didnt teach us that ah kk done <@cmad> okay now compile it Squibit no need to repost right :) <@cmad> and then run it worksies :)_ <@cmad> ozzcoz: what are you up to? hmmm im gunna change my system pause button typing, slowly hmm that bust :( how do i get it so that they dont need to press enter soon as they press 1 key it finishes cin <@cmad> ummmmmm <@cmad> with system("pause"); <@cmad> it exits with 1 key pressed <@cmad> wtf are you talking about yes but i tiried to use cin cout so it says press any key to quit not press any key to continue <@cmad> i don't think you can edit the function <@cmad> but you can make your own <@cmad> ;0 <@cmad> ;) ? i was tring to make my own <@cmad> you'll have to make your own pause cout << "Your age is " << age << "\nPress any key to quit"; cin >> age; cause i dont need age anymore <@cmad> huh <@cmad> that's the weirdest code ever :o ? what ? <@cmad> you don't know age, but you output age lol <@cmad> and then you read age, when the user's not expecting it int age; cout << "How old are you? \n"; cin >> age; cout << "Your age is " << age << "\nPress any key to quit"; cin >> age; the last cin is just so they have to type i dont redisplay it but u need a variable ? <@cmad> ah <@cmad> nah <@cmad> well but they have to press enter ? huh? <@cmad> cin >> age;w <@cmad> would wait for <@cmad> *ENTER hmmm <@cmad> OMG the stupidest typo eva press enter to quit ? :) <@cmad> yeah that can work it didnt quit :) ? <@cmad> ? i press enter and cursor just moved down <@cmad> ummmmm yeah sry <@cmad> you'd have to type a number that way ah yeah ! <@cmad> just stick with system("pause"); for the moment doh hehe ill make a new variable what type should quit; be ? string ? <@cmad> hmm <@cmad> either string or char <@cmad> lemme check string didnt go bold 10 C:\hello.cpp parse error before `;' token ? <@cmad> you'll have to <@cmad> #include <@cmad> to use string oh duh i typed cin >> char hmm getting there now its character, enter ozzcoz still doing code ? uh, ok, i have a linux question * Squibit zones out <@cmad> #include <@cmad> #include <@cmad> using namespace std; <@cmad> int main() { <@cmad> string a; <@cmad> cout << "press enter to exit\n"; <@cmad> getline(cin, a); <@cmad> return 0; <@cmad> } <@cmad> there <@cmad> that works getline ? <@cmad> ozzcoz: yes? <@cmad> Squibit: more advanced :) wheres my compiled stuff and how do i exec it <@cmad> in the current directory << less advanced <@cmad> let's say you got the source code file abc.cpp <@cmad> and you compile it with <@cmad> g++ -o abc abc.cpp <@cmad> there's an executable abc, in the current folder <@cmad> (where abc.cpp is) <@cmad> BTW: should this class be dismissed? ok <@cmad> class dismissed