Saturday, 1 February 2014

write a program in c++ that calculate leap year

Example 4 if,else statement:

logic:
         here the main logic is that "the year which will divide by 4 and reminder is zero then the year will be leap otherwise not" so we take the modules of year by and check the year is leap or not.

program:

#include "stdafx.h"
#include "iostream"
#include "conio.h"
using namespace std;
void main()
{
int year;
cout<<"enter the year==";
cin>>year;
if(year%4==0)
cout<<"leap year";
else
cout<<"not a leap year";
_getch();

}

                                                                DOWNLOAD .CPP FILE




write a program in c++ that take your marks as input and display your grade as output.

Example 3 nested if,else statement:

statement:

write a program in c++ that take your marks as input and display your grade as output.

logic:

      we simply use nested if,else statement because we have multiple choices. first of all we have to understand the grading system every institute have own grading system i made this program according to my institute. here  first if condition will be  true if the marks between 100 and 84.5 then output will be A+. if the first condition is false then compiler will check the second condition if this condition is true then then compiler will run its block of code and leave all condition similarly it will be done for all conditions. else block will be run if all if condition will be false.

program:

#include "stdafx.h"
#include "iostream"
#include"conio.h"
using namespace std;
 void main()
{
int marks;
            cout<<"enter the marks==";
cin>>marks;

       if(marks>=84.5 && marks<100 )
        {cout<<"your grade is A+";}
else
if (marks>=79.5 && marks<84.5)
{
cout<<"your grade is A";
}
else
if (marks>=74.5 && marks<79.5)
{
cout<<"your grade is B+";
}
else
if (marks>=69.5 && marks<74.5)
{
cout<<"your grade is B";
}
else
if (marks>=64.5 && marks<69.5)
{
cout<<"your grade is B-";
}
else
if (marks>=59.5 && marks<64.5)
{
cout<<"your grade is c+";
}
else
if (marks>=54.5 && marks<59.5)
{
cout<<"your grade is c";
}
else
if (marks>=49.5 && marks<54.5)
{
cout<<"your grade is D";
}
else
if (marks<49.5 && marks>=0)
{
cout<<"your grade is F";
}
else
{
cout<<"wrong entry";
}
_getch();       

}
                                                     
                                                             DOWNLOAD .CPP FILE