Solutions to Project Section 1


First Program : 

//To check whether the year is a leap year
#include<iostream.h>
int main( )
{
int year;
cout<<"Enter the year you want to check: ";
cin>>year;

if (  ( (year%100)!=0 ) && ( (year%4)= =0)  )
    {
    cout<<endl<<"The year "<<year<<" is a leap year";
    }
else if ( (year%400)= =0 )
    {
    cout<<endl<<"The year "<<year<<" is a CENTURY LEAP YEAR";
    }
else
    {
    cout<<endl<<"The year "<<year<<" is NOT a leap year ";
    }
return 0;
}


Second Program:

// Simple calculator

#include<iostream.h> 
int main( ) 
{
int num1, num2, num3; 
char choice;
cout<<"Let's calculate two numbers. Enter the two numbers: "; 
cin>>num1; 
cin>>num2; 
cout<<"What do you want to do with the numbers? Choose one of the options : "; 
cout<<"a for add, s for subtract, m for multiply, d for divide : "; 
cin>>choice; 
switch (choice) 

    case 'a': 
    { 
    num3 = num1 + num2; 
    cout<<"The sum of the two numbers is : "<<num3; 
    break; 
    } 
    case 's': 
    { 
    num3=num1- num2; 
    cout<<"The difference between the two numbers is : "<<num3; 
    break; 
    } 
    case 'm': 
    { 
    num3 = num1*num2; 
    cout<<"The product of the two numbers is : "<<num3; 
    break; 
    } 
    case 'd': 
    { 
    num3 = num1/num2; 
    cout<<"The quotient of the two numbers is : "<<num3; 
    break; 
    } 
    default: 
    { 
    cout<<"That is not a choice"; 
    break; 
    } 
}
return 0;
}


Go to the next section on : Functions

or return back to Contents.


Copyright © 2002 Sethu Subramanian All rights reserved.