Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

write a c++ program to draw 2 rectangles and fill one of them.

+1 vote
asked Jun 17, 2019 by Lorraine
#include<iostream.h>

1 Answer

0 votes
answered Jun 24, 2019 by The Guitar Frets (140 points)

#include <iostream.h>
#include <conio.h>
#include <graphics.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>

void main()
{
  clrscr();
  int gd = DETECT,gm,errorcode; //Requesting auto-detection.

  //Initializing graphics and local variables.
  initgraph (&gd, &gm, "d:\\bc3\\bgi"); //Path where graphics drivers are installed

  //Read result of initialization.
  errorcode = graphresult();

  //An error occured.
  if (errorcode != grOk)
    {
      cout << "Graphics error occured : \n" << grapherrormsg(errorcode) << endl;
      cout << "Press any key to stop : ";
      getch();
      exit(1);
    }

  /*Drawing a rectangle having top LHS vertex at (300, 300)
  and bottom RHS vertex at (600, 400)*/
  rectangle(300, 300, 600, 400);
  rectangle(100, 100, 200, 200);
  getch();
  floodfill(120, 120, WHITE);
  getch();
  closegraph();
}

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...