Search for notes by fellow students, in your own course and all over the country.

Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.

My Basket

You have nothing in your shopping cart yet.

Title: Control structure-All about selection and iteration statements
Description: It contains info on control structure, selection,iteration statements etc in C++ programming.It can be studied by 1st year beginner or anyone with decent computer knowledge.

Document Preview

Extracts from the notes are below, to see the PDF you'll receive please use the links above


3
...
2 The if…else Selection Statement
If student’s grade is greater than or equal to 60
Print “Passed”
else
Print “Failed”
prints Passed if the student’s grade is greater than or equal to 60 and Failed if the student’s grade is less
than 60
...
The conditional operator is C’s
only ternary operator—it takes three operands
...
1
...


3
...
4 Switch statement
[REF: https://www
...
org/switch-statement-cc/]
switch (n)
{
case 1: // code to be executed if n = 1;
break;
case 2: // code to be executed if n = 2;
break;
default: // code to be executed if n doesn't match any cases
}

Important Points about Switch Case Statements:










The expression provided in the switch should result in a constant value otherwise it would not be
valid
...

Duplicate case values are not allowed
...

The break statement is used inside the switch to terminate a statement sequence
...

The break statement is optional
...
The flow of
control will fall through to subsequent cases until a break is reached
...
However nested switch statements should be avoided as it makes program more
complex and less readable
...
The position of default doesn’t matter, it is still
executed if no match found
...
h>
int main()
{
int x;
printf("Enter your choice \n");
scanf("%d",&x);
switch (x)
{
case 1: printf("Choice is 1");
break;
case 2: printf("Choice is 2");
break;
case 3: printf("Choice is 3");
break;
default: printf("Choice other than 1, 2 and 3");
break;
}
return 0;
}

3
...
2
...
The pseudocode statement
While there are more items on my shopping list
Purchase next item and cross it off my list
The condition, “there are more items on my shopping list” may be true or false
...
This action will be performed repeatedly while the
condition remains true
...
h>
int main( void )
{
unsigned int counter;
int grade;
int total;
float average;
total = 0;
counter = 1;

// function main begins program execution
// number of grade to be entered next
// grade value
// sum of grades entered by user
// average of grades
// initialize total
// initialize loop counter

while (counter <= 5 ) {
printf( "%s", "Enter grade: " );
scanf( "%d", &grade );
total = total + grade;
counter = counter + 1;
}
// end while

}

// loop 10 times
// prompt for input
// read grade from user
// add grade to total
// increment counter

average = total / counter; // integer division
printf( "Class average is %
...
0



The above can be upgraded like this
while ( ++counter <= 10 )



The above program can be updated by replaing the condition of while statement as
while (grade != -1)
Now, the lop will repeat until the grade entered by user is -1 in the previous iteration
...
2f\n", 3
...
45
printf( "%
...
446 ); // prints 3
...
2
...
geeksforgeeks
...

#include ...

for ( j = x; j <= 4 * x * y; j += y / x ) { }



If the body contains ony single statement, curly bases can be removed
for ( j = x; j <= 4 * x * y; j += y / x )
printf(“Hello”);

Another example:
#include ...
2
...
Therefore, the
loop body will be executed at least once
...
h>
int main( void )
{
unsigned int counter = 1;
do {
printf( "%u ", counter );
} while ( ++counter <= 10 );
}

// initialize counter
// display counter
// end do
...
3 Jump statements
3
...
1 break statement
The break statement, when executed in a while, for, do…while or switch statement, causes an immediate exit from
that statement
...


#include ...
3
...
In while and do…while
statements, the loop-continuation test is evaluated immediately after the continue statement is executed
...

Example:
#include ...
3
...

This statement does not mandatorily need any conditional statements
...
The return statement may or may not return anything for a void function, but for a
non-void function, a return value is must be returned
...
geeksforgeeks
...
3
...
A label is an identifier followed by a colon
...


Example:

#include ...
A logic error has its effect at execution time
...
A nonfatal logic error allows a program to continue
executing but to produce incorrect results
...
Constants are said to be rvalues (for “right values”) because they can be used on only
the right side of an assignment operator
...


L-value: “l-value” refers to memory location which identifies an object
...
l-value often represents as
identifier
...
A r-value is an
expression that can’t have a value assigned to it which means r-value can appear on right but
not on left hand side of an assignment operator(=)
...
e
...

rvalues are defined by exclusion
...



Title: Control structure-All about selection and iteration statements
Description: It contains info on control structure, selection,iteration statements etc in C++ programming.It can be studied by 1st year beginner or anyone with decent computer knowledge.