-- Learning C++ -- - Page 2
You are Unregistered, please register to gain Full access.    
Desi Forums   


Go Back   Desi Forums > Ray Of Light > Tech Talk > Tutorials Cafe

Notices

-- Learning C++ --

  Discuss -- Learning C++ -- at the Tutorials Cafe; Did anybody take time to have a read ?...

Reply
 

 
Thread Tools
  #16 (permalink)  
Old 07-07-2007, 04:43 PM
mytonse's Avatar
Exorbitant
Location: India
Gender:
Visit mytonse's Blog
 
Join Date: Dec 2005
Age: 19
Posts: 3,368
Credits: 35,706
mytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of light
Send a message via MSN to mytonse Send a message via Yahoo to mytonse Send a message via Skype™ to mytonse
Did anybody take time to have a read ?
Reply With Quote
Sponsored Links
  #17 (permalink)  
Old 07-11-2007, 10:20 PM
RAHEN's Avatar
Team leader
Location: United Arab Emirates
Gender:
Visit RAHEN's Blog
 
Join Date: Apr 2006
Age: 24
Posts: 36,378
Credits: 363,866
RAHEN is a splendid one to beholdRAHEN is a splendid one to beholdRAHEN is a splendid one to beholdRAHEN is a splendid one to beholdRAHEN is a splendid one to beholdRAHEN is a splendid one to behold
Welldone yunus...u hve done a great job..keep it up...

hmm..i m stuck here...

Quote:
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.
^ plz explain this one
Reply With Quote
  #18 (permalink)  
Old 07-12-2007, 04:14 PM
AaDi's Avatar
Premium Member
Location: United Kingdom
Gender:
Visit AaDi's Blog
 
Join Date: Nov 2005
Age: 24
Posts: 1,926
Credits: 8,135
AaDi is a jewel in the roughAaDi is a jewel in the roughAaDi is a jewel in the roughAaDi is a jewel in the rough
@Rahen ..

Let me explain a bit .. in C++ when you define any variable (a memory location), you have to tell what will you store in it .. its called that variable's 'Data Type' .. there are a number of data types in C++ (int for storing integers, char for storing a character, etc .. Yunus will be talking about this more later) .. So as I was saying .. each variable has a data type .. now you can declare a variable called 'mynumber' with the integer data type .. now you cannot use the variable name 'mynumber' again (to declare with some other data type). For example:

Code:
   int a;
   char a;    // This is wrong
so the line:
'you can have multiple variables of the same type, you cannot have multiple variables with the same name'
means
you can declare more than one variable of the same data type (i.e. int a, b, c; declares three integer variables) but all the names have to be unique (as I tried to explain above).

The last bit is: you cannot have variables and functions with the same name
Its similar to the last one .. saying if you declare your own function (a piece of code that can be called again when you need it, again Yunus will come to this later) its name (or identifier in techi terms) should be unique .. for example

Code:
   function a() {
      // Some code
   }

   int a;    // This is wrong

@Yunus ..

awesome stuff bro .. I just found da topic name confusing .. I came here to chk out C but found out it was C++ .. and I love the tutorials .. keep up da good work man
Reply With Quote
  #19 (permalink)  
Old 07-13-2007, 12:54 PM
RAHEN's Avatar
Team leader
Location: United Arab Emirates
Gender:
Visit RAHEN's Blog
 
Join Date: Apr 2006
Age: 24
Posts: 36,378
Credits: 363,866
RAHEN is a splendid one to beholdRAHEN is a splendid one to beholdRAHEN is a splendid one to beholdRAHEN is a splendid one to beholdRAHEN is a splendid one to beholdRAHEN is a splendid one to behold
Thank you Aadi...got that point...in simple words...only one work can be assigned to one variable...for the program to function properly...
Reply With Quote
  #20 (permalink)  
Old 07-16-2007, 10:03 AM
mytonse's Avatar
Exorbitant
Location: India
Gender:
Visit mytonse's Blog
 
Join Date: Dec 2005
Age: 19
Posts: 3,368
Credits: 35,706
mytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of light
Send a message via MSN to mytonse Send a message via Yahoo to mytonse Send a message via Skype™ to mytonse
Post

If statements

The ability to control the flow of your program, letting it make decisions on what code to execute, is valuable to the programmer. The if statement allows you to control if a program enters a section of code or not based on whether a given condition is true or false. One of the important functions of the if statement is that it allows the program to select an action based upon the user's input. For example, by using an if statement to check a user entered password, your program can decide whether a user is allowed access to the program.

Without a conditional statement such as the if statement, programs would run almost the exact same way every time. If statements allow the flow of the program to be changed, and so they allow algorithms and more interesting code.

