Friday, 6 February 2015


Assignment no: 02

//Aim:Writing a C++ class for displaying pixel or point on the screen.

#include<iostream>

#include<graphics.h>

using namespace std;

class pixel

{

private:

int xc,yc,cl;

public:

pixel()

{

xc=yc=0;

cl=15;

}

void setcor(int x,int y)

{

xc=x;

yc=y;

}

void setcolor(int p)

{

cl=p;

}


void draw()

{

putpixel(xc,yc,cl);

}

};

int main()

{

int x1,y1,cl1,ch;

char a;

int gd=DETECT,gm=VGAMAX;

initgraph(&gd,&gm,NULL);

pixel p1;

do

{

cout<<" 1.PIXEL BY HARDCOADED VALUE..";

cout<<"\n2.ACCEPTING CO-ORDINATES..";

cout<<"\n3.DRAWING PIXEL ON SCREEN..";

cout<<"\nEnter your choice??";

cin>>ch;

switch(ch)

{

case 1:

p1.setcor(50,50);

p1.setcolor(2);

p1.draw();

break;

case 2:

cout<<"\nEnter Your X & Y co-ordinates??";

cin>>x1>>y1;

p1.setcor(x1,y1);

cout<<"\nEnter Color For Pixel??";

cin>>cl1;

p1.setcolor(cl1);

break;

case 3:

p1.draw();

break;

}

cout<<"\nDO U Want To Continue y OR n??";

cin>>a;

}while(a!='n');

getch();

closegraph();

return 0;

}

No comments:

Post a Comment