Saturday, 24 March 2018

To Add Own Header File in C++

"Nice One Program"

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

void main()                
{         clrscr();
int a=10,b=20;
int c=sum(a,b);                 //no prototype now create new file with extension .h
cout<<"Sum="<<c;      //again error now include file using ""

getch();
}


FILE WITH .H Exntension Will Have

int sum(int x,int y)
{
return (x+y);
}


Tuesday, 6 March 2018

Program For Copy Constructor

"Nice one Program"

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class point  {
public:          int x,y;
point() {x=0,y=0;        }
point(point &p)
{ x=p.x;
  y=p.y;
}

};
void main()
{clrscr();
point p1,p2;
p1.x=10;
p1.y=20;
p2=p1; //copy constructor called here
cout<<"p2.x="<<p2.x<<endl;
cout<<"p2.y="<<p2.y;
getch();

}



Assignment Operator Overloading ( +=)

"Nice One Program"

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

class rv{ public:
int inch,feet;
rv(){ inch=0,feet=0;

}
void operator +=(rv dis)
{
feet=feet+dis.feet;
inch=inch+dis.inch;
if(inch>=12)
{ feet+=inch/12;
  inch%=12;

}


}};

void main()
{       clrscr();
rv dis1,dis2;
cout<<"Enter dis1: ";
cin>>dis1.feet;
cin>>dis1.inch;
cout<<"\nEnter dis2: ";
cin>>dis2.feet;
cin>>dis2.inch;
dis1+=dis2;

cout<<"\n Value of feet: "<<dis1.feet;
cout<<"\n value of inch:"<<dis1.inch;
getch();

}


Operator Overloading

Adding Two Objects

"Nice One Program"

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

class rv{ public:
int val;
rv(){ val=1;

}
rv operator +(rv ss)
{     cout<<"func called Will returb object\n";
rv temp;
temp.val=val+ss.val;
return temp;
}};

void main()
{       clrscr();
rv obj1,obj2,obj3;

obj3=obj1+obj2;
cout<<"\n Value of obj3: "<<obj3.val;
getch();
}


Operator Overloading:-

Concatination of Two Strings

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<iostream.h>
#include<string.h>
class rv{ public:
char str[20];
rv(){ strcpy(str," ");

}
rv(char s[])
{
strcpy(str,s);
}
rv operator +(rv ss) const
{     cout<<"func called\n";
rv temp;
if((strlen(str)+strlen(ss.str))<20)
{   strcpy(temp.str,str);
    strcat(temp.str,ss.str);
}
else
cout<<"Overflow";
return temp;
}
};

void main()
{       clrscr();
rv st1="hello",st2=" ravi",st3;

st3=st1+st2;
cout<<st3.str;
getch();
}



Friday, 29 December 2017

Semester Working Days Calculator

Simple C,C++ Project (Program to Calculate Semester Working Days)

"Nice One Program"


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

void main()
{     clrscr();
int start,s1,end,e1,yr,tdays;    
                                                 
int tdwork; //total working days
int lp=0;
char *month[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
int days[]={31,28,31,30,31,30,31,31,30,31,30,31}; //days of mnth

cout<<"\n     -->Winter Project<--\n\n";
cout<<"Enter Start and End Month\n";
for(int i=0;i<12;i++)
{
cout<<month[i]<<" As "<<i+1<<endl;
}

cout<<"Enter:";
cin>>start>>end;
{ cout<<"\nEnter Year:"; cin>>yr;
if(yr%4==0) //for leap yr check
lp=1;
}
cout<<"\nEnter Start Date of Month <"<<month[start-1]<<">:";
cin>>s1;
cout<<"\nEnter End Date of Month <"<<month[end-1]<<">:";
cin>>e1;

{
//For TOTALdays
int l1=days[start-1]-s1;
int l2=days[end-1]-e1;
tdays=l1+l2;
for(i=start;i<end-1;i++)
tdays+=days[i];
//***** TOTAL DAYS ARE HERE cout<<"totl days""<tdays;      ****************

}
int tweek;
tweek=tdays/7;

//Removing All Holidays And Other days


{     tdwork=tdays-2*tweek;
      int gzdays[]={4,1,1,3,1,1,1,3,1,3,3,1};   //Gazzeted Holidays Each month

      //Removing leap Year
      {
if(lp)
tdays++;
      }
     int flag=start;      //bcoz of index value

     //Next Lines For Start sem Month Holidays
     { if(e1>=15)
      { if(gzdays[start-1]>=2)
       tdwork=tdwork-(gzdays[start-1]-1);     //that 1 holidays less
      }
      else
      tdwork=tdwork-(gzdays[start-1]);

     }
     //Removing holidays from Inbetween Months
       while(flag<end-1)          // minus 1 coz will work less than index
      {

tdwork=tdwork-gzdays[flag];
flag++;

      }

     //Removing Holidays Of last Month
     {
if(e1>=15)
{
  if(gzdays[end-1]>=2)
  tdwork=tdwork-(gzdays[end-1]-1);
}
else
tdwork=tdwork-(gzdays[end-1]);

     }

}

if(lp)                                //For Leap Year
cout<<"\nTotal Days:"<<tdays<<" (Leap Year)";
else
cout<<"\nTotal Days:"<<tdays;
cout<<"\nTotal Weeks:"<<tweek;


cout<<"\n\nTotal Working Days:"<<tdwork;
cout<<"\nTotal Holidays:"<<tdays-tdwork;
cout<<"\nTotal Gazzeted Holidays:"<<(tdays-tdwork)-(2*tweek);
endl;

getch();
}





Thursday, 7 December 2017

PROGRAM SELECTION SORT

"Nice One Program"


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

void main()
{       clrscr();
 int *a,i,n,j,temp;
cout<<"Enter numbr of elements:";
cin>>n;
a=new int[n];
cout<<"enter elemnts:";
for(i=0;i<n;i++)
cin>>a[i];

cout<<"\n\nelements Before sorting:";
for(i=0;i<n;i++)
cout<<a[i]<<" ";

for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;

}


cout<<"\n\nElemnts aftr selction sortng:";
for(i=0;i<n;i++)
cout<<a[i]<<" ";


getch();

}