Before discussing the actual structure of the if statement, let us examine the meaning of TRUE and FALSE in computer terminology. A true statement is one that evaluates to a nonzero number. A false statement evaluates to zero. When you perform comparison with the relational operators, the operator will return 1 if the comparison is true, or 0 if the comparison is false. For example, the check 0 == 2 evaluates to 0. The check 2 == 2 evaluates to a 1. If this confuses you, try to use a cout statement to output the result of those various comparisons (for example cout<< ( 2 == 1 )

When programming, the aim of the program will often require the checking of one value stored by a variable against another value to determine whether one is larger, smaller, or equal to the other.

There are a number of operators that allow these checks.

Here are the relational operators, as they are known, along with examples:



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:



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:



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.

It can look like this:



One use for else is if there are two conditional statements that may both evaluate to true, yet you wish only one of the two to have the code block following it to be executed. You can use an else if after the if statement; that way, if the first statement is true, the else if will be ignored, but if the if statement is false, it will then check the condition for the else if statement. If the if statement was true the else statement will not be checked. It is possible to use numerous else if statements.

Let's look at a simple program for you to try out on your own.



Boolean operators allow you to create more complex conditional statements. For example, if you wish to check if a variable is both greater than five and less than ten, you could use the boolean AND to ensure both var > 5 and var < 10 are true. In the following discussion of boolean operators, I will capitalize the boolean operators in order to distinguish them from normal english. The actual C++ operators of equivalent function will be described further into the tutorial - the C++ symbols are not: OR, AND, NOT, although they are of equivalent function.

When using if statements, you will often wish to check multiple different conditions. You must understand the Boolean operators OR, NOT, and AND. The boolean operators function in a similar way to the comparison operators: each returns 0 if evaluates to FALSE or 1 if it evaluates to TRUE.

NOT: The NOT operator accepts one input. If that input is TRUE, it returns FALSE, and if that input is FALSE, it returns TRUE. For example, NOT (1) evalutes to 0, and NOT (0) evalutes to 1. NOT (any number but zero) evaluates to 0. In C and C++ NOT is written as !. NOT is evaluated prior to both AND and OR.

AND: This is another important command. AND returns TRUE if both inputs are TRUE (if 'this' AND 'that' are true). (1) AND (0) would evaluate to zero because one of the inputs is false (both must be TRUE for it to evaluate to TRUE). (1) AND (1) evaluates to 1. (any number but 0) AND (0) evaluates to 0. The AND operator is written && in C++. Do not be confused by thinking it checks equality between numbers: it does not. Keep in mind that the AND operator is evaluated before the OR operator.

OR: Very useful is the OR statement! If either (or both) of the two values it checks are TRUE then it returns TRUE. For example, (1) OR (0) evaluates to 1. (0) OR (0) evaluates to 0. The OR is written as || in C++. Those are the pipe characters. On your keyboard, they may look like a stretched colon. On my computer the pipe shares its key with \. Keep in mind that OR will be evaluated after AND.
It is possible to combine several boolean operators in a single statement; often you will find doing so to be of great value when creating complex expressions for if statements. What is !(1 && 0)? Of course, it would be TRUE. It is true is because 1 && 0 evaluates to 0 and !0 evaluates to TRUE (ie, 1).

Try some of these - they're not too hard. If you have questions about them at DT Helpdesk.

If you find you enjoyed this section, then you might want to look more at Boolean Algebra ,a needed skill tool in C++
Reply With Quote
  #21 (permalink)  
Old 07-22-2007, 12:04 PM
mytonse's Avatar
Exorbitant
Location: India
Gender:
Visit mytonse's Blog
 
Join Date: Dec 2005
Age: 19
Posts: 3,368
Credits: 35,706
mytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of light
Send a message via MSN to mytonse Send a message via Yahoo to mytonse Send a message via Skype™ to mytonse
No doubts is it ?

Everyone's got it right...
Reply With Quote
  #22 (permalink)  
Old 08-23-2007, 05:36 AM
mytonse's Avatar
Exorbitant
Location: India
Gender:
Visit mytonse's Blog
 
Join Date: Dec 2005
Age: 19
Posts: 3,368
Credits: 35,706
mytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of light
Send a message via MSN to mytonse Send a message via Yahoo to mytonse Send a message via Skype™ to mytonse
Class 4

Loops are used to repeat a block of code. Being able to have your program repeatedly execute a block of code is one of the most basic but useful tasks in programming -- many programs or websites that produce extremely complex output (such as a message board) are really only executing a single task many times. (They may be executing a small number of tasks, but in principle, to produce a list of messages only requires repeating the operation of reading in some data and displaying it.) Now, think about what this means: a loop lets you write a very simple statement to produce a significantly greater result simply by repetition.

One Caveat: before going further, you should understand the concept of C++'s true and false, because it will be necessary when working with loops (the conditions are the same as with if statements). There are three types of loops: for, while, and do..while. Each of them has their specific uses. They are all outlined below.

FOR - for loops are the most useful type. The syntax for a for loop is

[Only Registered and Activated Users Can See Links. Click Here To Register...]

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

[Only Registered and Activated Users Can See Links. Click Here To Register...]

This program is a very simple example of a for loop. x is set to zero, while x is less than 10 it calls cout<< x <<endl; and it adds 1 to x until the condition is met. Keep in mind also that the variable is incremented after the code in the loop is run for the first time.

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

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:

[Only Registered and Activated Users Can See Links. Click Here To Register...]

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

[Only Registered and Activated Users Can See Links. Click Here To Register...]

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

Example:

[Only Registered and Activated Users Can See Links. Click Here To Register...]

Keep in mind that you must include a trailing semi-colon after the while in the above example. A common error is to forget that a do..while loop must be terminated with a semicolon (the other loops should not be terminated with a semicolon, adding to the confusion). Notice that this loop will execute once, because it automatically executes before checking the condition.

[Only Registered and Activated Users Can See Links. Click Here To Register...]


Enjy Readin !!
Reply With Quote
  #23 (permalink)  
Old 08-23-2007, 03:19 PM
crazy_guy's Avatar
Evolutionist
Gender:
 
Join Date: Aug 2007
Posts: 126
Credits: 184
crazy_guy is on a distinguished road
r u teacher or what .../???
Reply With Quote
  #24 (permalink)  
Old 08-23-2007, 04:59 PM
mytonse's Avatar
Exorbitant
Location: India
Gender:
Visit mytonse's Blog
 
Join Date: Dec 2005
Age: 19
Posts: 3,368
Credits: 35,706
mytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of light
Send a message via MSN to mytonse Send a message via Yahoo to mytonse Send a message via Skype™ to mytonse
No i am not.I dnt find your question relevant.
Reply With Quote
  #25 (permalink)  
Old 12-19-2007, 12:54 PM
mytonse's Avatar
Exorbitant
Location: India
Gender:
Visit mytonse's Blog
 
Join Date: Dec 2005
Age: 19
Posts: 3,368
Credits: 35,706
mytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of light
Send a message via MSN to mytonse Send a message via Yahoo to mytonse Send a message via Skype™ to mytonse
Can someone direct me as to where i stopped last time..Cant make out..Tuts are ready.
Reply With Quote
  #26 (permalink)  
Old 12-19-2007, 12:54 PM
mytonse's Avatar
Exorbitant
Location: India
Gender:
Visit mytonse's Blog
 
Join Date: Dec 2005
Age: 19
Posts: 3,368
Credits: 35,706
mytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of light
Send a message via MSN to mytonse Send a message via Yahoo to mytonse Send a message via Skype™ to mytonse
Okies..Loops...posting tom.
Reply With Quote
  #27 (permalink)  
Old 12-20-2007, 08:07 PM
RAHEN's Avatar
Team leader
Location: United Arab Emirates
Gender:
Visit RAHEN's Blog
 
Join Date: Apr 2006
Age: 24
Posts: 36,378
Credits: 363,866
RAHEN is a splendid one to beholdRAHEN is a splendid one to beholdRAHEN is a splendid one to beholdRAHEN is a splendid one to beholdRAHEN is a splendid one to beholdRAHEN is a splendid one to behold
sorry h.w incomplete teter
Reply With Quote
  #28 (permalink)  
Old 01-21-2008, 12:58 AM
ViSIoN's Avatar
Exorbitant
Location: United Arab Emirates
Gender:
Visit ViSIoN's Blog
 
Join Date: Jan 2008
Posts: 1,970
Credits: 8,564
ViSIoN is on a distinguished road
nice shearing...
Reply With Quote
  #29 (permalink)  
Old 04-28-2008, 02:31 PM
mytonse's Avatar
Exorbitant
Location: India
Gender:
Visit mytonse's Blog
 
Join Date: Dec 2005
Age: 19
Posts: 3,368
Credits: 35,706
mytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of light
Send a message via MSN to mytonse Send a message via Yahoo to mytonse Send a message via Skype™ to mytonse
My pleasure Vision .More coming up.Sry for any inconvinience cause.
Reply With Quote
  #30 (permalink)  
Old 04-28-2008, 04:37 PM
RAHEN's Avatar
Team leader
Location: United Arab Emirates
Gender:
Visit RAHEN's Blog
 
Join Date: Apr 2006
Age: 24
Posts: 36,378
Credits: 363,866
RAHEN is a splendid one to beholdRAHEN is a splendid one to beholdRAHEN is a splendid one to beholdRAHEN is a splendid one to beholdRAHEN is a splendid one to beholdRAHEN is a splendid one to behold
welcome back yunus...its good to see u ..
yah...now classes will start...
Reply With Quote
Reply

Bookmarks

Tags
c language, computer language, functions, information technology, learn, programming, tutorial, variables


Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post