Smileman
02-09-07, 04:11
Hello my name is Kozical.I will be slowly walking you through this step by step and giving as much information as I recall it. I learned C++ a long time ago so bare with me. I will try my best to explain it thoroughly and also try to make my code simple enough for you to understand.
Tools required:
DevCpp (Free C++ compilation environment. I recommend it for beginners with no money) you can download that here http://www.bloodshed.net/devcpp.html
One moderately intelligent fellow
At least a few hours to spare.
Alright we'll start small with a few examples of a console application.
Firstly open up DevCpp after you have downloaded and installed it.
---
Step 1: Open DevCpp then proceed to File (alt+f) -> New (alt+n) -> Project (alt+p)
Step 2: At this point you will see a photo that resembles (VA-01)
VA-01:
http://img407.imageshack.us/my.php?image=section1step2ux9.gif
Step 2 (continued): Select Console Application and then name your project Day1Project1
Step 3: Save your .dev (project file) to a location in which you feel comfortable keeping your c++ files.
Step 4: Right from the start DevCpp will equip you with a working application containing the code in VA-02 (below); at this point you can proceed to goto Execute (alt+x) -> Compile & Run (F9)
(note: this will ask you to save main.cpp just save it wherever you saved your Day1Project1.dev (project file) )
VA-02:
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
system("PAUSE");
return EXIT_SUCCESS;
}
Step 5: When this application runs it will appear blank and ask you to press any key to continue. This is a console application in action. However we want a more complex application so we will continue on. Now press a key to exit and go back to your code. I will go ahead and explain what each part does.
-
In C++ there are many types of data this you'll learn over and over again. All of which can be converted back to digits but we are nowhere near that far at this point. So I will explain some more about these 'types'.
In the code displayed you will see int and char. int as you may have guessed stands for integer integer is a number. So you may put only numbers into an integer variable. Example: int nTest = 1; You may safely say that nTest is equal to 1 now. Now char on the other hand stands for character which in this case we will only use ASCII characters. Example: char cTest = 'K'; Now as you may have guessed cTest is equal to K. Notice I added ' and ' around my character this signifies to the compiler that this is a character and not an integer.
In the coming exercises we will use these a lot but we still have not covered all the material given in your code. #include as you may have guessed includes another file to your current code. We will cover this more as we progress as of right now we're keeping this simple. int main(int argc, char *argv[]) is the main function of your code anything done in this function will directly effect how your program works. That being said anything not done in this function will directly effect how your program works. If you add nothing to main 's function then your program will do nothing.
We will cover two more things and progress to our first exercise. using namespace std; we will cover this in other projects but I will say that the namespace keyword lets you partition an application into multiple subsystems. system("PAUSE"); this will stop your application from continuing and will send the message "Press any key to continue.." As you saw before when you compiled and ran the program.
Step 6:
In this step we will be working with the function cout which is basically an echo function for those of you who have used mIRC, php, perl, or any other coding/scripting languages. What this does it output characters to the console and that kind of works well with the name. There are several of these functions in C++ in which I will cover in this brief tutorial.
Firstly, I want you to make room between { and system("PAUSE"); for you to work do not delete anything just press enter. (if you do delete something press ctrl+z)
Now in this space you have just made type:
cout << "This is a test of the emergency broadcast system!";
your code should now look like VA-03
VA-03:
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
cout << "This is a test of the emergency broadcast system!";
system("PAUSE");
return EXIT_SUCCESS;
}
your output should look like VA-04:
VA-04:
http://img294.imageshack.us/my.php?image=section1step6wc0.gif
This looks wrong, right? The text runs into your "Press any key to continue" right? You have to add a new line or the technical term would be a line feed. C++ recognizes this as '\n'
so lets try this again with a new string and a line feed.
Will continu on part 2....
Credits for Kozical!
Tools required:
DevCpp (Free C++ compilation environment. I recommend it for beginners with no money) you can download that here http://www.bloodshed.net/devcpp.html
One moderately intelligent fellow
At least a few hours to spare.
Alright we'll start small with a few examples of a console application.
Firstly open up DevCpp after you have downloaded and installed it.
---
Step 1: Open DevCpp then proceed to File (alt+f) -> New (alt+n) -> Project (alt+p)
Step 2: At this point you will see a photo that resembles (VA-01)
VA-01:
http://img407.imageshack.us/my.php?image=section1step2ux9.gif
Step 2 (continued): Select Console Application and then name your project Day1Project1
Step 3: Save your .dev (project file) to a location in which you feel comfortable keeping your c++ files.
Step 4: Right from the start DevCpp will equip you with a working application containing the code in VA-02 (below); at this point you can proceed to goto Execute (alt+x) -> Compile & Run (F9)
(note: this will ask you to save main.cpp just save it wherever you saved your Day1Project1.dev (project file) )
VA-02:
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
system("PAUSE");
return EXIT_SUCCESS;
}
Step 5: When this application runs it will appear blank and ask you to press any key to continue. This is a console application in action. However we want a more complex application so we will continue on. Now press a key to exit and go back to your code. I will go ahead and explain what each part does.
-
In C++ there are many types of data this you'll learn over and over again. All of which can be converted back to digits but we are nowhere near that far at this point. So I will explain some more about these 'types'.
In the code displayed you will see int and char. int as you may have guessed stands for integer integer is a number. So you may put only numbers into an integer variable. Example: int nTest = 1; You may safely say that nTest is equal to 1 now. Now char on the other hand stands for character which in this case we will only use ASCII characters. Example: char cTest = 'K'; Now as you may have guessed cTest is equal to K. Notice I added ' and ' around my character this signifies to the compiler that this is a character and not an integer.
In the coming exercises we will use these a lot but we still have not covered all the material given in your code. #include as you may have guessed includes another file to your current code. We will cover this more as we progress as of right now we're keeping this simple. int main(int argc, char *argv[]) is the main function of your code anything done in this function will directly effect how your program works. That being said anything not done in this function will directly effect how your program works. If you add nothing to main 's function then your program will do nothing.
We will cover two more things and progress to our first exercise. using namespace std; we will cover this in other projects but I will say that the namespace keyword lets you partition an application into multiple subsystems. system("PAUSE"); this will stop your application from continuing and will send the message "Press any key to continue.." As you saw before when you compiled and ran the program.
Step 6:
In this step we will be working with the function cout which is basically an echo function for those of you who have used mIRC, php, perl, or any other coding/scripting languages. What this does it output characters to the console and that kind of works well with the name. There are several of these functions in C++ in which I will cover in this brief tutorial.
Firstly, I want you to make room between { and system("PAUSE"); for you to work do not delete anything just press enter. (if you do delete something press ctrl+z)
Now in this space you have just made type:
cout << "This is a test of the emergency broadcast system!";
your code should now look like VA-03
VA-03:
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
cout << "This is a test of the emergency broadcast system!";
system("PAUSE");
return EXIT_SUCCESS;
}
your output should look like VA-04:
VA-04:
http://img294.imageshack.us/my.php?image=section1step6wc0.gif
This looks wrong, right? The text runs into your "Press any key to continue" right? You have to add a new line or the technical term would be a line feed. C++ recognizes this as '\n'
so lets try this again with a new string and a line feed.
Will continu on part 2....
Credits for Kozical!