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.
//Note: If you are not using Borland or Turbo C then add the following line after header files :
//using namespace std;
#include<iostream.h>
#include<conio.h>
class date
{
public:
int d,m,y;
friend istream & operator >>(istream & in,date & dd); //declare friend function
friend ostream & operator <<(ostream & out,date & dd); //declare friend function
void valid()
{
switch(m)
{
case 1 : if(d>31)
cout<<"Invalid date";break;
case 2 : if(y%4==0)
{
if(d>29)
{
cout<<"Invalid date";break;
}
}
else
if(d>28)
cout<<"Invalid date";break;
case 3,6 : if(d>31)
cout<<"Invalid date";break;
case 4,7,8,10,12 : if(d>30)
cout<<"Invalid date";break;
case 5 : if(d>31)
cout<<"Invalid date";break;
}
}
};
istream & operator>>(istream & in,date & dd)
{
in>>dd.d>>dd.m>>dd.y;
return in;
}
ostream & operator <<(ostream & out,date & dd)
{
out<<dd.d<<"/"<<dd.m<<"/"<<dd.y;
return out;
}
int main()
{
date d; //creating instance of class date
cout<<"Enter date(dd mm yyyy):- ";
cin>>d;
d.valid();
cout<<"\nDate is: "<<d;
getch();
return(0);
}
-
Next Create two base classes Learning_Info( Roll_No, Stud_Name, Class, Percentage) and Earning_Info(No_of_hours_worked, Charges_per_hour). Derive a class Earn_Learn_info from above two classes. Write necessary member functions to accept and display Student information. Calculate total money earned by the student. (Use constructor in derived class)
-
Previous 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)
0 Comments