Shorted Bharathiar University C ++ Practical Programs for MCA 2nd year students

 Shorted Bharathiar University C ++ Practical Programs for MCA 2nd year students



To Download This Program as a Document Click the below Download button to download. 




C++ Programs List

1)To Perform Arithmetic And Relational Operators 
    Using  Operator Overloading.
 
2)To Convert From Basic Data Type To Class Type
   And Class Data Type To   Basic  Data Type Using
   Type  Conversion.

3)To Implement String Copy ,String Length, Reverse   
    of  String Without  String Function.

 4)Pay Roll Using File Concept

5)Minimum and Maximum Using Template
6)Mark Statement Using Hybrid Inheritance
7)  To Implement Polymorphism Using Integer 
     Series And  Countries Currency Class.

8)Finding Area Of Circle Using Friend Function
9)Matrix Manipulation using Pointer
10)Random Access Files
 
Programs



Program-1
(Operator Overloading)
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
class opera
{
int a,b;
public:
void input();
void output();
opera operator *(opera ob1);
void operator <(opera ob2);
};
void opera::input()
{
cout<<"\nEnter The Value For A and B:";
cin>>a>>b;
}
void opera::output()
{
cout<<"\nA="<<a<<"\tB="<<b;
}
opera opera::operator *(opera ob1)
{
opera t;
t.a=a*ob1.a;
t.b=b*ob1.b;
return t;
}
void opera::operator<(opera ob2)
{
if((a<ob2.a)&&(b<ob2.b))
cout<<"\nA is Lessthen B";
else if((a>ob2.a)&&(b>ob2.b))
cout<<"\nB is Lessthen A";
else
cout<<"\nInvalid No";
}
void main()
{
opera obj1,obj2;
int opt;
clrscr();
for(;;)
{
cout<<"\nOperating Overloading\n**************************";
cout<<"\n1.Arith\n2.Relational\n3.exit";
cout<<"\nEnter Your choice: ";
cin>>opt;
switch(opt)
{
case 1:
cout<<"\n\tArith";
obj1.input();
obj2.input();
opera obj3;
obj3=obj1*obj2;
obj3.output();
break;
case 2:
cout<<"\nRelational ";
obj1.input();
obj2.input();
obj1<obj2;
break;
case 3:
exit(0);
break;
default:
cout<<"\nYour Choice Is Wrong Enter Right no";
}
}
}
Program-2
(Type Conversion)
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
#include<dos.h>
class sint
{
long int p,n,r;
double si;
public:
sint()
{
si=p=n=r=0;
}
sint(long int pi)
{
p=pi;
n=2;
r=5;
}
void output()
{
si=(p*n*r)/100;
cout<<"\nInterst Is :"<<si;
}
operator double()
{
return si;
}
};
void main()
{
int opt;
clrscr();
for(;;)
{
clrscr();
cout<<"\nType Conversion";
cout<<"\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
cout<<"\n1.from Basic Type to Class";
cout<<"\n2.From Class Type to Basic";
cout<<"\n3.Exit";
cout<<"\nEnter Your Choice: ";
cin>>opt;
switch(opt)
{
case 1:
cout<<"\nType Conversion\n~~~~~~~~~~~~~~~~~~~~~~~";
cout<<"\nFrom Basic Type To Class Type ";
sint siob;
int amt;
cout<<"\nEnter the value for Principle Amount:";
cin>>amt;
siob=amt;
siob.output();
sleep(3);
break;
case 2:
cout<<"\nType Conversion\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
cout<<"\nFrom Class Type To Basic Type ";
sint ob;
ob=25466;
double irt=ob;
cout<<"\nInterst Is: "<<irt;
sleep(3);
break;
case 3:
cout<<"\nSuccessfully Logout";
exit(0);
default:
cout<<"\nYour are Entered Wrong Value";
sleep(3);
}
}
}
Program-3
(String Manipulation)
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
char str1[20],str2[20];
void strlength();
void strcomp();
void strcopy();
void strreverse();
void main()
{
int opt;
clrscr();
for(;;)
          {
cout<<"\n\tString Manipulation\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
cout<<"\n1.To String Length";
cout<<"\n2.To String Copy";
cout<<"\n3.To String Reverse";
cout<<"\n4.Exit";
cout<<"\nEnter Your Choice:";
cin>>opt;
switch(opt)
{
case 1:
cout<<"\n\tString Length";
strlength();
break;
case 2:
cout<<"\n\tString Copy";
strcopy();
break;
case 3:
cout<<"\n\tReverse Of The String";
strreverse();
break;
case 4:
exit(0);
default:
cout<<"\nYou Entered Wrong Value Enter Right keyword";
}
}
}
void strlength()
{
cout<<"\nEnter THe String: ";
cin>>str1;
int i=0,len=0;
while(str1[i]!='\0')
{
len=len+1;
i++;
}
cout<<"\nThe Given String is :"<<str1;
cout<<"\nLength Of The String:"<<len;
}
void strcopy()
{
cout<<"\nEnter The First String:";
cin>>str1;
int i=0;
while(str1[i]!='\0')
{
str2[i]=str1[i];
i++;
}
str2[i]='\0';
cout<<"\nThe Given String Is:"<<str1;
cout<<"\nThe Copied String Is :"<<str2;
}
void strreverse()
{
cout<<"\nEnter The String:";
cin>>str1;
cout<<"\nThe Given String Is :"<<str1;
int i=0,len=0;
while(str1[i]!='\0')
{
len=len+1;
i++;
}
cout<<"\nReverse Of The String: ";
for(i=len;i>=0;i--)
cout<<str1[i];
}
Program-4
(Pay Roll Using File Concept)
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<dos.h>
#include<math.h>
class emp
{
int empno,bpay;
float da,hra,ta,lic,ded,npay,gpay,allow,pf;
char ename[20];
public:
emp()
{
ta=hra=da=lic=pf=ded=npay=gpay=allow=0;
}
void get();
void put();
void calc();
};
void emp:: get()
{
cout<<"\nEnter The Empno and Name and BasicPay: ";
cin>>empno>>ename>>bpay;
}
void emp::calc()
{
da=abs(bpay*80/100);
hra=abs(bpay*30/100);
ta=abs(bpay*20/100);;
pf=abs(bpay*12/100);;
lic=abs(bpay*5/100);
ded=abs(lic+pf);
allow=abs(allow+da+hra+ta);
gpay=abs(bpay+allow);
npay=abs(gpay-ded);
}
void emp::put()
{
clrscr();
cout<<"\nPayRoll";
cout<<"\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
cout<<"\nEmployeeNumber: "<<empno<<"\nName:
        <<ename <<"\nBasicPay: "<<bpay;
cout<<"\nAllowance: "<<allow<<"\nDection: "<<ded
        <<"\nNetpay: "<<npay;<<"\nGrossPay:"<<gpay
        <<"\n~~~~~~~~~~~~~~~~~~~~~~~";
}
void main()
{
emp e;
char opt;
fstream fob;
clrscr();
fob.open("emp.dat",ios::in|ios::out|ios::app);
do
{
e.get();
fob.write((char*)&e,sizeof(e));
cout<<"\nDo you Wnat TO Continue(y/n):";
cin>>opt;
}while(opt=='Y'||opt=='y');
clrscr();
fob.seekg(0);
fob.read((char*)&e,sizeof(e));
while(!fob.eof())
{
e.calc();
e.put();
fob.read((char*)&e,sizeof(e));
}
getch();
}
Program-5
(Minimum and Maximum Using Template)
#include<iostream.h>
#include<conio.h>
template<class x>void minmax(x a1[],int n)
{
x min,max;
min=max=a1[0];
for(int i=0;i<n;i++)
{
if(a1[i]<min)
{
min=a1[i];
}
if(a1[i]>max)
{
max=a1[i];
}
}
cout<<"\n\nMaximum ="<<max<<"\tMinimax ="<<min;
};
void main()
{
int a[10],n,i;
clrscr();
cout<<"\nEnter The Value for n: ";
cin>>n;
cout<<"\nEnter "<<n<<"Integer Value one by one:";
for(i=0;i<n;i++)
cin>>a[i];
cout<<"\nGiven Value For Integer Array:";
for(i=0;i<n;i++)
cout<<a[i]<<"\n";
cout<<"\nMaximum And Minimum Values In Integer Array";
minmax(a,n);
double b[10];
cout<<"\nEnter The Value For n: ";
cin>>n;
cout<<"\nEnter "<<n<<" Float value one by one";
for(i=0;i<n;i++)
cin>>b[i];
cout<<"\nGiven Values For Float Array: ";
for(i=0;i<n;i++)
cout<<b[i]<<"\n";
cout<<"\nMaximum and Minimum Value In Float Array";
minmax(b,n);
getch();
}
Program-6
(Mark Statement Using Hybrid Inheritance)
#include<iostream.h>
#include<conio.h>
#include<string.h>
int i=0,x=5,y=5;
class base
{
protected:
int rno;
char name[20];
char scode[5][5],sname[5][20];
public:
void input();
void output();
};
class internal:public virtual base
{
protected:
int intmar[5];
public:
void input2();
void output2();
};
class external:public base
{
protected:
int extmar[5];
public:
void input3();
void output3();
};
class result:public internal,public external
{
int tot[5];
char rst[5][5];
public:
void process();
void display();
};
void base::input()
{
cout<<"\nEnter Rno and Name:";
cin>>rno>>name;
cout<<"Enter 5 Subject Codes and subject names:";
for(i=0;i<5;i++)
cin>>scode[i]>>sname[i];
}
void internal::input2()
{
input();
cout<<"\nEnter 5 Subject Internal Marks";
for(i=0;i<5;i++)
cin>>intmar[i];
}
void external::input3()
{
cout<<"\nEnter The External Marks";
for(i=0;i<5;i++)
cin>>extmar[i];
}
void base::output()
{
cout<<"\nReg no:"<<rno;
cout<<"\nNmae:"<<name;
cout<<"\nSubject Code:";
for(i=0;i<5;i++)
cout<<scode[i]<<" ";
cout<<"\n Subject Names:";
for(i=0;i<5;i++)
cout<<sname[i]<<" " ;
}
void internal::output2()
{
output();
cout<<"\nInternal Marks";
for(i=0;i<5;i++)
cout<<"\n"<<intmar[i]<<" ";
}
void external::output3()
{
cout<<"\nExternal Marks";
for(i=0;i<5;i++)
cout<<"\n"<<extmar[i]<<" ";
}
void result::display()
{
output3();
cout<<"\nTotal Marks:";
for(i=0;i<5;i++)
cout<<tot[i]<<" ";
cout<<"\nResult     :";
for(i=0;i<5;i++)
cout<<rst[i]<<" ";
}
void result::process()
{
int j;
for(j=0;j<5;j++)
tot[j]=0;
for(j=0;j<5;j++)
{
tot[j]=tot[j]+intmar[j]+extmar[j];
if(intmar[j]>11&&extmar[j]>37&&tot[j]>49)
strcpy(rst[j],"pass");
else
strcpy(rst[j],"Fail");
}
}
void main()
{
result ob;
clrscr();
ob.input2();
ob.input3();
ob.process();
clrscr();
cout<<"\nStudent Result Is Processed";
ob.output2();
ob.display();
getch();
}
Program-7
(Polymorphism)
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
class base
{
public:
virtual void input()=0;
virtual void output()=0;
};
class insert:public base
{
int n,sum1,sum2,sum3;
public:
void input();
void output();
};
class currence:public base
{
float uk,irp,us,ero,pk,chi,quwt,sri;
public:
void input();
void output();
};
class percom:public base
{
int n,r;
long int ncr,npr,fact;
public:
void input();
int facto(int n1);
void output();
};
void insert::input()
{
cout<<"\Enter Value For n:";
cin>>n;
}
void insert::output()
{
sum1=sum2=sum3=0;
sum1=sum1+n*(n+1)/2;
sum2=sum2+n*(n+1)*(2*n+1)/6;
sum3=sum3+sqrt(n*(n+1));
cout<<"\n\t1+2+3...........+"<<n<<":="<<sum1;
cout<<"\n\t1^2+2^2+3^2...........+"<<n<<"^2:="<<sum2;
cout<<"\n\t1^3+2^3+3^3...........+"<<n<<"^3:="<<sum3;
}
void percom::input()
{
cout<<"\n\tEnter The Value for n(object) and r(time): ";
cin>>n>>r;
}
void currence::input()
{
cout<<"\nENter The amount Of Indian Currency:";
cin>>irp;
}
void currence::output()
{
uk=irp/99.73;
us=irp/62.17;
ero=irp/84.16;
pk=irp/0.59;
sri=irp/0.47;
quwt=irp/219.36;
chi=irp/10.16;
cout<<"\nIndian Reupees .........:"<<irp;
cout<<"\nEqulient Uk Bound: "<<uk;
cout<<"\nEqulient Us Dollor: "<<us;
cout<<"\nEqulient Europ Rate: "<<ero;
cout<<"\nEqulient Kuwail Dinar: "<<quwt;
cout<<"\nEqulient China Rupee: "<<chi;
cout<<"\nEqulient Pakisthan Rupee: "<<pk;
cout<<"\nEqulient Sirlank Rupee: "<<sri;
}
void main()
{
int opt;
base *pt;
for(;;)
          {
clrscr();
cout<<"\n\tPolymorphisam With Virtual Function";
cout<<"\n\t\t1.Integer Series";
cout<<"\n\t\t2.Contrieses Currenices:";
cout<<"\n\t\t3.Exit";
cout<<"\nEnter Your Choice: ";
cin>>opt;
switch(opt)
{
case 1:
cout<<"\n\t Integer Series";
insert ob1;
pt=&ob1;
pt->input();
pt->output();
getch();
break;
case 2:
cout<<"\nContries and Currencies";
currence ob3;
pt=&ob3;
pt->input();
pt->output();
getch();
break;
case 3:
exit(0);
break;
default:
cout<<"\nEntered Wrong value";
}
}
}
Program-8
(Finding Area Of Circle Using Friend Function)
#include<iostream.h>
#include<conio.h>
#define pi 3.4;
class circ;
class rect
{
float l,b;
float ar;
public:
rect(float x,float y);
friend float area(rect r,circ c);
};
class circ
{
float r,ar;
public:
circ(float ra);
friend float area(rect r,circ c);
}
rect::rect(float x,float y)
{
l=x;
b=y;
ar=l*b;
}
circ::circ(float ra)
{
r=ra;
}
float area(rect r,circ c)
{
float a=r.ar-c.ar;
return a;
}
void main()
{
rect obr(12,15);
circ obc(5);
clrscr();
cout<<"\nAre Outside The Circle: "<<area(obr,obc);
getch();
}
Program-9
(Matrix Using Pointer)
#include<iostream.h>
#include<conio.h>
#include<process.h>
int **malloc(int ro,int col);
void disp(int **a,int raw,int col);
void matmult(int **a,int m,int n,int **b,int p,int q,int **c);
void matread(int **a,int row,int col);
void memfree(int **p,int ro);
void main()
{
int **a,**b,**c,m,n,p,q;
clrscr();
cout<<"\nEnter Matrix A Details:";
cin>>n>>m;
a=malloc(n,m);
matread(a,m,n);
cout<<"\nEnter Matrix B Details:";
cin>>p>>q;
b=malloc(p,q);
matread(b,p,q);
c=malloc(m,q);
matmult(a,m,n,b,p,q,c);
cout<<"\nMatrix A("<<n<<"*"<<m<<")";
disp(a,m,n);
cout<<"\nMatrix B("<<p<<"*"<<q<<")";
disp(b,p,q);
cout<<"\nMatrix C=A*B";
disp(c,n,q);
getch();
}
void disp(int **a,int row,int col)
{
int i,j;
for(i=0;i<row;i++)
{
cout<<endl;
for(j=0;j<col;j++)
cout<<a[i][j]<<"\t";
}
}
int **malloc(int ro,int col)
{
int **p;
p=new int*[20];
for(int i=0;i<ro;i++)
p[i]=new int[col];
return p;
}
void memfree(int **p,int ro)
{
for(int i=0;i<ro;i++)
delete p[i];
delete p;
}
void matread(int **a,int row,int col)
{
int i,j;
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
cout<<"\nMatrix ["<<i<<","<<j<<"]=";
cin>>a[i][j];
}
}
}
void matmult(int **a,int m,int n,int **b,int p,int q,int **c)
{
int i,j;
if(n!=p)
{
cout<<"\nError Invalid Matrix Order: ";
exit(1);
getch();
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
c[i][j]=0;
c[i][j]=a[i][j]*b[i][j];
}
}
}
Program-10
(Random Access Files)
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
class stu
{
int rno;
char name[15];
public:
void get()
{
cout<<"\nEnter The Rno,name:";
cin>>rno>>name;
}
void put()
{
cout<<"\nReg no:"<<rno<<"\tName:"<<name;
}
};
void main()
{
clrscr();
char opt;
stu s;
fstream f;
f.open("stud.dat",ios::in|ios::out|ios::app);
do
{
clrscr();
s.get();
f.write((char *)&s,sizeof(s));
cout<<"\n Do you Wnat To Continue(y/n): ";
cin>>opt;
}while(opt=='Y'||opt=='y');
f.seekg(0,ios::cur);
int p=f.tellg();
int nr=p/sizeof(s);
cout<<"\n"<<nr<<" Record in the file";
cout<<"\nEnter the record no:";
int n;
cin>>n;
int po=(n-1)*sizeof(s);
f.seekg(po);
f.read((char *)&s,sizeof(s));
s.put();
getch();
}

SHARE

Milan Tomic

Hi. I’m Designer of Blog Magic. I’m CEO/Founder of ThemeXpose. I’m Creative Art Director, Web Designer, UI/UX Designer, Interaction Designer, Industrial Designer, Web Developer, Business Enthusiast, StartUp Enthusiast, Speaker, Writer and Photographer. Inspired to make things looks better.

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment