BCA 4th Sem Lab Programs
BCA 4th Sem Lab Programs
BCA 4th Sem Lab Programs
RAICHUR
PROJECT REPORT
ON
INTERNAL PROGRAMS
SUBIMITTED TO THE
GULBARGA UNIVERSITY
GULBARGA
CERTIFICATE
Reg No:-0971230
2.
EXAMINERS:
1.
2.
Place: Raichur
Date:
SL.NO NAME OF THE PROGRAMS SIGNATURE REMARKS
INDEX
C ++ PROGRAMS
GRAPHICS PROGRAMS
SL.NO NAME OF THE PROGRAMS SIGNATURE REMARK
S
2. A PROGRAM TO GENERATE A
CIRCLE USING BRESENHAM’S
ALGORITHM
#include<iostream.h>
class student
{
private:char name[20];
int roll_no;
float percentage;
public:void getdata(void)
{
cout<<"enter the name"<<endl;
cin>>name;
cout<<"enter the roll_no"<<endl;
cin>>roll_no;
cout<<"enter the percentage"<<endl;
cin>>percentage;
}
void printdata(void)
{
cout<<"roll_no="<<roll_no<<endl;
cout<<"name="<<name<<endl;
cout<<"percentage="<<percentage<<endl;
}
};
void main()
{
student boy;
boy.getdata();
boy.printdata();
}
OUTPUT
Name: ramesh
Roll.no:230
Percentage: 6808
* THE PROGRAM TO FIND NUMBER AND COST OF THE PRODUCT */
#include<iostream.h>
#include<conio.h>
class item
{
int number;
float cost;
public:
void getdata(int a,float b);
void putdata(void)
{
cout<<"number:"<<number<<"\n";
cout<<"cost:"<<cost<<"\n";
}
};
void item::getdata(int a, float b)
{
number=a;
cost=b;
}
int main()
{
item x;
clrscr();
x.getdata(100,24.65);
x.putdata();
item y;
y.getdata(200,46.34);
y.putdata();
return 0;
}
OUTPUT
Number:100
Cost: 24.65
Number: 200
Cost: 46.34
/* THE PROGRAM TO CREATE AN OBJECT FOR INITIALIZING ITS DATA
MEMBER USING ITS DEFAULT CONSTRUCTOR */
.#include<iostream.h>
class box
{
private:int length;
int height;
int width;
public:box(void)
{
length=0;
height=0;
width=0;
}
void print(void)
{
cout<<"length="<<length<<endl;
cout<<"height="<<height<<endl;
cout<<"width="<<width<<endl;
}
};
void main()
{
box bob;
bob.print();
}
OUTPUT
Length =0
Height=0
Width=0
/* THE CPP PROGRAM FOR MULTI INHERITANCE */
#include<iostream.h>
#include<conio.h>
class M
{
protected:
int m;
public:
void get_m(int x)
{
m=x;
}
};
class N
{
protected:
int n;
public:
void get_n(int y)
{
n=y;
}};
class P:public M,public N
{
public:
void display(void)
{
cout<<"m="<<m<<"\n";
cout<<"n="<<n<<"\n";
cout<<"m*n="<<m*n<<"\n";
}
};
void main()
{
P p;
p.get_m(10);
p.get_n(20);
p.display();
getch();
}
OUTPUT
M=10
N=20
M*N=200
/* THE PROGRAM USED TO ILLUSTRATES THE FRIEND FUNCTION */
#include<iostream.h>
class sample
{
int a,b;
public: void setvalue() {a=32;b=64;}
friend float mean(sample s);
};
float mean(sample s)
{
return float(s.a+s.b)/2.0;
}
int main()
{
sample x;
x.setvalue();
cout<<"mean value="<<mean(x)<<endl;
return 0;
}
OUTPUT
Mean value = 48
/* THE PROGRAM FOR STATIC CLASS MEMBER */
#include<iostream.h>
#include<conio.h>
class item
{
static int count;
int number;
public:
void getdata(int a)
{
number-a;
count++;
}
void getcount(void)
{
cout<<"count:"<<count<<"\n";
}};
int item::count;
void main()
{
clrscr();
item a,b,c;
a.getcount();
b.getcount();
a.getdata(100);
b.getdata(200);
cout<<"after reading data"<<"\n";
a.getcount();
b.getcount();
getch();
}
OUTPUT
Count:0
Count:0
After reading data
Count:2
Count:2
/* THE PROGRAM ILLUSTRATE HOW AN INTEGER CONSTRUCTED IS
DESTROYED */
#include<iostream.h>
class sample
{
private:int x;
public:sample(void)
{
x=0;
cout<<"is constructor"<<"x="<<endl;
}
void point(void)
{
x=50;
cout<<"in printx,x="<<x<<endl;
}
~sample()
{
cout<<"in destructor object dies"<<endl;
}
};
void main()
{
sample sl;
sl.point();
}
OUTPUT
Is constructed 0
In point x,x=50
#include<iostream.h>
#include<string.h>
#include<conio.h>
class employee
{
private : int employee;
char empname[20];
float salary;
public : employee (int no,char name[],float salary)
{
employee=eno;
strcpy(empname,name);
salary=sal;
}
void display(void)
{
cout<<"employee information"<<employee<<endl;
cout<<"employee code"<<employee code<<endl;
cout<<"employee name"<<employee name<<endl;
cout<<"employee salary"<<employee salary<<endl;
}};
void main()
{
clrscr();
employee emp=employee(1234,"shashi",4000);
emp display();
}
OUTPUT
Employee code:1234
Employee name:shashi
Employee salary:4000
1234
Shashi
4000
GRAPHICS
PROGRAMS
#include<stdio.h>
#include<graphics.h>
main()
{
int a,b,k;
float x,y,r,x1,y1,p;
float e,i;
detectgraph(&a,&b);
initgraph(&a,&b," ");
printf("enter coordinates for center point\n");
scanf("%f%f",&x1,&y1);
printf("enter radius for circle\n");
scanf("%f",&r);
x=y=r;
e=0.0125;
k=1;
putpixel(x+x1,y+y1,3);
for(i=1;i<=100;i=i+0.01)
{
putpixel(x+x1,y+y1,k++);
p=x;
x=x+e*y;
y=y-e*p;
}
getch();
closegraph();
}
OUTPUT
Enter the co-ordinates for center point
20
30
Enter the radius of the circle
10
/* THE PROGRAM TO DRAW A LINE USING DDA ALGORITHM */
#include<stdio.h>
#include<graphics.h>
#include<math.h>
main()
{
int x0,y0,x1,y1,x2,y2,l,i,a,b,x,y;
detectgraph(&a,&b);
initgraph(&a,&b," ");
printf("enter the values of x1,y1,x2,y2\n");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
l=abs(y2-y1);
if(abs(y2-y1)>l)
{
l=abs(y2-y1);
}
x0=(x2-x1)/l;
y0=(y2-y1)/l;
x=x1+0.5;
y=y1+0.5;
for(i=1;i<=i+1;i++)
{
putpixel(x,y,3);
x=x+x0;
y=y+y0;
}
getch();
closegraph();
}
OUTPUT
Enter the values of x1,y1,x2,y2
30
60
40
80
/* THE PROGRAM TO DRAW AN ELLIPSE */
#include<stdio.h>
#include<graphics.h>
main()
{
int a,b,x,y,stang,endang,xrad,yrad;
detectgraph(&a,&b);
initgraph(&a,&b," ");
printf("enter x,y,stang,endang,xrad,yrad\n");
scanf("%d%d%d%d%d%d",&x,&y,&stang,&endang,&xrad,&yrad);
ellipse(x,y,stang,endang,xrad,yrad);
getch();
closegraph();
}
OUTPUT
Enter the x,y,stang,endang, xrad,yrad
120
160
360
60
100
80
/* THE PROGRAM TO DRAW A PATTERN */
#include<stdio.h>
#include<graphics.h>
main()
{
int a,b;
detectgraph(&a,&b);
initgraph(&a,&b," ");
setcolor(4);
ellipse(250,250,0,360,150,50);
ellipse(250,250,0,360,50,150);
setcolor(2);
ellipse(400,250,90,180,150,150);
ellipse(250,100,270,360,150,150);
ellipse(250,100,180,270,150,150);
ellipse(100,250,0,90,150,150);
ellipse(100,250,270,360,150,150);
ellipse(250,400,90,180,150,150);
ellipse(250,400,0,90,150,150);
ellipse(400,250,180,270,150,150);
getch();
closegraph();
}
OUTPUT
/* THE PROGRAM TO PERFORM SCALING */
#include<stdio.h>
#include<graphics.h>
main()
{
int a,b;
float x1,y1,x2,y2;
detectgraph (&a,&b);
initgraph (&a,&b," ");
x1=100;
y1=100;
x2=200;
y2=200;
rectangle(x1,y1,x2,y2);
x1=x1*0.5;
y1=y1*0.5;
x2=x2*1.2;
y2=y2*1.2;
rectangle(x1,y1,x2,y2);
getch();
closegraph();
}
OUTPUT
*/ THE PROGRAM TO DRAW A LINE USING BRESHENHAMS */
#include<stdio.h>
#include<graphics.h>
#include<math.h>
main()
{
int x,y,dx,dy,e,a,b,i;
detectgraph(&a,&b);
initgraph(&a,&b," ");
printf("enter the values of x,y,dx,dy\n");
scanf("%d%d%d%d",&x,&y,&dx,&dy);
for(i=1;i<=dx;i++);
{
putpixel(x,y,3);
e=0.001;
if(e>0)
{
y=y+1;
e=e-1;
}
x=x+1;
e=e+dy/dx;
}
getch();
closegraph();
}
OUTPUT
Enter the values of x,y,dx,dy
20
40
80
60
/*PROGRAM TO FIND A BEZIER CURVE*/
#include<stdio.h>
#include<graphics.h>
#include<math.h>
main()
{
float n,m,i,k,j;
int a,gd,gm,x[20],y[20];
float p,t,c,d,v,v2,u;
float bnt (int);
detectgraph (&gd,&gm);
initgraph (&gd,&gm," ");
printf("enter the number control points\n");
scanf("%f",&m);
n=m-1;
printf("enter the control points\n");
for(i=0;i<=n;i++)
{
scanf("%d%d",&x[i],&y[i]);
circle (x[i],y[i],2);
}
outtextxy (150,150,"bezier curve");
for(i=0;i<=n;i++)
line (x[i],y[i],x[i+1],y[i+1]);
for(i=0.0009;i<=500;i++)
{
t=(float)(i)/500.0;
c=0.0;
d=0.0;
for(j=0;j<=n;j++)
{
v=pow(t,j)*pow(1-t,n-j)*bnt(n)/(gd+gm)*bnt(n-j);
c=c+v*x[j];
d=d+(y[i]*v);
}
if(i==0)
moveto (c,d);
else
putpixel (c,d,7);
}
getch();
}
float bnt (int n)
{
int j;
float s=1.0;
for (j=1;j<=n;j++)
s=s*j;
return(s);
}
OUTPUT