Friday, 9 March 2012

The for Statement in C++

The for statement is typically used to count a number of items. At its regular structure, it is divided in three parts. The first section specifies the starting point for the count. The second section sets the counting limit. The last section determines the counting frequency. The syntax of the for statement is: for( Start; End; Frequency) Statement; The Start expression is a variable assigned the starting value. This could be Count = 0;The End expression sets the criteria for ending the counting. An example would be Count < 24; this means the counting would continue as long as the Count variable is less than 24. When the count is about to rich 24, because in this case 24 is excluded, the counting would...

The do...while Statements in C++

The do…while statement uses the following syntax: do Statement while (Condition); The do…while condition executes a Statement first. After the first execution of the Statement, it examines the Condition. If the Condition is true, then it executes the Statement again. It will keep executing the Statement AS LONG AS the Condition is true. Once the Condition becomes false, the looping (the execution of the Statement) would stop. If the Statement is a short one, such as made of one line, simply write it after the do keyword. Like the if and the while statements, the Condition being checked must be included between...

The While Statements in C++

The while statement examines or evaluates a condition. The syntax of the while statement is: while(Condition) Statement; To execute this expression, the compiler first examines the Condition. If the Condition is true, then it executes the Statement. After executing the Statement, the Condition is checked again. AS LONG AS the Condition is true, it will keep executing the Statement. When or once the Condition becomes false, it exits the loop. Here is an example: int Number; while( Number <= 12 ) { cout << "Number " << Number << endl; Number++; } To effectively execute a while condition, you should make sure you provide...

The Switch Statements in C++

Good Afternoon Readers, Today we will discuss about the switch statement. When defining an expression whose result would lead to a specific program execution, the switch statement considers that result and executes a statement based on the possible outcome of that expression, this possible outcome is called a case. The different outcomes are listed in the body of the switch statement and each case has its own execution, if necessary. The body of a switch statement is delimited from an opening to a closing curly brackets: “{“ to “}”. The syntax of the switch statement is:        switch(Expression){    case Choice1:        Statement1;   ...

Conditional Statements in C++

Now we can  move to conditional statements in C++. Today we can learn about the conditional statements "if  & if else". When programming, you will ask the computer to check various kinds of situations and to act accordingly. The computer performs various comparisons of various kinds of statements. These statements come either from you or from the computer itself, while it is processing internal assignments. Let’s imagine you are writing an online survey and one question would be, "whats your martial status?" The source file of such a program would look like this: #include <iostream> void main() { char Answer; cout << "Whats your martial stats? "; cin >> Answer; getch(); } Some of...

C++ Practice A-3

Hi,             How are you? I was busy with my some assignments for last week.So what about your home work? Did you try the exercises that I given in the last post? I am giving the syntax of that exercise below. Subtraction / multiplication / division with three numbers.(read &print)  Subtraction --------------- #include<iostream.h>#include<conio.h>void main(){ int a,b,sum; clrscr(); cout<<"Enter First Number :"; cin>>a; cout<<"Enter Second Number : "; cin>>b; sum=a-b; cout<<"Sum :"; cout<<sum; getch();} --------------- For multiplication and division you only need to change the line -   sum=a-b;   to- sum=a*b;...

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Web Hosting Coupons