j

    Sunday, 13 December 2015

    what is if-else-if Statement



    if-else-if Statement
    if-else-if statement can be used to choose one block of statements from multiple statements. It is used when there are many options and only one block of statements should be executed on the basis of a condition.
    Syntax:
    if(condition)
    {
    Block 1;
    }
    else if(condition)
    {
    Block 2;
    }
    else if(condition)
    {
    Block 3
    }
    .
    .
    else
    {
    Block N;
    }

      
    Write a program that input choice 1 to 7 if user enter 1 then display Sunday , if enter 2 Monday and so on
    #include<iostream.h>
    #include<conio.h>
    void main()
    {
    clrscr();
    int ch;
    cout<<"Enter your Choice 1 to 7 :";
    cin>>ch;
    if(ch==1)
    cout<<"Sunday";
    else if(ch==2)
    cout<<"Monday";
    else if(ch==3)
    cout<<"Tuesday";
    else if(ch==4)
    cout<<"Wednesday";
    else if(ch==5)
    cout<<"Thirsday";
    else if(ch==6)
    cout<<"Friday";
    else if(ch==7)
    cout<<"Saturday";
    else
    cout<<"Invalid Input!";
    getch();
    }
     

    What is Relational Operators ?

    Relational Operators
                    The relational operators are used to specify conditions in the programs. A relational operator compares two values. It produces result as true of false. The relational operators are sometimes called conditional operators or comparison operators as they test conditions that are either true or false. C++ provides the following relational operators.
    Operators
    Description
    Greater than operators returns true if the value if left side of > is greater than the value of right side. Otherwise returns false
    <
    Less than operators returns true if the value of left side of < is less than the value of right side. Otherwise return false
    ==
    Equal to operators returns true if the values if both sides is equal. Otherwise return false
    >=
    Greater than or equal to operators returns true if the value on left side of >= is greater than or equal to the value of right side. Otherwise returns false
    <=
    Less than or equal to operators returns true if the value on left side of <= is less than or equal to the value of right side. Otherwise returns false.
    !=
    The not equal to operators returns true if the value on left side of! = is not equal to the value on right side. Otherwise returns false


    What is Control Structure define the types of control structure.




     

    Control Structure


                    A statement used to control the flow of execution in a program is called control structure. The instructions in a program can be organized in three kinds of control structures to control execution flow. The control structure is used to implement the program logic.
    Types of Control Structure
                Different types of control structure are as follows:
    Sequence
    In sequential structure, the statements are executed in the same order in which they are specified in program. The control flows from one statement to other statement in logical sequence. All statement is executed exactly once. It means that no statement is skipped and no statement is executed more that once
    Example
                    Suppose a program inputs two numbers and displays average on screen. The program uses two statements to input numbers, one statement to calculate average and one statement to display average number. These statements are executed in a sequence to find the average number. All statements are executed once when the program is executed. It is an example of sequence control structure.

    Selection
                    A selection structure selects a statement or set of statements to execute on the basis of a condition. In this structure, statement or set of statement is executed when a particular condition is true and ignored when the condition is false. There are different types of selection structure in C++ these are if….else and switch.
    Example
                    Suppose a program inputs the marks of a student and displays a message on screen whether the student is pass or fail. It displays pass if the student gets 40 or more then 40 marks. It displays fail when the marks are below 40. The program checks the marks before displaying the message. It is an example of selection structure.

    Repetition
                A repetition structure executes a statement or set of statements repeatedly. It is also known as iteration structure or loop. There are different types of repetition structure in C++. These are while, do while and for.       
    Example
                    Suppose we want to display a Name “Umair Jatoi” on screen for 100 times. It is time consumi9ng to perform this task using control sequence; however, it is very easy to perform this task using repetition structure. A single loop statement can display the message for 100 times.


    Function call
                    Function call is a type of statement that moves the control to another block of a code the control returns back after executing all statement in the block. The remaining statement are executed immediately after the function call when the control returned