This is a discussion on VC++ A Short Cut - tutorial within the C and C++ Programming forums, part of the Software Development category; VC++ Short cut method Hi...friends... Here I have started this thread for basic level programmers to learn VC++ in ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| VC++ Short cut method Hi...friends... Here I have started this thread for basic level programmers to learn VC++ in a short manner. Its very hard to learn VC++ one by one tutorial. Learn by tutorial is not the easy way to learn all the features in vc++. Here I have given a real time project methodology that will help you to learn all the features in vc++. We will start from the first project work. All you need is ... VC++ 6.0 MSDN Local or online help. Projects 1 - Fundamentals of Programming Language C++ is a different breed of programming language. A C++ program begins with a function, a collection of commands that do something. The function that begins a C++ program is called main. From main, we can also call other functions whether they are written by us or by others. To access a standard function that comes with the compiler, you include a header with the #include directive. What this does is take everything in the header and paste it into your program. Let's look at a working program: #include <iostream> The #include is a preprocessor directive that tells the compiler to put code from the header called iostream into our program. By including header files, you can gain access to many different functions. For example, the cout function requires iostream. Here are some variable declaration examples: int x; While you can have multiple variables of the same type, you cannot have multiple variables with the same name. Moreover, you cannot have variables and functions with the same name. a = 4 * 6; // (Note use of comments and of semicolon) a is 24 The other form of equal, ==, is not a way to assign a value to a variable. Rather, it checks to see if the variables are equal. It is useful in other areas of C++; for example, you will often use == in such constructions as conditional statements and loops. You can probably guess how < and > function. They are greater than and less than operators.to be contnd... thanks
__________________ Karpagarajan. R Necessity is the mother of invention Last edited by Karpagarajan : 04-02-2007 at 03:10 AM. |
| Sponsored Links |
| |||
| PART 2 Here are the relational operators, as they are known, along with examples: > greater than 5 > 4 is TRUEIt is highly probable that you have seen these before, probably with slightly different symbols. They should not present any hindrance to understanding. Now that you understand TRUE and FALSE in computer terminology as well as the comparison operators, let us look at the actual structure of if statements. The structure of an if statement is as follows: if ( TRUE )To have more than one statement execute after an if statement that evaluates to true, use braces, like we did with the body of a function. Anything inside braces is called a compound statement, or a block. For example: if ( TRUE ) {There is also the else statement. The code after it (whether a single line or code between brackets) is executed if the if statement is FALSE. Try some of these - they're not too hard. If you have questions about them, feel free to stop by our forums. A. !( 1 || 0 ) ANSWER: 0FOR - for loops are the most useful type. The layout is The variable initialization allows you to either declare a variable and give it a value or give a value to an already existing variable. Second, the condition tells the program that while the conditional expression is true the loop should continue to repeat itself. The variable update section is the easiest way for a for loop to handle changing of the variable. It is possible to do things like x++, x = x + 10, or even x = random ( 5 ), and if you really wanted to, you could call other functions that do nothing to the variable but still have a useful effect on the code. Notice that a semicolon separates each of these sections, that is important. Also note that every single one of the sections may be empty, though the semicolons still have to be there. If the condition is empty, it is evaluated as true and the loop will repeat until something else stops it. WHILE - WHILE loops are very simple. The basic structure is while ( condition )The true represents a boolean expression which could be x == 1 or while ( x != 7 ) (x does not equal 7). It can be any combination of boolean statements that are legal. Even, (while x = =5 || v == 7) which says execute the code while x equals five or while v equals 7. Notice that a while loop is the same as a for loop without the initialization and update sections. However, an empty condition is not legal for a while loop as it is with a for loop. Example: #include <iostream>This was another simple example, but it is longer than the above FOR loop. The easiest way to think of the loop is that when it reaches the brace at the end it jumps back up to the beginning of the loop, which checks the condition again and decides whether to repeat the block another time, or stop and move to the next statement after the block. DO..WHILE - DO..WHILE loops are useful for things that want to loop at least once. The structure is do {Notice that the condition is tested at the end of the block instead of the beginning, so the block will be executed at least once. If the condition is true, we jump back to the beginning of the block and execute it again. A do..while loop is basically a reversed while loop. A while loop says "Loop while the condition is true, and execute this block of code", a do..while loop says "Execute this block of code, and loop while the condition is true". to be condn... ![]()
__________________ Karpagarajan. R Necessity is the mother of invention |
| |||
| PART 3 Functions that a programmer writes will generally require a prototype. Just like a blueprint, the prototype tells the compiler what the function will return, what the function will be called, as well as what arguments the function can be passed. When I say that the function returns a value, I mean that the function can be used in the same manner as a variable would be. For example, a variable can be set equal to a function that returns a value between zero and four. For example: #include <cstdlib> // Include rand() using namespace std; // Make rand() visible int a = rand(); // rand is a standard function that all compilers have Do not think that 'a' will change at random, it will be set to the value returned when the function is called, but it will not change again. The general format for a prototype is simple: return-type function_name ( arg_type arg1, ..., arg_type argN ); There can be more than one argument passed to a function or none at all (where the parentheses are empty), and it does not have to return a value. Functions that do not return values have a return type of void. Lets look at a function prototype: int mult ( int x, int y ); This prototype specifies that the function mult will accept two arguments, both integers, and that it will return an integer. Do not forget the trailing semi-colon. Without it, the compiler will probably think that you are trying to write the actual definition of the function. Switch case statements are a substitute for long if statements that compare to an integral value. The basic format for using switch case is outlined below. switch ( value ) { case this: Code to execute if value == this break; case that: Code to execute if value == that break; ... default: Code to execute if value != this or that break; } The condition of a switch statement is a value. The case says that if it has the value of whatever is after that case then do whatever follows the colon. The break is used to break out of the case statements. Break is a keyword that breaks out of the code block, usually surrounded by braces, which it is in. In this case, break prevents the program from falling through and executing the code in all the other case statements. An important thing to note about the switch statement is that the case values may only be constant integral expressions. Sadly, it isn't legal to use case like this: int a = 10; int b = 10; int c = 20; switch ( a ) { case b: // Code break; case c: // Code break; default: // Code break; } The default case is optional, but it is wise to include it as it handles any unexpected cases. Switch statements serves as a simple way to write long if statements when the requirements are met. Often it can be used to process input from a user. to be contnd... ![]() thanks
__________________ Karpagarajan. R Necessity is the mother of invention |
| |||
| PART 4 In order to have a pointer actually point to another variable it is necessary to have the memory address of that variable also. To get the memory address of the variable, put the & sign in front of the variable name. This makes it give its address. This is called the address operator, because it returns the memory address. For example: #include <iostream> using namespace std; int main() { int x; // A normal integer int *p; // A pointer to an integer p = &x; // Read it, "assign the address of x to p" cin>> x; // Put a value in x, we could also use *p here cin.ignore(); cout<< *p <<"\n"; // Note the use of the * to get the value cin.get(); } The cout outputs the value in x. Why is that? Well, look at the code. The integer is called x. A pointer to an integer is then defined as p. Then it stores the memory location of x in pointer by using the address operator (&). If you wish, you can think of it as if the jar that had the integer had a ampersand in it then it would output its name (in pointers, the memory address) Then the user inputs the value for x. Then the cout uses the * to put the value stored in the memory location of pointer. If the jar with the name of the other jar in it had a * in front of it would give the value stored in the jar with the same name as the one in the jar with the name. It is not too hard, the * gives the value in the location. The unasterisked gives the memory location. to be contnd... ![]()
__________________ Karpagarajan. R Necessity is the mother of invention |
| |||
| File I/O File I/O is reading from and writing to files. This lesson will only cover text files, that is, files that are composed only of ASCII text. C++ has two basic classes to handle files, ifstream and ofstream. To use them, include the header file fstream. Ifstream handles file input (reading from files), and ofstream handles file output (writing to files). The way to declare an instance of the ifstream or ofstream class is: ifstream a_file;or ifstream a_file ( "filename" );The constructor for both classes will actually open the file if you pass the name as an argument. As well, both classes have an open command (a_file.open()) and a close command (a_file.close()). You aren't required to use the close command as it will automatically be called when the program terminates, but if you need to close the file long before the program ends, it is useful. The beauty of the C++ method of handling files rests in the simplicity of the actual functions used in basic input and output operations. Because C++ supports overloading operators, it is possible to use << and >> in front of the instance of the class as if it were cout or cin. In fact, file streams can be used exactly the same as cout and cin after they are opened. For example: #include <fstream>The default mode for opening a file with ofstream's constructor is to create it if it does not exist, or delete everything in it if something does exist in it. If necessary, you can give a second argument that specifies how the file should be handled. They are listed below: ios::app -- Append to the fileFor example: ofstream a_file ( "test.txt", ios::app );This will open the file without destroying the current contents and allow you to append new data. When opening files, be very careful not to use them if the file could not be opened. This can be tested for very easily: ifstream a_file ( "example.txt" );......... bye thanks ![]()
__________________ Karpagarajan. R Necessity is the mother of invention |
![]() |
| Thread Tools | |
| Display Modes | |
| |
LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/c-c-programming/910-vc-short-cut-tutorial.html | |||
| Posted By | For | Type | Date |
| Digg - VC++ A Short Cut - tutorial | This thread | Refback | 07-20-2007 03:20 AM |
| Digg / News / Upcoming | This thread | Refback | 07-20-2007 03:06 AM |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| short cut command in windows run? | saravanan | Operating Systems | 0 | 03-23-2008 10:16 PM |
| How use the short cuts for button in Flash | arunsamini | Flash Actionscript Programming | 2 | 02-24-2008 09:47 PM |
| Short Cut 2 success | Sabari | The Lounge | 0 | 09-04-2007 07:51 AM |
| Keyboard short cuts of PhotoShop CS2 | PixelNameVj | Web Design Help | 1 | 07-30-2007 10:34 AM |
| COM - The Short Explanation | Karpagarajan | C and C++ Programming | 0 | 04-10-2007 09:52 AM |