Sunday, 10 April 2016

Program to draw circle using Cartesian coordinates

C++ program to draw a circle using Cartesian Coordinates technique 

Solution:

#include<iostream.h>
#include<graphics.h>
#include<conio.h>
#include<math.h>
void main()
{
int xc, yc, x, y, r;
cout<<"please enter center point of the circle";
cin>>xc>>yc;
cout<<"please enter the radius of the circle";
cin>>r;
int gd=DETECT, gm;
initgraph(&gd,&gm, "..\\bgi");
for(x=r-xc; x<=r+xc; x++)
{
y=yc+sqrt((r*r-(x-xc)*(x-xc)));
putpixel(x,y, RED);
y=yc-sqrt((r*r-(x-xc)*(x-xc)));
putpixel(x,y, BLUE);
}
getch();
}




output: 



Solution of homework 2

Write a C++ Program to print start on the screen.

Solution: 
#include<iostream.h>
#include<graphics.h>
#include<conio.h>
void main()
{
int x1,x2,x3,x4,x5,y1,y2,y3,y4,y5;
cout<< "please enter 1st point coordinates";
cin>>x1>>y1;
cout<< "please enter 2nd point coordinates";
cin>>x2>>y2;
cout<< "please enter 3rd point coordinates";
cin>>x3>>y3;
cout<< "please enter 4th point coordinates";
cin>>x4>>y4;
cout<< "please enter 5th point coordinates";
cin>>x5>>y5;
int gd=DETECT, gm;
initgraph(&gd,&gm, "..\\bgi");
line(x1,y1,x2,y2); getch();
line(x3,y3,x4,y4); getch();
line(x3,y3,x5,y5); getch();
line(x1,y1,x4,y4); getch();
line(x2,y2,x5,y5); getch();
Output: 
















 

Solution of homework 1

Write a C++ Program to print the entire screen with BROWN color.
in my case Screen Size: 600*480

Solution:
 #include<iostream.h>
#include<graphics.h>
#include<conio.h>
void main()
{
cout<<"Program to print entire screen with BROWN color";
int gd=DETECT, gm;
initgraph(&gd,&gm, "..\\bgi");
for(int x=0;x<600; x++)
for(int y=0; y<480;y++)
{
putpixel(x,y, BROWN);
 }
getch();

}


Output