PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label bgi. Show all posts
Showing posts with label bgi. Show all posts

Tuesday, November 8, 2022

[FIXED] why isnt initgraph getting recognized in my program?

 November 08, 2022     bgi, c++, menu, user-interface     No comments   

Issue

I have programmed a code for displaying a GUI menu in Turbo C++ but I don't know why it wont recognize initgraph

This is the output message BGI Error:Graphics not initialized when i tried a simpler program on graphics in Turbo C++ it said egavga.bgi not found but it was there in the bgi file in my turbo c++ folder Also when i tried to put the location of the bgi in initgraph it doesnt do anything

this is the program code

#include<iostream.h>
#include<conio.h>
#include <dos.h>
#include<graphics.h>

//Menu Global Item
#define pixTOrc(x) (8*(x-1))  //convert pixel into row and col format
#define INC 5  //Increment Distance Between Menu Items
#define ROW 15 //Row Value for Menu Item
#define COL 8 //Column Value for Menu Item
#define MAXMENU 5 //Total menu items

// To display the Inventory Main menu options
typedef char option[20];
option MMenu[]= {
             "View Account",
                "Transactions",
                "New Accont",
                "Edit Account",
                "Quit"
              };
// Function to displays all the menu prompt messages from the pointer array of option a[]
void normalvideo(int x,int y,char *str)
{
   x=pixTOrc(x);
   y=pixTOrc(y);
   outtextxy(x,y,str);
}
// Function to move the cursor on the menu prompt with a reverse video color            
void selectedMenu(int x,int y,char *str)
{
   x=pixTOrc(x);
   y=pixTOrc(y);
   setcolor(5);  //Selected Item Color
   sound(400);
   delay(100);
   nosound();
   outtextxy(x,y,str);
   setcolor(WHITE); //Unselected Item Color
   sound(500);
   delay(100);
   nosound();
}
//Keep Track of which arrow key is pressed
char menu()
{
   settextstyle(TRIPLEX_FONT,HORIZ_DIR,2);
   setcolor(WHITE);  //Initial Menu Item Color
   int i,done;
   for(i = 1; i < MAXMENU; i++)
   normalvideo(COL, (i*INC)+ROW, MMenu[i]);
   selectedMenu(COL,ROW, MMenu[0]);
   i = done = 0;
   do
   {
      /**Status Bar Code**/
      setfillstyle(SOLID_FILL,BLUE);
      settextstyle(SMALL_FONT,HORIZ_DIR,5);
      bar(pixTOrc(2),pixTOrc(52.5),pixTOrc(75),pixTOrc(55));
      setcolor(LIGHTCYAN);
      switch(i)
      {
        case 0 : outtextxy(pixTOrc(5),pixTOrc(52.75),"View Account --> View Detail of an account");
                 break;
        case 1 : outtextxy(pixTOrc(5),pixTOrc(52.75),"Transactions --> Do transaction Debit/Credit");
                  break;
case 2 : outtextxy(pixTOrc(5),pixTOrc(52.75),"New Accont --> Create a new account for customer");
                 break;
        case 3 : outtextxy(pixTOrc(5),pixTOrc(52.75),"Edit Account --> Edit an existing account");
                 break;
        case 4 : outtextxy(pixTOrc(5),pixTOrc(52.75),"Close the Program");
                 break;
      }
      /**status Bar ends**/
      setcolor(WHITE);
      settextstyle(TRIPLEX_FONT,HORIZ_DIR,2);
      int key = getch();
      switch (key)
      {
         case 00: key = getch();
            switch (key)
            {
               case 72: normalvideo(COL, (i*INC)+ROW, MMenu[i]);
                      i--;
                          if (i == -1)
               i = MAXMENU-1;
                           selectedMenu(COL,(i*INC)+ROW,MMenu[i]);
                        break;
               case 80: normalvideo(COL, (i*INC)+ROW, MMenu[i]);
                      i++;
              if (i == MAXMENU)
                           i = 0;
                           selectedMenu(COL, (i*INC)+ROW, MMenu[i]);
                        break;
            }
            break;
         case 13: done = 1;
      }
   }
   while (!done);
   return(i+49);
}
//This part you can use for main functionality of the menu
void mainArea()
{
   setcolor(BLUE);
   outtextxy(pixTOrc(30),pixTOrc(20),"http://cbsecsnip.in/");
   setcolor(YELLOW);
}
/* Code for displaying the main menu*/
void call_menu()
{
   char choice;
   do
   {
      choice = menu();
      switch (choice)
      {
         case '1': setcolor(BLUE);
                   outtextxy(pixTOrc(40),pixTOrc(15),"View Account");
                   mainArea();
                   getch();
                   setfillstyle(SOLID_FILL,LIGHTGRAY);
                   bar(pixTOrc(28),pixTOrc(14),pixTOrc(75),pixTOrc(50));
                   mainArea();
                   break;
        case '2':
                   setcolor(BLUE);
                 outtextxy(pixTOrc(40),pixTOrc(15),"Transactions");
                 mainArea();
                 getch();
                 setfillstyle(SOLID_FILL,LIGHTGRAY);
                 bar(pixTOrc(28),pixTOrc(14),pixTOrc(75),pixTOrc(50));
                 mainArea();
                 break;
        case '3':
                 setcolor(BLUE);
                 outtextxy(pixTOrc(40),pixTOrc(15),"New Accont");
                 mainArea();
                 getch();
                 setfillstyle(SOLID_FILL,LIGHTGRAY);
                 bar(pixTOrc(28),pixTOrc(14),pixTOrc(75),pixTOrc(50));
                 mainArea();
                 break;
        case '4':
                 setcolor(BLUE);
                 outtextxy(pixTOrc(40),pixTOrc(15),"Edit Account");
                 mainArea();
                 getch();
                 setfillstyle(SOLID_FILL,LIGHTGRAY);
                 bar(pixTOrc(28),pixTOrc(14),pixTOrc(75),pixTOrc(50));
                 mainArea();
                 break;
        case '5':    //Close the project
                 setcolor(BLUE);
                 outtextxy(pixTOrc(40),pixTOrc(15),"Quit");
                 mainArea();
                 delay(1000);
                 setfillstyle(SOLID_FILL,LIGHTGRAY);
                 bar(pixTOrc(28),pixTOrc(14),pixTOrc(75),pixTOrc(50));
                 mainArea();
                 goto exit;
      }
   } while (choice != MAXMENU);
exit:
}
void main()
{
   int i,j;
   int gd=DETECT,gm;
   initgraph(&gd,&gm,"");
   setcolor(BLACK);
   rectangle(0,0,640,480);
   setfillstyle(SOLID_FILL,LIGHTGRAY);
   bar(2,1,637,478);
   setfillstyle(SOLID_FILL,BLACK);
   bar(1,3,637,50);
   settextstyle(BOLD_FONT,HORIZ_DIR,2);
   setcolor(YELLOW);
   outtextxy(pixTOrc(12),pixTOrc(1)," BANKING SYSTEM PROJECT ");
   setfillstyle(CLOSE_DOT_FILL,DARKGRAY);
   bar(pixTOrc(7),pixTOrc(14),pixTOrc(25),pixTOrc(50));
   call_menu();
   closegraph();
   getch();
}

Solution

Possible Solutions: Copy all Files from BGI folder to BIN. Check if it works.



Answered By - Arun Sharma
Answer Checked By - Timothy Miller (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Sunday, August 14, 2022

[FIXED] How to draw circle at a specific area?

 August 14, 2022     bgi, c, output     No comments   

Issue

I wrote a simple C program to make a circle. It follow mid-point circle drawing algorithm.

This is my code right now:

#include <stdio.h>
#include <conio.h>
#include <graphics.h>

void main()
{
   int gd = DETECT, gm ;
   int r, x, y, xc, yc, P;

   initgraph(&gd, &gm ,"..//bgi");
   clrscr();

   printf("\n Enter the radius : ");
   scanf("%d", &r);
   printf("\n Enter the centre as X and Y : ");
   scanf("%d%d", &xc,&yc);

   x = 0;
   y = r;
   P = 1 - r;

   do
   {
     putpixel( x,  y, WHITE);
     putpixel( y,  x, WHITE);
     putpixel(-x, -y, WHITE);
     putpixel(-y, -x, WHITE);
     putpixel(-x,  y, WHITE);
     putpixel( y, -x, WHITE);
     putpixel( x, -y, WHITE);
     putpixel(-y,  x, WHITE);

     if(P < 0)
     {
       x = x + 1 ;
       P = P + (2 * x) + 1 ;
     }
     else
     {
       x = x + 1 ;
       y = y - 1 ;
       P = P + (2 * x) - (2 * y) + 1 ;
     }
  }while(x < y);

    getch();
    closegraph();

}

The problem is that the output seems to go in the top left corner and I can't see the whole output. Is there any way I can set the output to show up at specific area of my screen or something like that?

Screen shot of my current output:

SCREENSHOT_OF_OUTPUT

EDIT: After the points suggested by LPs and koldewb, I re-wrote the whole code and now, I'm getting output in center, I mean, the output is much better. I added different color to see which quadrant was plotted... Here is the code :-

#include<stdio.h>
#include<conio.h>
#include<graphics.h>

void main()
{
   int gd = DETECT , gm ;
   int r , x , y , xc , yc  , P;

   initgraph(&gd , &gm ,"..//bgi") ;

   printf("\n Enter the radius : ") ;
   scanf("%d" , &r) ;
   printf("\n Enter the centre as X and Y : ") ;
   scanf("%d%d" , &xc,&yc) ;

   x = 0 ;
   y = r ;
   P = 1-r ;

   do
  {
     putpixel(xc+x,yc+y,WHITE) ;
     putpixel(yc+y,xc+x,WHITE) ;
     putpixel(xc-x,yc-y,WHITE) ;
     putpixel(yc-y,xc-x,WHITE) ;
     putpixel(xc-x,yc+y,WHITE) ;
     putpixel(yc+y,xc-x,WHITE) ;
     putpixel(xc+x,yc-y,WHITE) ;
     putpixel(yc-y,xc+x,WHITE) ;

     if(P<0)
     {
       x = x + 1 ;
       P = P + (2*x) + 1 ;
     }
     else
     {
       x = x + 1 ;
       y = y - 1 ;
       P = P + (2*x) - (2*y) + 1 ;
     }
     } while(x<y) ;

     getch() ;
     closegraph() ;
  }

I'm not sure if this would be of any help to anyone, But, well, I might as well post the updated code.

Screen shot of my Updated output:

SCREENSHOT_OF_OUTPUT


Solution

User inserts coos of circle center into xc an yc variables, but your code always start with x=0 and y=r.

I cannot test the code, but probably you can add xc and yc offset each time you calculate a new x and y.



Answered By - LPs
Answer Checked By - Marilyn (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Saturday, June 25, 2022

[FIXED] Why is this program giving an error: to_string is not a member of std. Why?

 June 25, 2022     bgi, c++, compiler-errors     No comments   

Issue

I am using VS2008 and Win7 64bit.

#include <iostream>
#include "utils.h"
#include <string>

int main()
{
    int gm = DETECT;
    int gd = DETECT;
    initgraph(&gm, &gd, "");
    double x = 0;
    double y = 0;
    double r = 50;
    for(int i=0 ; i<=360 ; i++)
    {
        x = r * cos(DegreeToRad((double)i));
        y = r * sin(DegreeToRad((double)i));

        PlotLine(0,0,x,y, YELLOW);

        std::string str;
        str.append(std::to_string(i));
        str.append(". ");
        str.append(std::to_string(0));
        str.append(", ");
        str.append(std::to_string(0));
        str.append(") to (");
        str.append(std::to_string(x));
        str.append(", ");
        str.append(std::to_string(y));
        str.append(").  m=");
        str.append(std::to_string(Slope(0,0,x,y)));
        str.append("\n");       

        if(i%90==0)
        {
            str.append("\ni=");
            str.append(std::to_string(i));
            str.append("\n");
        }

        WriteToFile("slope.txt", str.c_str());
    }

    getch();
    closegraph();

    return 0;
}

Error Messages.

1>e:\slope.test.cpp(21) : error C2039: 'to_string' : is not a member of 'std'
1>e:\slope.test.cpp(21) : error C3861: 'to_string': identifier not found
1>e:\slope.test.cpp(23) : error C2039: 'to_string' : is not a member of 'std'
1>e:\slope.test.cpp(23) : error C3861: 'to_string': identifier not found
1>e:\slope.test.cpp(25) : error C2039: 'to_string' : is not a member of 'std'
1>e:\slope.test.cpp(25) : error C3861: 'to_string': identifier not found
1>e:\slope.test.cpp(27) : error C2039: 'to_string' : is not a member of 'std'
1>e:\slope.test.cpp(27) : error C3861: 'to_string': identifier not found
1>e:\slope.test.cpp(29) : error C2039: 'to_string' : is not a member of 'std'
1>e:\slope.test.cpp(29) : error C3861: 'to_string': identifier not found
1>e:\slope.test.cpp(31) : error C2039: 'to_string' : is not a member of 'std'
1>e:\slope.test.cpp(31) : error C3861: 'to_string': identifier not found
1>e:\slope.test.cpp(37) : error C2039: 'to_string' : is not a member of 'std'
1>e:\slope.test.cpp(37) : error C3861: 'to_string': identifier not found
1>Generating Code...
1>Build log was saved at "file://e:\Debug\BuildLog.htm"
1>RasterizationLineCircleEllipse - 15 error(s), 14 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Solution

Those errors could mean:

  1. std::to_string requires header, which you did not include (but it doesn't)
  2. You didn't enable C++11 (I don't know how this works for Visual Studio)
  3. You compiler does not support C++11.

From comments it seems that Visual Studio you are using does not support C++11, so you can use old good string stream and with template you can create an equivalent of std::to_string:

#include <sstream>
#include <string>

template<class T>
std::string toString(const T &value) {
    std::ostringstream os;
    os << value;
    return os.str();
}

//Usage:
std::string valueStr = toString(10);
valueStr.append(toString(1));
valueStr.append(toString(2.5));

Note that to use this function type T needs to have operator<< defined, but it's not a problem with types, which std::to_string supports.



Answered By - zoska
Answer Checked By - Clifford M. (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing