Browsing articles tagged with " C++ prgoram"
Dec
3

Object & Methods in C++

By admin  //  C++  //  View Comments

#include<iostream.h>
#include<conio.h>
class employee
{
char name[30];
int age;
public:
void getdata(void);
void putdata(void);
};

void employee::getdata(void)
{
cout<<”Enter name and age”<<endl;
cin>>name>>age;
}

void employee::putdata(void)
{
cout<<”Name: “<<name<<endl;
cout<<”Age : “<<age<<endl;
}

const int size=3;

int main()
{
employee emp[size];
for(int i=0;i<3;i++)
{
cout<<”Details of “<<i+1<< “employee:\n”;
emp[i].getdata();
}
cout<<endl<<endl;
cout<<”The details are:”<<endl;
for(i=0;i<3;i++)
{
cout<<”Employee No.:”<<i+1<<endl;
emp[i].putdata();              
cout<<endl;
}
getch();
return(0);
}

Sep
29

WAP in C++ to decide whether the input year is leap year or not

By admin  //  C++  //  View Comments

A year will be a leap year if it is divisible by 4 but not by 100. If a year is divisible by 4 and by 100, it is not a leap year unless it is also divisible by 400.

Thus years such as 1996, 1992, 1988 and so on are leap years because they are divisible by 4 but not by 100. For century years, the 400 rule is important. Thus, century years 1900, 1800 and 1700 while all still divisible by 4 are also exactly divisible by 100. As they are not further divisible by 400, they are not leap years.
In general terms the algorithm for calculating a leap year is as follows in C++.

include <iostream.h>
#include <conio.h>
#define pi 3.1415
void main()
{
int y;
cout<<”Please provide a year to detect whether it is leap year or not?”<<endl;
cin>>y;
if (y%100==0)
{
if (y%400==0)
{
cout<<”leap year”<<endl;
}

else
{
cout<<”Not leap year”<<endl;
}
}                           

else if (y%4==0)
{
cout<<”leap year”<<endl;
}
else{
cout<<”Not leap year”<<endl;      
}

getch();

}

Namaste!

Hello! This is Nirmal Gyanwali, a freelance web developer from Kathmandu, Nepal. I am well versed with Open source CMS and portal frameworks like Joomla!, Wordpress, Drupal. If you're interested, you can contact me at info@nirmal.com.np.
Thanks!

Latest Tweets