IT Community - Software Programming, Web Development and Technical Support

VC++ A Short Cut - tutorial

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 ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C and C++ Programming

Register FAQ Members List Calendar Mark Forums Read
  2 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 04-02-2007, 03:06 AM
Karpagarajan Karpagarajan is offline
D-Web Analyst
 
Join Date: Mar 2007
Posts: 299
Karpagarajan is on a distinguished road
Thumbs up VC++ A Short Cut - tutorial

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>

using namespace std;

int main()
{
cout<<"HEY, you, I'm alive! Oh, and Hello World!\n";
cin.get();
}
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.

The next imporant line is int main(). This line tells the compiler that there is a function named main, and that the function returns an integer, hence int. The braces ({ and }) signal the beginning and end of functions and other code blocks. If you have programmed in Pascal, you will know them as BEGIN and END.

In C++, however, the cout function is used to display text. It uses the << symbols, known as insertion operators. The quotes tell the compiler that you want to output the literal string as-is. The \n is actually one character that stands for a newline. It moves the cursor on your screen to the next line. The semicolon is added onto the end of all function calls in C++. You will see later that the semicolon is used to end most commands in C++.

The next command is cin.get(). This is another function call that expects the user to hit the return key.
Here are some variable declaration examples:
int x;
int a, b, c, d;
char letter;
float the_float;
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.

Here are a few examples:
a = 4 * 6; // (Note use of comments and of semicolon) a is 24
a = a + 5; // a equals the original value of a with five added to it
a == 5 // Does NOT assign five to a. Rather, it checks to see if a equals 5.
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.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-19-2007, 05:28 AM
Karpagarajan Karpagarajan is offline
D-Web Analyst
 
Join Date: Mar 2007
Posts: 299
Karpagarajan is on a distinguished road
Default Re: VC++ A Short Cut - tutorial

PART 2
Here are the relational operators, as they are known, along with examples:
> greater than 5 > 4 is TRUE
< less than 4 < 5 is TRUE
>= greater than or equal 4 >= 4 is TRUE
<= less than or equal 3 <= 4 is TRUE
== equal to 5 == 5 is TRUE
!= not equal to 5 != 4 is TRUE
It 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 )
Execute the next statement
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 ) {
Execute all statements inside the braces
}
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: 0
B. !( 1 || 1 && 0 ) ANSWER: 0 (AND is evaluated before OR)
C. !( ( 1 || 0 ) && 0 ) ANSWER: 1 (Parenthesis are useful)
FOR - for loops are the most useful type. The layout is

for ( variable initialization; condition; variable update ) {
Code to execute while the condition is true
}
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 )
{ Code to execute while the condition is true }
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>

using namespace std; // So we can see cout and endl

int main()
{
int x = 0; // Don't forget to declare variables

while ( x < 10 ) { // While x is less than 10
cout<< x <<endl;
x++; // Update x so the condition can be met eventually
}
cin.get();
}
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 {
} while ( condition );
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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-16-2007, 08:04 AM
Karpagarajan Karpagarajan is offline
D-Web Analyst
 
Join Date: Mar 2007
Posts: 299
Karpagarajan is on a distinguished road
Smile Re: VC++ A Short Cut - tutorial

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-17-2007, 12:41 AM
Karpagarajan Karpagarajan is offline
D-Web Analyst
 
Join Date: Mar 2007
Posts: 299
Karpagarajan is on a distinguished road
Smile Re: VC++ A Short Cut - tutorial

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-17-2007, 12:54 AM
prasath prasath is offline
D-Web Sr.Programmer
 
Join Date: Jul 2007
Location: Chennai
Posts: 173
prasath is on a distinguished road
Smile Re: VC++ A Short Cut - tutorial

Hi
Thanks,it should attract the beginners in VC++


cheers,
Prasath.K
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 08-02-2007, 06:28 AM
Karpagarajan Karpagarajan is offline
D-Web Analyst
 
Join Date: Mar 2007
Posts: 299
Karpagarajan is on a distinguished road
Thumbs up Re: VC++ A Short Cut - tutorial

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>
#include <iostream>

using namespace std;
int main()
{
char str[10];

//Creates an instance of ofstream, and opens example.txt
ofstream a_file ( "example.txt" );
// Outputs to example.txt through a_file
a_file<<"This text will now be inside of example.txt";
// Close the file stream explicitly
a_file.close();
//Opens for reading the file
ifstream b_file ( "example.txt" );
//Reads one string from the file
b_file>> str;
//Should output 'this'
cout<< str <<"\n";
// b_file is closed implicitly here
}
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 file
ios::ate -- Set the current position to the end
ios::trunc -- Delete everything in the file
For 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" );

if ( !a_file.is_open() ) {
// The file could not be opened
}
else {
// Safely use the file stream
}
.........
bye
thanks
__________________
Karpagarajan. R
Necessity is the mother of invention
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT -7. The time now is 04:47 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0