Search the Community
Showing results for tags 'introduction'.
Found 1 result
-
Well I guess I'm now here to share my process from a know nothing to a master Jedi, what wrong movie oh, sorry I meant from a beginner to a decent programmer and beyond. Lets start off by saying I am by no means an expert nor am I here to teach, if by some miracle someone learns something from me then great, if someone is inspired to learn a programming language by this then fantastic, if someone wishes to hunt me down and punch me in the face for this then wonderful just as long as you let me know your coming first. This would be a good time to note, computers are smart but at the same time computers are stupid, a computer can do anything you want it to do, if you want a computer to wipe your rear then you design and build a robot arm and then write a program to execute and make the robot arm do so, this would of course be uncomfortable and pointless but still possible. I'd also like to add that I am using Visual Studio 2010 Ultimate edition. I guess now is a good a time to start as any, I'll start off by introducing the new concepts and then add some code making use of said concepts, the majority of these will be console applications so no fancy GUI for anyone yet. New concepts: Comments | something every programmer needs doesn't do anything other than make the code easier to understand and read, not really a new concept but still worth mentioning. Comments are made using // or long comments can be placed between /* and */ #include | using the #include directive I can specify to use one of the libraries. One specific and common example would be #include <iostream> which includes the standard library used for I/O or input/output. using | using allows me to specify which namespace or even just commands within the namespace to use. For example using namespace std; would allow me access to the standard namespace where the <iostream> resides, I could also specify using std::cin; or using std::cout; to specify using cin and cout input and output commands found in <iostream>. functions | functions like the int main() are blocks of code within which I can preform different tasks and usually return a value. cin | cout | I feel it to be appropriate to mention these two together cin is the standard input command used to get input from the user, where as cout is the standard output command used to display output such as text. variables | I'm sure you saw that one coming, yes variables. A variable is data stored in memory that the computer can access at a later time, there are different kinds of variables such as constants, local variables, and global variables, I'm sure I'm forgetting something. There are also different "types" of variables variables can be any kind of data so it is necessary to specify the data type, be it integers, floats, strings, or bool (I'll say more on these another time just to save time. Well I think that is enough new concepts for this time it's now time to write some code, the code written on here will be done using italics as you may have noticed to set it apart from the rest. The program that I will be writing will be a simple console program that will ask for a user's name store it in a variable and then display "Hello" and the name stored in the variable. 1 // Hello User a first look into programming 2 // 3 4 #include <iostream> 5 6 using std::cin; 7 using std::cout; 8 using std::endl; 9 10 int main() 11 { 12 const int MAX (20); 13 char name [MAX]; 14 15 cout << "Please enter a name: "; 16 cin.getline (name, MAX, '\n'); 17 18 cout << "Hello " << name << endl; 19 20 return 0; 21 } That's all there is to it I will go through it line by line however. The first two lines are comment lines where you can really put anything you want. The fourth line specifies to use the <iostream> library. The sixth, seventh, and eighth lines specify commands that I intend to use from the standard namespace. The 10th line declares the main function and the 11th and 21th lines are the opening and closing brackets of the main function, all code between then is part of the main function. The 12th line declares a constant with the integer type named MAX and is set to 20 The 13th line declares a char using the name name that hold the value of MAX. This method of calling strings uses arrays and is more advanced than this introduction covers. The 15th line is an output statement that displays the text "Please enter a name: " to prompt the user for input. The 16th line is an input statement that takes input from the user and stores it in name. The 18th line outputs the text "Hello " and then the data stored in name, then moves to the end line statement endl. The 20th line returns the value of 0 to the function main and closes the program. Please to anyone who knows more about this stuff than me please share if you have a better way of doing something that I've shown here or if I made a mistake anywhere.
-
- programing
- c++
-
(and 5 more)
Tagged with: