C++ menu-driven program to draw the thick, thin, and dotted line
kw.cpp
#include<graphics.h>
#include<iostream>usingnamespacestd;classt_thin_d{intx,y,x1,x2,y1,dx,dy,y2,xinc,yinc;floatm,step,k;public:voidgetdata();voidcalc();voiddraw();voiddraw1();voiddraw2();};voidt_thin_d::getdata(){cout<<"Enter the x1 coordinate ";cin>>x1;cout<<"Enter the y1 coordinate ";cin>>y1;cout<<"Enter the x2 coordinate ";cin>>x2;cout<<"Enter the y2 coordinate ";cin>>y2;}voidt_thin_d::calc(){dx=x2-x1;dy=y2-y1;m=dy/dx;if(m<1){step=dx;}else{step=dy;}xinc=(dx/step);yinc=(dy/step);}voidt_thin_d::draw(){x=x1;y=y1;intgd=DETECT,gm=VGAMAX;initgraph(&gd,&gm,NULL);putpixel(x,y,15);for(k=1;k<step;k++){x=x+xinc;y=y+yinc;putpixel(x,y,15);}}voidt_thin_d::draw1(){x=x1;y=y1;intgd=DETECT,gm=VGAMAX;initgraph(&gd,&gm,NULL);putpixel(x,y,15);for(k=1;k<step;k++){x=x+xinc+4;y=y+yinc+4;putpixel(x,y,15);}}voidt_thin_d::draw2(){for(intj=1;j<=3;j++){putpixel(x1+j,y1,15);}for(inti=1;i<=step;i++){x1=x1+xinc;y1=y1+yinc;putpixel(x1,y1,15);for(intj=1;j<=3;j++){putpixel(x1+j,y1,15);}}}intmain(){intgd=0,gm,ch;t_thin_dT;do{cout<<"———————————————————————————————————————————";cout<<"\nC++ program for the thick, thin, dotted line";cout<<"\n———————————————————————————————————————————";cout<<"\n1.Thin Line";cout<<"\n2.Dotted Line";cout<<"\n3.Thick Line";cout<<"\n4.Exit";cout<<"\n———————————————————————————————————————————";cout<<"\nEnter your choice ";cin>>ch;switch(ch){case1:T.getdata();initgraph(&gd,&gm,NULL);T.calc();T.draw();delay(5000);closegraph();break;case2:T.getdata();initgraph(&gd,&gm,NULL);T.calc();T.draw1();delay(5000);closegraph();break;case3:T.getdata();initgraph(&gd,&gm,NULL);T.calc();T.draw2();delay(5000);closegraph();break;case4:exit(0);default:cout<<"\nWrong Choice Entered...Please Try Again\n";}}while(ch!=4);return0;}
Output
kodingwindow@kw:~$ g++ kw.cpp -lgraph kodingwindow@kw:~$ ./a.out
———————————————————————————————————————————
C++ program for the thick, thin, dotted line
———————————————————————————————————————————
1.Thin Line
2.Dotted Line
3.Thick Line
4.Exit
———————————————————————————————————————————
Enter your choice 1
Enter the x1 coordinate 20
Enter the y1 coordinate 20
Enter the x2 coordinate 150
Enter the y2 coordinate 150
———————————————————————————————————————————
C++ program for the thick, thin, dotted line
———————————————————————————————————————————
1.Thin Line
2.Dotted Line
3.Thick Line
4.Exit
———————————————————————————————————————————
Enter your choice 2
Enter the x1 coordinate 20
Enter the y1 coordinate 20
Enter the x2 coordinate 100
Enter the y2 coordinate 100
———————————————————————————————————————————
C++ program for the thick, thin, dotted line
———————————————————————————————————————————
1.Thin Line
2.Dotted Line
3.Thick Line
4.Exit
———————————————————————————————————————————
Enter your choice 3
Enter the x1 coordinate 20
Enter the y1 coordinate 20
Enter the x2 coordinate 150
Enter the y2 coordinate 150
Dear User, Thank you for visitng KodingWindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.