/*Slip no : 8_1 Write a C++ program
to create a class Employee which
contains data members
as Emp_Id, Emp_Name, Basic_Salary, HRA, DA, Gross_Salary.
Write member functions
to accept Employee information. Calculate and display
Gross salary of an
employee. (DA=12% of Basic salary and HRA = 30% of Basic
salary) (Use
appropriate manipulators to display employee information in
given format :- Emp_Id
and Emp_Name should be left justified and Basic_Salary,
HRA, DA, Gross salary
Right justified with a precision of two digits) */
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class emp
{
int
eid;
float
bs,hra,da,gs;
char
name[10];
public:
void
accept()
{
cout<<"enter
id";
cin>>eid;
cout<<"enter
name";
cin>>name;
cout<<"enter
bs";
cin>>bs;
}
void
display()
{
cout<<"\n
eid="<<eid<<"\n name="<<name<<"\n
bssic salary = "<<bs;
cout<<"\n
HRA = "<<(bs*0.30);
cout<<"\n
DA = "<<(bs*0.12);
cout<<"\n
Gross Salary = "<<(bs-((bs*0.12)+(bs*0.30)));
}
};
void main()
{
emp
ob;
clrscr();
ob.accept();
ob.display();
getch();
}
/* Slip no : 8_2 Create a class
Date containing members as:
dd
mm
yyyy
Write a C++ program for overloading
operators >> and << to accept and display a Date also write a
member function to validate a date. */
#include<conio.h>
#include<iostream.h>
class date
{
int dd,mm,yy;
public:
friend istream
&operator>>(istream &,date &);
friend ostream
&operator<<(ostream &,date &);
void validate()
{
int flag=0;
if(mm==2)
{
if(yy%4==0)
{
if(dd>=1&&dd<=29)
flag=1;
}
else
if(dd>=1&&dd<=28)
flag=1;
}
else
if(mm==1||mm==3||mm==5||mm==7||mm==8||mm==10||mm==12)
{
if(dd>=1&&dd<=31)
flag=1;
}
else
{ if(mm==4||mm==6||mm==9||mm==11)
{
if(dd>=1&&dd<=30)
flag=1;
}
}
if(flag==1)
cout<<"valid date
\t";
else cout<<"invalid date
\t ";
}//end of validation
};
istream
&operator>>(istream &in,date &ob)
{
cout<<"enter date";
cin>>ob.dd;
cout<<"enter
month";
cin>>ob.mm;
cout<<"enter year";
cin>>ob.yy;
return in;
}
ostream
&operator<<(ostream &out,date &n)
{
cout<<n.dd<<"/"<<n.mm<<"/"<<n.yy;
return out;
}
void main()
{
date ob;
clrscr();
cin>>ob;
ob.validate();
cout<<ob;
getch();
}
slip 8
Reviewed by Dinesh Varal
on
January 16, 2018
Rating:
No comments: