About Me

My photo
Latur, Maharashtra, India

Monday, December 26, 2011

Saturday, October 15, 2011

CSS Assignment


1. Design horizontal and vertical navigation bars using embedded css.


CODE:
<html>
<head>
            <title>program for vertical and horrizontal navigation bar</title>
            <style type="text/css">
            .ul1
            {
                        list-style-type:none; 
                        background-color:red;   
            }
            .li1
            {
                        display:inline;
                        background-color:red;
                        margin:15;
            }
            .ul2
            {          
                        list-style-type:none; 
                        display:block;
                        background-color:yellow;
                        width:80;
            }
            .li2
            {
                        display:block;
                        background-color:pink;
                        margin:15;
            }
            </style>
</head>

<body bgcolor="grey">

<ul class="ul1">
            <li class="li1"><a href="http://www.dte.org.in\mca">MCA</a></li>
            <li class="li1"><a href="http://www.dte.org.in\mba">MBA</a></li>
            <li class="li1"><a href="http://www.dte.org.in\mcm">MCM</a></li>
</ul>

<ul class="ul2">
            <li class="li2"><a href="http://www.dte.org.in\mca">MCA</a></li>
            <li class="li2"><a href="http://www.dte.org.in\mba">MBA</a></li>
            <li class="li2"><a href="http://www.dte.org.in\mcm">MCM</a></li>
</ul>

</body>
</html>




OUTPUT:




 generate outut by running it own





2. Design a web page using external css which uses nested styles.

CODE:
<html>
<head>
<title>program using nested css</title>
<style type="text/css">
.div
{
            text-align:center;
            color:red;
            background-color:black;
            font-size:30;
}
p
{
            text-align:center;
            color:blue;
            background-color:green;
            font-size:20;   
}

.div p
{
            text-align:center;
            color:pink;
            background-color:gray;
            font-size:20;   
}
</style>
</head>

<body>
<div class="div">
       <p>
            Nested css. Nested css. Nested css. Nested css.
            Nested css. Nested css. Nested css. Nested css.
            Nested css. Nested css. Nested css. Nested css.
            Nested css. Nested css. Nested css. Nested css.
      </p>
</div>
<p>

            Nested css. Nested css. Nested css. Nested css.
            Nested css. Nested css. Nested css. Nested css.
            Nested css. Nested css. Nested css. Nested css.
            Nested css. Nested css. Nested css. Nested css.
</p>
</body>
</html>

OUTPUT:

 generate outut by running it own

3. Design a html page for creating image gallery using css and html.

CODE:
<html>
<head>
            <title>Image gallery</title>
            <link rel="stylesheet" href="imgal.css"/>
           
            <style type="text/css">
            fieldset
            {
                        width:40%;
            }
            </style>
</head>

<body>
<fieldset>
            <legend>
                        <font color="red" size="15" style="impact" >Image Gallery</font>
            </legend>

            <div class="img">
                        <a href="">
                                    <img src="s1.jpg" alt="C3" width="130" height="100"/>
                        </a>
                        <div class="about">Nokia C3</div>
            </div>
           
            <div class="img">
                        <a href="">
                                    <img src="s2.jpg" alt="C5" width="130" height="100" />
                        </a>
                        <div class="about">Nokia C5</div>
            </div>
           
            <div class="img">
                        <a href="">
                        <img src="s3.jpg" alt="C6" width="130" height="100" />
                        </a>
                        <div class="about">Nokia C6</div>
            </div>
</fieldset>
</body>
</html>

imgal.css

.img
{
            border:1px dashed;
            text-align:center;
           
}


.img a
{
            border:1px solid;
}

.about
{
            text-align:center;
           
}







OUTPUT:



 generate outut by running it own


4. Design a web page using external css which uses the following properties.
·       Text with comic font
·       Text indent 10 px
·       H4 with small letters
·       H4 background image and underlined text
·       Hyperlink with yellow color text.


CODE:
<html>
<head>
            <title>design a web page using external css.</title>
            <link rel="stylesheet" href="textsheet.css"/>
</head>

<body>

<font>
            Text with comic font
            Text indent 10 px

</font>

<h4>
            H4 with small letters
            H4 background image and underlined text

</h4>

<a href="http://www.google.com">
            This a link with yellow color.
</a>

</body>
</html>




textsheet.css
font
{
            font-family:comic;
            text-indent:10px;
}

h4
{
            background:url('image.jpg');
            text-decoration:underline;
}

a
{
            color:yellow;
}



OUTPUT:


 generate outut by running it own


5. Design a web page using external css which uses the following properties.          
·       Paragraph with Background page
·       Aligh h1 text in center of web page
·       h2 with right indent 10px
·       Table with blue border at Top and Bottom 

CODE:

<html>
<head>
            <title>design a web page using external css.</title>
            <link rel="stylesheet" href="5.css"/>
</head>

<body bgcolor="pink">

<p>
            Paragraph with Background.Paragraph with Background.Paragraph with Background.Paragraph with
BackgroundParagraph with Background        pageParagraph with BackgroundParagraph with BackgroundParagraph            with
Background pageParagraph with BackgroundParagraph with Background             pageParagraph with BackgroundParagraph with
BackgroundParagraph with Background pageParagraph with BackgroundParagraph with Background pageParagraph with
BackgroundParagraph with BackgroundParagraph   with Background page
</p>
<h1>
            Aligh the text in center of browser
<h1>
<h2>
            Heading 2 with right indent 10pixels
<h2>
<table border=1s>
            <th colspan=2>Table with blue border at Top and Bottom</th>
            <tr>
                        <td>1</td>
                        <td>2</td>
            </tr>
            <tr>
                        <td>1</td>
                        <td>2</td>
            </tr>
</table>
</body>
</html>

5.css
p
{
            background:url('image.jpg');
}

h1
{
            text-align:center;
}

h2
{
            text-indent:10px;
            text-align:right;
}

table
{
            border-top-color:blue;
            border-bottom-color:blue;
}


OUTPUT:


 generate outut by running it own


6. Design a web page using external css which uses the following properties.          
·       Color of text should be  ‘navy’
·       Text having 13 font-size, Times New Roman font, and Italic
·       Three types of hyperlinks with mentioned color visited-red active blue, 
      current-marron
·       Set Border for paragraph in ‘magenta’ color.


CODE:
<html>
<head>
        <title>main </title>
  <link rel="stylesheet" type="text/css" href="properties.css" ></link>
</head>
<body bgcolor="pink">
<center><h1>
IT IS DBMS PAGE</h1></center>
<h3>What is DBMS?</h3><br>
<p>

• DBMS stands for database management system<br>
• Database is the storage for the data<br>
• There are two major databases---<br>
• Relaitional database<br>
• Distributed databases<br>
</p>

<a href ="http:www.http://www.w3schools.com/css/css_intro.asp">What is DBMS</a><br>
<a href ="http:www.http://www.w3schools.com/css/css_intro.asp">What is Relaitional DBMS</a><br>
<a href ="http:www.http://www.w3schools.com/css/css_intro.asp">What is Distributed databases</a>

</body>
</html>

Properties.CSS

p
{
                   color:navy;
                  font-size:13px;
                  font-family:"Times New Roman";
                  font-style:italic;
                  border-width:2px;
                  border-style:solid;
                  border-color:magenta;
}
a:link {color:#FF0000;}    /* unvisited link */
a:visited {color:#00FF00;} /* visited link */
a:hover {color:#FF00FF;}   /* mouse over link */
a:active {color:#0000FF;}  /* selected link */

OUTPUT:


 generate outut by running it own
                                       

Thursday, October 13, 2011

C++ second assignment



1.    Write a programe for addition of two complex numbers using a friend function Return the result from the function.

# include<iostream.h>
# include<conio.h>
class complex
{
            float x,y;
            public:
                        void getdata(float real,float imag)
                        {
                                    x=real;y=imag;
                        }
                        friend complex add(complex,complex);
void show();
};

complex add(complex c1,complex c2)
{
            complex c3;
            c3.x=c1.x+c2.x;
            c3.y=c1.y+c2.y;
            return(c3);
}
void complex::show()
{
            cout<<x<<"+j"<<y;
}

int main()
{
            complex c1,c2,c3;    //OBJECTS
            float a1,b1,a2,b2; // VARIABLES
            clrscr();
cout<<”Wasim Shaikh”;
            cout<<"\nArithematic Operations " <<endl;
            cout<<"\n\t->Enter the first equation a b : ";
            cin>>a1;cin>>b1;



            cout<<"\t->Enter the second Equation a b : ";
            cin>>a2;cin>>b2;
            c1.getdata(a1,b1);
            c2.getdata(a2,b2);
                        c3=add(a,b);
                        cout<<"\nA = ";
                        c1.show();
                        cout<<endl;
                        cout<<"B = ";
                        c2.show();
                        cout<<endl;
                        cout<<"C = ";
                        c3.show();
            getch();
}




Output:
Enter the first equation a b :
2
3

Enter the second Equation a b :
3
3

A = 2+j3
B = 3+j3
C = 5+j3























2. WAP in which take 2 classes containing integer data member and getdata and putdata as member functions ,write a function compare which is not a member function of the two classes but compares the data values of the two classes.


#include<iostream.h>
#include<conio.h>
class B;
class A
{
            int a;
   public:
   void getdata()
   {
   cout<<"\nEnter Number for Class A :";
   cin>>a;
   }
   void putdata()
   {
       cout<<"Class A's Variable a ="<<a;
   }
   friend void comp(A aa,B bb);
};

class B
{
            int b;
   public:
   void getdata()
   {
   cout<<"\nEnter Number for Class B :";
   cin>>b;
   }
   void putdata()
   {
       cout<<"\nClass B's Variable a ="<<b;
   }
   friend void comp(A aa,B bb);
};



void comp(A aa,B bb)
{
            if(aa.a>bb.b)
   {
            cout<<"\n\n"<<aa.a<<" is Greater than "<<bb.b;
   }
   else if(bb.b>aa.a)
   {
            cout<<"\n\n"<<bb.b<<" is Greater than "<<aa.a;
   }
   else
   {
            cout<<"\nBoth are Equal";
   }
}

void main()
{
A aa;
B bb;
clrscr();
cout<<”Wasim Shaikh”;
aa.getdata();
bb.getdata();

aa.putdata();
bb.putdata();

comp(aa,bb);
getch();
}


Output:


Enter Number for Class A :12

Enter Number for Class B :11
Class A's Variable a =12
Class B's Variable a =11

12 is Greater than 11












3.WAP in which create 2 classes cube and cylinder.set the color property of the two classes.write a function samecolor as a member function of cylinder class which compares the color of two objects of cylinder and cube classes and returns a Boolean value accordingly.print the appropriate message in the main function.

#include<iostream.h>
#include<conio.h>
enum color{red,blue,green};
class cyllinder;
class cube
{
public:
color col;
void setcolor(color c)
{
col=c;
}
bool same_color(cyllinder y);
};

class cyllinder
{
public:
color col;
void setcolor(color c)
{
col=c;
}
friend bool cube::same_color(cyllinder );
};

bool cube::same_color(cyllinder y)
{
if(col==y.col)
{
return(true);
}
else
return(false);
}
void main()
{
cout<<”Wasim Shaikh”;
clrscr();

cube cub;
cyllinder cyl;
cub.setcolor(green);
cyl.setcolor(red);
if(cube1.same_color(cyl)==true)
{
cout<<endl<<"Same colour...";
}
else
{
cout<<endl<<"Different Colour...";
}
getch();
}

Output:
Same colour...
Different Colour...















4.Create two classes DB and DM which stores the values of distances.DM stores the distances in meters and centemeters and DB stores in feet and inches.WAP that can read values for class objects and adds one object of DM with another object of DB.Use the firend function to carry out addition operation .The object which stores the result should be the DM object.Display the result appropriately.

# include<iostream.h>
# include<conio.h>
class DB;
class DM
{
            int m,cm;
            public:
                        void getdata()
                        {
                                    cout<<"\n\tEnter distance in Meters : ";
                                    cin>>m;
                                    cout<<"\n\tEnter distance in Centimeters : ";
                                    cin>>cm;
                        }
                        friend void add(DM,DB);
};
class DB
{
            int ft,in;
            public:
                        void getdata()
                        {
                                    cout<<"\n\tEnter distance in Fits : ";
                                    cin>>ft;
                                    cout<<"\n\tEnter distance in Inches : ";
                                    cin>>in;
                        }
                        friend void add(DM,DB);
};





void add(DM dmobj, DB dbobj)
{
            float met=(dbobj.ft*12*2.45)/100;
            float centi=(dbobj.in*2.54);
            float totalm=dmobj.m+met;
            float totalcenti=dmobj.cm+centi;
            cout<<"\n\n\tTotal Distance : ";
                        while(totalcenti>=100)
                        {
                                    totalm++;
                                    totalcenti=totalcenti-100;
                        }
            cout<<totalm<<" Meters "<<totalcenti<<"  Centimeters"<<endl;

}

void main()
{
            DM d;
            DB b;
            clrscr();
cout<<”Wasim Shaikh”;
            d.getdata();
            b.getdata();
            add(d,b);
            getch();
}



Output :


        Enter distance in Meters : 2

        Enter distance in Centimeters : 3

        Enter distance in Fits : 2

        Enter distance in Inches : 5

        Total Distance : 2.588 Meters 15.7  Centimeters
















5.WAP using the friend function multiply which will return the multiplication of data values of two different classes using pointer to data member and pointer to object.

#include<iostream.h>
#include<conio.h>
class B;
class A
{
int a;
public:
void set_a(int x)
{
a=x;
}
friend int multi(A,B);
};

class B
{
int b;
public:


void set_b(int y)
{
b=y;
}
friend int multi(A,B);
};

int multi(A a,B b)
{
int A :: *pa=&A::a;
int B :: *pb=&B::b;
B *op=&b;
int multi= ( (a.*pa) * (op->*pb) );
return multi;
}
int main()
{
clrscr();
A n1;
B n2;
cout<<”Wasim Shaikh”;
void(A :: *pa)(int)=&A::set_a;
(n1.*pa)(20);

void(B :: *pb)(int)=&B::set_b;
(n2.*pb)(20);
cout<<"multiplication="<<multi(n1,n2)<<"\n";
A *op1=&n1;
(op1->*pa)(3);
B *op2=&n2;
(op2->*pb)(3);
cout<<"multiplicatin="<<multi(n1,n2)<<"\n";
getch();
return(0);
}

Output:
multiplication=400
multiplicatin=9

















6.Take two classes Time1 and Time2 which stores the time in 12 hours and 24 hours formate.Write a friend function which takes the two time objects and converts it into one of them.Write a display function to display the appropriate time.

#include<iostream.h>
#include<conio.h>
class Time2;
class Time1
{
            int hh;
   int mm;
   char s;
   public:
   Time1()
   {
   hh=0;
   mm=0;
   }
   void gettime1()
   {
            cout<<"\nEnter Time in 12 Hour Format:";
      cout<<"\nEnter Hour :";
      cin>>hh;
      cout<<"\nEnter Minutes :";
      cin>>mm;
      cout<<"\nEnter A for AM/P for PM";
      cin>>s;
   }
   void disptime1()
   {

      cout<<hh<<":"<<mm<<" "<<s<<"M";

   }
   friend void convert(Time1 t1,Time2 t2);
};

class Time2
{
            int hh;
   int mm;
            public:
   Time2()
   {
            hh=0;
      mm=0;
   }
   void gettime2()
   {
            cout<<"\nEnter Time in 24 Hour Format :";
      cout<<"\nEnter Hour :";
      cin>>hh;
      cout<<"\nEnter Minutes :";
      cin>>mm;
   }
   void disptime2()
   {

      cout<<hh<<":"<<mm;
   }
friend void convert(Time1 t1,Time2 t2);
};

void convert(Time1 t1,Time2 t2)
{
            if(t1.hh!=0)
   {
            if(t1.s=='A')
      {
            t2.hh=t1.hh;
         t2.mm=t1.mm;
         t2.disptime2();
      }
      else
      {
            t2.hh=t1.hh+12;
         t2.mm=t1.mm;
         t2.disptime2();
      }
   }
   else
   {
            if(t2.hh>=12)
      {
            t1.hh=t2.hh-12;
         t1.mm=t2.mm;
         t1.s='P';
         t1.disptime1();
      }
      else
      {
            t1.hh=t2.hh;
         t1.mm=t2.mm;
         t1.s='A';
         t1.disptime1();
      }
   }
}

void main()
{
            Time1 t1;
   Time2 t2;
            int ff;
   clrscr();
cout<<”Wasim Shaikh”;


   cout<<"\nIn Which Format you want to Enter Time :";
   cout<<"\n1 For 12 hour Format\n2 For 24 hour Format\n";
   cin>>ff;
   if(ff==1)
   {
            t1.gettime1();
      cout<<"\nEntered Time in 12 Hour Format:";
      t1.disptime1();

      cout<<"\nConverted Time in 24 Hour Format:";
      convert(t1,t2);
   }
  else
   {
            t2.gettime2();
            cout<<"\nEntered Time in 24 Hour Format:";
      t2.disptime2();
      cout<<"\nConverted Time in 12 Hour Format:";
      convert(t1,t2);
   }
getch();
}


Output:

In Which Format you want to Enter Time :
1 For 12 hour Format
2 For 24 hour Format
1

Enter Time in 12 Hour Format:
Enter Hour :11

Enter Minutes :21

Enter A for AM/P for PM :P

Entered Time in 12 Hour Format:11:21 PM
Converted Time in 24 Hour Format:23:21

7.WAP to show the use of constructor and destructor.

#include<iostream.h>
int count=0;
class alpha
{
public:
alpha()
{
count++
cout<<"\n No.of Object created"<<count;
}
~alpha()
{
cout<<"\n No.of object Destroyed"<<count;
count--;
}
};

int main()
{
cout<<"\n Enter Main\n";
alpha a1,a2,a3,a4;


{
cout<<"\n Enter in Block 1 ";
alpha a5;
}
{
cout<<"\n Enter in Block 2 ";
alpha a6;
}
cout<<"\n Re-Enter Main\n";
return(0);
}

Output:
Enter Main
No.of Object created1
No.of Object created2
No.of Object created3
No.of Object created4
Enter in Block 1
No.of Object created5
No.of object Destroyed5
Enter in Block 2
No.of Object created5
No.of object Destroyed5
Re-Enter Main


8. WAP to test your class to see that it does the following      - 19 -Created by FRKtasks.
1)Create uninitialized string objects.
2)Create objects with string constants.
3)Concatenates two strings.
4)Display the desired string objects.

#include<iostream.h>
#include<conio.h>
#include<string.h>
class string
{
char *name;
int lenght;
public:
string()
{
lenght=0;
name=new char[lenght+1];
strcpy(name,"\0");
}
string(char *s)
{
int length=strlen(s);
name=new char[lenght+1];
strcpy(name,s);
}
void display()
{
cout<<name<<endl;
}
friend string join(string &,string &);
};
string join(string &a,string &b)
{
string s;
s.lenght=a.lenght+b.lenght;
delete s.name;
s.name=new char[s.lenght+1];
strcpy(s.name,a.name);
strcat(s.name,b.name);
return(s);
}

void main()
{
clrscr();
string name1("Faruk "),name2("Meman"),s2;
cout<<”Wasim Shaikh”;
name1.display();
name2.display();
s2=join(name1,name2);
s2.display();
getch();
}

Output:-
wasim
Shaikh
Wasim Shaikh






































Operator Overloading
1)WAP for overloading the following operators.
a)+,-,*,% ,binary operators.

#include<iostream.h>
#include<conio.h>
class complex
{
float real,img;
public:
complex(){} //default constructor
complex(float r,float i)
{
real=r; img=i;
}
void display()
{
cout<<real<<" + "<<img<<" i"<<endl;
}
complex operator+(complex x)
{
complex add;
add.real=real+x.real;
add.img=img+x.img;
return add;
}

friend complex operator-(complex x,complex y)
{
complex sub;
sub.real=x.real-y.real;
sub.img=x.img-y.img;
return sub;
}
complex operator*(complex x)
{
complex mul;
mul.real=real*x.real-img*x.img;
mul.img=real*x.img+img*x.real;
return mul;
}
complex operator/(complex x)
{
complex div;
div.real=(real*x.real+img*x.img)/(x.real*x.real+x.img*x.img);
div.img=(-real*x.img+img*x.real)/(x.real*x.real+x.img*x.img);
return div;
}
};

void main()
{
complex c1(4,5),c2(2,3),c3;
cout<<"comlex1=\t";
c1.display();
cout<<endl<<"complex2=\t";
c2.display();
c3=c1+c2; //c3=c1.operator+(c2)
cout<<”Wasim Shaikh”;
cout<<endl<<"Addition=\t";
c3.display();
c3=c1-c2; //c3=operator-(c1,c2)
cout<<endl<<"Substraction=\t";
c3.display();
c3=c1*c2; //c3=c1.operator*(c2)
cout<<endl<<"multiplication=";
c3.display();
cout<<endl<<"Division=\t";
c3=c1/c2; //c3=c1.operator/(c2)
c3.display();
}
Output:
comlex1= 4 + 5 i
complex2= 2 + 3 i
Addition= 6 + 8 i
Substraction= 2 + 2 i
multiplication=-7 + 22 i
Division= 1.769231 + -0.153846 i
b)++,__ unary operators

#include<iostream.h>
#include<conio.h>
class index
{
int count;
public:
index()
{
count=0;
}
index(int i)
{
count=i;
}

index operator ++()
{
return (++count);
}

index operator ++(int)
{
return (count++);
}
index operator --()
{
return (++count);
}
index operator --(int)
{
return (count--);
}
void display();
};
void index::display()
{
cout<<count<<endl;
}

void main()
{
clrscr();
index a;
cout<<”Wasim Shaikh”;
cout<<"=====use of ++ && -- operator====="<<endl;
a.display();
<<”Count=”:
a++;
<<”Count++”:
a.display();
<<”++Cout=”:
++a;
a.display();
a--;
<<”Count - - =”;
a.display();
getch();
}

Output:
=====use of ++ && -- operator=====
Count=0
Count++= 1
++Count=2
Count--= 1









2)Accept date D in DD-MM-YYYY formate and an integer number n from keyboard.
a) Write a programme to overload + (plus) operator which gives the next date n days after ‘D’ in DD-MM-YYYY formate.ex. if D is 26-01-2010 and n=5,function should return 31-01-2010

#include<iostream.h>
#include<conio.h>
class date
{
            int dd;
            int mm;
            int yy;
            public:
            void getdate()
            {
                        cout<<"\nEnter Date in dd mm yyyy Format :";
                        cin>>dd>>mm>>yy;
            }
            void dispdate()
            {
                        cout<<dd<<"/"<<mm<<"/"<<yy;
            }
            friend date operator+(date d1,int n);
};
date operator+(date d1,int n)
            {
                        if(d1.mm==4||d1.mm==6||d1.mm==9||d1.mm==11)
                        {
                                    if(d1.dd+n<=30)
                                    {
                                           d1.dd=d1.dd+n;
                                    }
                                    else
                                    {
                                                d1.dd=(d1.dd+n)%30;
                                                d1.mm++;
                                    }
                        }
                        else if(d1.mm==1||d1.mm==3||d1.mm==5||d1.mm==7||d1.mm==8||d1.mm==10||d1.mm==12)
                        {
                                    if(d1.dd+n<=31)
                                    {
                                           d1.dd=d1.dd+n;
                                    }
                                    else
                                    {
                                                d1.dd=(d1.dd+n)%31;
                                                if(d1.mm==12)
                                                {
                                                            d1.mm=(d1.mm+1)%12;
                                                            d1.yy++;
                                                }
                                    }
                        }
                        else if(d1.mm==2)
                        {
                          if(d1.yy%4==0||d1.yy%400==0||d1.yy%100)
                          {
                                    if(d1.dd+n<=29)
                                    {
                                           d1.dd=d1.dd+n;
                                    }
                                    else
                                    {
                                                d1.dd=(d1.dd+n)%29;
                                                d1.mm++;
                                    }
                          }
                          else
                          {
                              if(d1.dd+n<=28)
                                    {
                                           d1.dd=d1.dd+n;
                                    }
                                    else
                                    {
                                                d1.dd=(d1.dd+n)%28;
                                                d1.mm++;
}
                          }
                        }
                        return d1;
            }
void main()
{
            date d;
            date d2;
cout<<”Wasim Shaikh”;
            int n;
            clrscr();
            cout<<"\nWasim Shaikh\n\n";
            d.getdate();
            d.dispdate();
            cout<<"\nEnter how many days you want to increament in Date:";
            cin>>n;
            d2=operator+(d,n);
            d2.dispdate();
            getch();
}





Output:

Wasim Shaikh
Enter Date in dd mm yyyy Format :12
03
2011
12/3/2011
Enter how many days you want to increament in Date:2
14/3/2011















b) WAP to overload an operator “-” to find the date difference.

#include<conio.h>
#include<iostream.h>
class Date
{
intdd;
int mm;
intyyyy;
char ch1,ch2;
public :
Date(){};
Date operator -(Date);
friendistream& operator >>(istream&, Date &);
friendostream& operator <<(ostream&, Date &);
intisValid();
intisLeap();
friendintfindgreater(Date, Date);
};
int Date :: isLeap()
{
int leap=0;
if((yyyy%400==0) || ((yyyy%4==0) && (yyyy%100!=0)))
leap=1;
else
leap=0;
return leap;
}
int Date :: isValid()
{
int flag=0;
if(dd<=0 || mm<=0 || yyyy<=0)
{
flag=1;
}
else
if(mm==2 &&dd>29 &&isLeap())
{
flag=1;
}
Else P.T.O
if(mm==2 &&dd>=29 && !isLeap())
{
flag=1;
}
else
if(mm%2!=0 &&dd>31 && mm<8)
{
flag=1;
}
else
if(mm%2==0 &&dd>30 && mm<8)
{
flag=1;
}
else
if(mm>12)
{
flag=1;
}
return flag;
}

intfindgreater(Date d1, Date d2)
{
if(d1.yyyy>=d2.yyyy)
return 1;
else return 2;}
Date Date :: operator -(Date d)
{
Date temp;
intfm,lm,fd,ld,gd,sd;
int month[]={31,28,31,30,31,30,31,31,30,31,30,31};
if(yyyy==d.yyyy)
{
temp.yyyy=0;
if(mm==d.mm)
{
temp.mm=-1;
if(dd>d.dd)
{
gd=dd;
sd=d.dd;
}
else
if(d.dd>dd)
{
gd=d.dd;
sd=dd;
}
else
{ P.T.O
gd=dd;
sd=d.dd;
}
}
else
if(d.mm>mm)
{
temp.mm=d.mm-mm-1;
gd=d.dd;
sd=dd;
}
else
{
temp.mm=mm-d.mm-1;
gd=dd;
sd=d.dd;
}
}
else
{
temp.yyyy=yyyy-d.yyyy-1;
gd=dd;
sd=d.dd;
fm=12-d.mm;
lm=mm-1;
temp.mm=fm+lm;
cout<<temp.mm;
}
if(mm==2)
{
if(isLeap())
fd=29-dd;
else
fd=month[mm-1]-dd;
}
else
fd=month[mm-1]-dd;
ld=d.dd;
temp.dd=fd+ld;
int m=month[d.mm-1];
if(d.mm!=2)
{
if(temp.dd>30)
{
temp.mm=temp.mm+1;
temp.dd=temp.dd%m;
}
}
else
{
if(temp.dd>28) P.T.O
{
temp.mm=temp.mm+1;
if(isLeap())
temp.dd=temp.dd%29;
else
temp.dd=temp.dd%m;
}
}

if(temp.mm>11)
{
temp.yyyy=temp.yyyy+1;
temp.mm=temp.mm%11-1;
cout<<temp.mm;
}
return temp;
}

istream& operator >> (istream&din, Date &d)
{
din>>d.dd>>d.ch1>>d.mm>>d.ch1>>d.yyyy;
return din;
}

ostream& operator << (ostream&dout, Date &d)
{
dout<<"\n\n\t = = = Date Difference = = = \n\n";
dout<<"\t -> "<<d.dd<<" Days "<<d.mm<<" Months "<<d.yyyy<<" Years";
returndout;
}

void main()
{
intd,m,y,g;
Date d1,d2,diff;
clrscr();
cout<<”Wasim Shaikh”;
cout<<"\n\tEnter dates in dd/mm/yyyy format:";
cout<<"\n\n\t -> Enter Date 1 : ";
cin>>d1;
if(d1.isValid())
cout<<"\n\n\t!! Invalid Date !!";
else
{
cout<<"\n\n\t -> Enter Date 2 : ";
cin>>d2;
if(d2.isValid())
cout<<"\n\n\t !! Invalid Date !! ";
else
{
g = findgreater(d1,d2);
if(g==1) P.T.O
diff=d1-d2;
else
diff=d2-d1;
cout<<diff;
}
}
getch();
}






Output:
Enter dates in dd/mm/yyyy format:
Enter Date 1 : 20/05/2009
Enter Date 2 : 10/07/2010
= = = Date Difference = = =
10 Days 2 Months 1 Years




















3)Define a class String.Overload
1)+ operator to concate two strings
2)[] operator to return ith character.
3)operator == for comparision of two strings.
Include constructors and appropriate access functions

#include<iostream.h>
#include<conio.h>
#include<string.h>
class string
{
char v[20];
public:
string() {strcpy(v,"");}
string(char s[20])
{
strcpy(v,s);
}
char operator[](int i)
{
return v[i];
}
friend string operator+(string ob1,string v);
voidy display();
};
void string::display()
{
cout<<endl<<v;
}
string operator+(string ob1,string ob2)
{
string temp;
strcpy(temp.v,ob1.v);
strcat(temp.v,ob2.v);
return temp;
}

void main()
{
clrscr();
string ob1("Maha");
string ob2("rashtra"),ob3;
int i;
cout<<”Wasim Shaikh”;
ob1.display();
cout<<"\n Enter value of i :";
cin>>i;
cout<<endl<<ob1[i]<<endl;
ob2.display();
cout<<"\n Enter I:";
cin>>i;
cout<<endl<<ob2[i]<<endl;
ob3=ob1+ob2;
ob3.display();
cout<<"\n Enter I:";
cin>>i;
cout<<endl<<ob3[i]<<endl ;
ob3.display();
getch();
}

Output:
First String=GUJ
Enter value of i :2
J
Second String=ARAT
Enter i:1
R
After concatenation=GUJARAT
Enter i:3
A







4)Write a programme to overload insertion and extraction operators.

#include<iostream.h>
#include<conio.h>
class op
{
int a,b;
public:
friend istream & operator>>(istream &,op &);
friend ostream & operator<<(ostream &,op &);
};
istream & operator>>(istream &obj,cricket &c)
{
obj>>c.a;
obj>>c.b;
return obj;
}
ostream & operator<<(ostream &obj,op &c)
{
obj<<c.a<<endl;
obj<<c.b;
return obj;
}

void main()
{
clrscr();
op o;
cout<<”Wasim Shaikh”;
cout<<”Enter the object values”;
cin>>o;
cout<<”object values are:=”;
cout<<o;
getch();
}


Output:
Enter the object values:
25
65
Object values are
25
65







5)Create a class cricket having data members player ID.player name ,no. of inning,total runs and numbers of times not out.Add necessary member functions in it.Write a C++ programme to accept the complete information of player from the user.Calculate its average of runs and display all information.Overload insertion << and extraction>> operators to accept and display information. Create array of objects for 11 players of team.

#include<iostream.h>
#include<conio.h>

class cricket
{
int pid,noi,totrun;
char name[10];
public:
cricket()
{
}
friend istream & operator>>(istream &,cricket &);
friend ostream & operator<<(ostream &,cricket &);
};

istream & operator>>(istream &obj,cricket &c)
{
obj>>c.pid;
obj>>c.noi;
obj>>c.totrun;
obj>>c.name;
return obj;
}
ostream & operator<<(ostream &obj,cricket &c)
{
obj<<c.pid<<endl;
obj<<c.noi<<endl;
obj<<c.totrun<<endl;
obj<<c.name<<endl;
return obj;
}

void main()
{
clrscr();
cricket obj[2];
cout<<”Wasim Shaikh”;
for(int i=0;i<=1;i++)
{
cout<<" enter the value of pid,noi,totrun,name for player"<<i+1<<endl;
cin>>obj[i];
}
for(i=0;i<=1;i++)
{
cout<<"player details are"<<obj[i];
}
getch();
}

Output:
enter the value of pid,noi,totrun,name for player 1: 10 405 15355 Sachin
enter the value of pid,noi,totrun,name for player 2: 99 299 8449 Sehwag
player details are:
10 405 15355 Sachin
99 299 8449 Sehwag
















6)Create a class MAT of size mXn in which define a class matrix and overload all possible operators for operation on MAT type objects(eg.+,-,*)

#include<conio.h>
#include<iostream.h>
class mat
{
int r,c;
int a[10][10];
public:
void getmat();
void putmat();
mat friend operator+(mat,mat);
mat friend operator-(mat,mat);
mat friend operator*(mat,mat);
};
void mat::getmat()
{
cout<<"Enter the rows and coloumn(r*c)=";
cin>>r;
cin>>c;
cout<<"Enter matrix="<<endl;
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
cin>>a[i][j];
}
}
}
void mat::putmat()
{
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
}
mat operator+(mat m1,mat m2)
{
mat temp;
temp.r=m1.r;
temp.c=m1.c;
for(int i=0;i<m1.r;i++)
{
for(int j=0;j<m1.c;j++)
{
temp.a[i][j]=m1.a[i][j]+m2.a[i][j];
}
}
return temp;
}
mat operator-(mat m1,mat m2)
{
mat temp;
temp.r=m1.r;
temp.c=m1.c;
for(int i=0;i<m1.r;i++)
{
for(int j=0;j<m1.c;j++)
{
temp.a[i][j]=m1.a[i][j]-m2.a[i][j];
}
}
return temp;
}
mat operator*(mat m1,mat m2)
{
mat temp;
temp.r=m2.r;
temp.c=m1.c;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
temp.a[i][j]=0;
for(int k=0;k<3;k++)
{
temp.a[i][j]=m1.a[i][j]+m2[i][k]*temp.[k][j];
}
}
}
return temp;
}
void main()
{
clrscr();
mat m1,m2,m3,m4,m5;
m1.getmat();
m2.getmat();
cout<<”Wasim Shaikh”;
m3=m1+m2;
m4=m1-m2;
m5=m1*m2;
cout<<endl<<"First matrix"<<endl;
m1.putmat();
cout<<endl<<"second matrix"<<endl;
m2.putmat();
cout<<endl<<"Addition of matrix"<<endl;
m3.putmat();
cout<<endl<<"Substraction of matrix"<<endl;
m4.putmat();
cout<<endl<<"Multiplication of matrix"<<endl;
m5.putmat();
getch();
}
Output:
Enter the rows and coloumn(r*c)=2 2
Enter matrix=5 6 7 8
Enter the rows and coloumn(r*c)=2 2
Enter matrix=1 2 3 4
First matrix
5 6
7 8
second matrix
1 2
3 4
Addition of matrix
6 8
10 12
Substraction of matrix
4 4
4 4
Multiplication of matrix
23 34
31 46