Welcome to Gaia! ::

The Official Lanzer Shrine (June, 2011)

Back to Guilds

 

 

Reply The Official Lanzer Shrine
Xero's studys of C++

Quick Reply

Enter both words below, separated by a space:

Can't read the text? Click here

Submit

Xero1200
Vice Captain

PostPosted: Sat Feb 04, 2006 5:44 pm


All right, i'm going to keep a journal here in the OLS (because i'm too lazy to put it in my actual journal on gaia.) and I will be recording my progress of C++ from here on out...

Whenever I get the feeling of something gravy, I will share it with my friends. I don't know if anyone else will find this interesting, but i'm going to post anyways.

Praises are muchly obliged! mrgreen

P.S. - If anyone is interested in learning C++, I strongly suggest you buy the "Sams Teach Yourself C++ in 24 Hours" Book which comes with a CD for a C++ compiler you can use. I haven't used the CD, but I think it's the Borland compiler. I my-self use Dev-C++ from www.bloodshed.net/devcpp.html which I am completely in love with. 3nodding heart
PostPosted: Sat Feb 04, 2006 5:58 pm


Alright! My first cool thingy ... ish... Which includes the "void" function.

// Listing 5.4 - demonstrates passing by value
#include

void swap(int x, int y);

int main()
{
int x = 5, y = 10;
std::cout << "Main. Before swap, x: " << x << " y: " << y << "n";
swap(x,y);
// Above command calls out "void swap" take this out, the program will
// still compile, but the "void swap" will not be there... try it if you like
std::cout << "Main. After swap, x: " << x << " y: " << y << "n";
std::cin.get();
return 0;
}

void swap (int x, int y)
// Declaring the function here and will be called out by the main function whenever
{
int temp; // int temp is declared
std::cout << "Swap. Before swap, x: " << x << " y: " << y << "n";

temp = x; // whatever x was equal to in "int main" temp will equal that
x = y; // just as it says
y = temp; // y then turns into swap
std::cout << "Swap. After swap, x: " << x << " y: " << y << "n";
}


the "int main()" with the { brace is of course the main part of the program. While the "void swap(blahblahblah);" note: the semicolon there and not with int main() ... The semicolon symbolizes that the function is just a prototype, and has no body of its own. Not until it is declared in the body below the main function. Note that the closing brace } ends a functions body.

I just find this to be a lot of fun ... i'm becomming a fscking nerd whee

Xero1200
Vice Captain


Pharaohess
Crew

PostPosted: Sat Feb 04, 2006 8:57 pm


*pets* I'm sure you're in good company. Probably. And it may not even be permanent. 3nodding
PostPosted: Sat Feb 04, 2006 9:23 pm


Pharaohess
*pets* I'm sure you're in good company. Probably. And it may not even be permanent. 3nodding

*confused*

Xero1200
Vice Captain


Pharaohess
Crew

PostPosted: Sun Feb 05, 2006 5:57 pm


Xero1200
Pharaohess
*pets* I'm sure you're in good company. Probably. And it may not even be permanent. 3nodding

*confused*


*pokes last line of second post*
PostPosted: Sun Feb 05, 2006 6:24 pm


Pharaohess
Xero1200
Pharaohess
*pets* I'm sure you're in good company. Probably. And it may not even be permanent. 3nodding

*confused*


*pokes last line of second post*

... but nerds fsckin' rock

Xero1200
Vice Captain


Pharaohess
Crew

PostPosted: Mon Feb 06, 2006 4:53 pm


I understand. Whatever gets you through the day. sad
PostPosted: Mon Feb 06, 2006 6:41 pm


Now now, no need to show your jealousy.

Xero1200
Vice Captain


Pharaohess
Crew

PostPosted: Tue Feb 07, 2006 1:36 pm


gonk I can't help myself! Is it really that obvious?
PostPosted: Tue Feb 07, 2006 6:15 pm


Pharaohess
gonk I can't help myself! Is it really that obvious?

Afraid so ... clinic's to your left.

Xero1200
Vice Captain


Pharaohess
Crew

PostPosted: Tue Feb 07, 2006 7:18 pm


*sniffs* Thank you.... *walks in the opposite direction*
PostPosted: Wed Feb 08, 2006 3:05 pm


Well, Prototype functions are interesting ... They work a lot like Void functions, but a lot differently.

// Listing 5.6 - demonstrates use
// of default parameter values
#include

int AreaCube(int length, int width = 25, int height = 1)

int main()
{
int length = 100;
int width = 50;
int height = 2;
int area;

area = AreaCube(length, width, height)
std::cout << "First time area equals " << area << "n";

area = AreaCube(length, width)
std::cout << "Second time area equals " << area << "n";

area = AreaCube(length)
std::cout << "Third time area equals " << area << "n";
std::cin.get()
return 0;
}
int AreaCube(int length, int width, int height)
{
return(length * width * height)
}


Like the void function, prototypes are also called by just typing the names. The integers set in the prototype function are default values for Length, Width, and Height. The bottom is the command that "AreaCube" which is Length * Width * Height . When AreaCube is typed in, it returns the values of each of the integers. Very basic, simple stuff.

Ehh ... I want to work on C++ more, so right now i'll just cut it down and show what comes up when you compile(debug) and run it.

Compilage

First time area equals 10000
Second time area equals 5000
Third time area equals 2500

Xero1200
Vice Captain


Xero1200
Vice Captain

PostPosted: Wed Feb 15, 2006 5:34 pm


hmm ... went through a whole chapter without posting any of my learnings ... damn ... And these were really fun to work with..

I just got done with the basics of for, while, and do...while statements ... pretty simple, yet very complex thing. But is something very vital to C++ programming. hmm maybe i'll think about posting up a thing or two ... or not.
Reply
The Official Lanzer Shrine

 
Manage Your Items
Other Stuff
Get GCash
Offers
Get Items
More Items
Where Everyone Hangs Out
Other Community Areas
Virtual Spaces
Fun Stuff
Gaia's Games
Mini-Games
Play with GCash
Play with Platinum