bca 4th sem lab programs
TRANSCRIPT
VIJAYANAGARA BCA COLLEGE RAICHUR
PROJECT REPORT
ON
INTERNAL PROGRAMS
SUBIMITTED TO THE GULBARGA UNIVERSITY
GULBARGA
IN THE PARTIAL FOR THE AWARD OF
BACHELOR OF COMPUTERBACHELOR OF COMPUTER APPLICATIONAPPLICATION
(BCA)BY
GOPISETTY SHIVA PRASADRAICHUR
2009-2010
VIJAYANAGARA BCA COLLEGERAICHUR
CERTIFICATE
Reg No:-0971230
This is to certify that MR. GOPISETTY SHIVA PRASAD has satisfactorily completed the course of programming in practical by the GULBARGA UNIVERSITY, GULBARGA FOR BCA IV semester in laboratory of this department during the year 2009-2010.
STAFF MEMBER IN-CHARGE PRINCIPAL1.
2.
EXAMINERS:
1.
2.
Place: Raichur
Date:
SL.NO NAME OF THE PROGRAMS SIGNATURE REMARKS
1. THE PROGRAM TO GET INFORMATION ABOUT STUDENTS
2. THE PROGRAM TO FIND NUMBER AND COST OF THE PRODUCT
3. THE PROGRAM TO CREATE AN OBJECT FOR INITIALIZING ITS DATA MEMBER USING ITS DEFAULT CONSTRUCTOR
4. THE CPP PROGRAM FOR MULTI INHERITANCE
5. THE PROGRAM USED TO ILLUSTRATES THE FRIEND FUNCTION
6. THE PROGRAM FOR STATIC CLASS MEMBER
7. THE PROGRAM ILLUSTRATE HOW AN INTEGER CONSTRUCTED IS DESTROYED
8. THE PROGRAM FOR STRING
INDEXC ++ PROGRAMS
GRAPHICS PROGRAMSSL.NO NAME OF THE PROGRAMS SIGNATUR
EREMARKS
1. THE PROGRAM TO DRAW A LINE USING INTEGER ALGORITHM
2. A PROGRAM TO GENERATE A CIRCLE USING BRESENHAM’S ALGORITHM
3. THE PROGRAM TO DRAW A LINE USING DDA ALGORITHM
4. THE PROGRAM TO DRAW AN ELLIPSE
5. THE PROGRAM TO DRAW A PATTERN
6. THE PROGRAM TO PERFORM SCALING
7. THE PROGRAM TO DRAW A LINE USING BRESHENHAMS
8. PROGRAM TO FIND A BEZIER CURVE
C++
PROGRAMS
/* THE PROGRAM TO GET INFORMATION ABOUT STUDENTS */
#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:0Count:0After reading dataCount:2Count: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();}
OUTPUTIs constructed 0
In point x,x=50
In destructor object dies.
/* THE CPP PROGRAM FOR STRING */
#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();}
OUTPUTEmployee code:1234Employee name:shashiEmployee salary:4000
1234Shashi4000
GRAPHICS PROGRAMS
/* THE PROGRAM TO DRAW A LINE USING INTEGER ALGORITHM */
#include<stdio.h>#include<graphics.h>main(){int a,b;float e,x,y,dx,dy;float i;detectgraph(&a,&b);initgraph(&a,&b," ");printf("input x,y,dy,dx\n");scanf("%f%f%f%f", &x,&y,&dy,&dx);e=2*dy-dx;for(i=1;i<=dx;i=i++);{putpixel(x,y,3);if(e>0){y=y+1;e=e+(2*dy-2*dx);}else{e=e+2*dy;}x=x+1;}getch();closegraph();}
OUTPUT
Input x,y,dy,dx20604080
/* A PROGRAM TO GENERATE A CIRCLE USING BRESENHAM’S ALGORITHM */
#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 point2030Enter the radius of the circle10
/* 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,y230604080
/* 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,yrad1201603606010080
/* 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();}
OUTPUTEnter the values of x,y,dx,dy20408060
/*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);elseputpixel (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
Enter the number of control points6Enter the control points320280240320280240160120160220260220