User-submitted CPP Projects

115
3002 reads

February 1, 2012

The for loop


Its format is:

for (initialization; condition; increase) statement;

and its main function is to repeat statement while condition remains true, like the while loop.

115
2962 reads

February 1, 2012

The do-while loop


The do-while loop

Its format is:

do statement while (condition);

Its functionality is exactly the same as the while loop, except that condition in the do-while loop is evaluated after the exe

108
3048 reads

February 1, 2012

The while loop


Iteration structures (loops)

Loops have as purpose to repeat a statement a certain number of times or while a condition is fulfilled.

The while loop
Its format is:

while (expression) stateme

145
3184 reads

February 1, 2012

Conditional structure1


Conditional structure: if and else
The if keyword is used to execute a statement or block only if a condition is fulfilled.

124
3292 reads

February 1, 2012

Conditional structure


if and else
The if keyword is used to execute a statement or block only if a condition is fulfilled.

53
2198 reads
stringstream

stringstream
The standard header file defines a class called stringstream that allows a string-based object to be treated as a stream.


Run It Now!
108
1861 reads

February 1, 2012

cin and strings


cin and strings
We can use cin to get strings with the extraction operator (>>) as we do with fundamental data type variables:

cin >> mystring;

However, as it has been said, cin extractio

161
1785 reads

February 1, 2012

Standard Input (cin)


The standard input device is usually the keyboard. Handling the standard input in C++ is done by applying the overloaded operator of extraction (>>) on the cin stream.

109
1788 reads

February 1, 2012

Basic Output


Until now, the example programs of previous sections provided very little interaction with the user, if any at all.

110
2876 reads

February 1, 2012

Conditional operator


Conditional operator ( ? )

The conditional operator evaluates an expression returning a value if that expression is true and a different one if the expression is evaluated as false.