Condition Statement


 

v  Input Function

The input function allows you to ask a user to type some sort of information into the program and to save that information into a variable that the program can process.

v  Output Function

An output function is a function that an optimization function calls at each iteration of its algorithm. Typically, you use an output function to generate graphical output, record the history of the data the algorithm generates, or halt the algorithm based on the data at the current iteration.

v Cin.get Function

The cin. get() C++ function is used to access the character array. This is a very basic function in the c++ programming language that is used to get input from the user. The cin. get() C++ function also includes the white space characters into it.

v     Cin.ignore Function

The cin. ignore() function is used which is used to ignore or clear one or more characters from the input buffer.

v  Putback Function

The putback() function lets us put the last character extracted from the input stream by the get() function back into the input stream. We will be using both functions with the input stream object cin. Note that the functions get(), peak(), and putback() are members of the istream data type.

v  Peak Function

The peaks function is useful for demonstrating graphics functions, such as contour , mesh , pcolor , and surf 

v     Format Manipulate

 Data Manipulation Meaning: Manipulation of data is the process of manipulating or changing information to make it more organized and readable.


·       ConditionalStatement

 Use if to specify a block of code to be executed, if a specified condition is true. Use else to specify a block of code to be executed, if the same condition is false. Use else if to specify a new condition to test, if the first condition is false.

Ø     Statement#1

·       Get an integer as input from keyboard. Determine whether it is even or odd in nature.

·       Algorithm:-

·       Declare a variable

·       Use the condition of “if else”

·       If (a%2==0) print that variable is even

·       Else variable is odd

Ø      Program:-

#include<iostream>

using namespace std;

int main()

{                   

int a;

cout<<"Enter any number "<<endl;

cin>>a;

if(a%2==0)

cout<<"it is even number";

else

cout<<"it is odd number";

return 0;

} 

Ø     Statement#1:-

·       A company insures its driver in following three cases:

                                           i.            If driver is married

                                         ii.            If driver is unmarried and male and his age >30

                                      iii.            If driver is unmarried and female and her age>25

In all other cases the driver is not insured. Write a program that takes the marital status, gender and age of driver as input from keyboard and determines whether he is insured or not.

 

·       Algorithm:-

o   Declare variables age,ms,gender.

·         Take input from user and store in age,ms,and gender.

o   Useif(gender=m && age>=30),Then print “You are insured”.

o   Use else if(gender=f && age>=25)),Then print “You are insured”.

·         Otherwise use Else and print “You are not insured”.

Ø     Program:-

#include<iostream>

using namespace std;

int main()

{

         charms,gender;

         int age;

         cout<<"Enter martial status";

         cin>>ms;

         cout<<"Enter gender";

         cin>>gender;

         cout<<"Enter age";

         cin>>age;

         if(ms=='m')

         {

                     cout<<"You are insured:";     

         }

         else if(gender=='m' && age>=30)

                     {

                                 cout<<"You are insured";      

                     }

        

         else if(gender=='f' && age>=25)

                     {

                                 cout<<"You are insured";      

                     }

        

         else

         {

                     cout<<"You are not insured";

         }

        

         return 0;

        

}


Share this:

ABOUT THE AUTHOR

Hello We are OddThemes, Our name came from the fact that we are UNIQUE. We specialize in designing premium looking fully customizable highly responsive blogger templates. We at OddThemes do carry a philosophy that: Nothing Is Impossible

0 comments:

Post a Comment