Wikipedia

Search results

Saturday, November 23, 2024

Creating Simple Selectable Menu in Turbo C++ [graphics mode]

 Here is simple code for creating a menu in graphics mode in turbo c++. you can select menus by pressing up and down arrow keys.


#include <graphics.h>

#include <conio.h>


void drawMenu(int x, int y, char* items[], int count, int selected) {

    int height = 20;

    for (int i = 0; i < count; i++) {

        if (i == selected) {

            setcolor(RED);

        } else {

            setcolor(WHITE);

        }

        rectangle(x, y + (i * height), x + 100, y + (i * height) + height);

        outtextxy(x + 5, y + (i * height) + 5, items[i]);

    }

}


int main() {

    int gd = DETECT, gm;

    initgraph(&gd, &gm, "C:\\Turboc3\\BGI");


    char* menuItems[] = {"Option 1", "Option 2", "Option 3"};

    int selectedItem = 0;

    int itemCount = 3;

    

    drawMenu(50, 150, menuItems, itemCount, selectedItem);

    

    while (1) {

        if (kbhit()) {

            int ch = getch();

            if (ch == 0) { // special keys

                ch = getch();

                switch (ch) {

                    case 72: // up arrow key

                        selectedItem = (selectedItem - 1 + itemCount) % itemCount;

                        break;

                    case 80: // down arrow key

                        selectedItem = (selectedItem + 1) % itemCount;

                        break;

                }

                drawMenu(50, 150, menuItems, itemCount, selectedItem);

            } else if (ch == 13) { // Enter key

                outtextxy(50, 250, "You selected: ");

                outtextxy(150, 250, menuItems[selectedItem]);

                break;

            }

        }

    }

    

    getch();

    closegraph();

    return 0;

}


output:




Sunday, November 17, 2024

What is generative AI?

 Generative AI, sometimes called gen AI, is artificial intelligence (AI) that can create original content—such as text, images, video, audio or software code—in response to a user’s prompt or request.

Generative AI relies on sophisticated machine learning models called deep learning models—algorithms that simulate the learning and decision-making processes of the human brain. These models work by identifying and encoding the patterns and relationships in huge amounts of data, and then using that information to understand users' natural language requests or questions and respond with relevant new content

For further reading follow this link. What is Generative AI? | IBM

Saturday, November 16, 2024

Add colored text output in your console application using gcc compiler

 There is no traditional  way to show colored output in your console in gcc compiler like turbo C++. Turbo C++ has built in header file (conio.h) to perform this task. But in gcc this can be achieved through escape sequences. e.g. look at this program output 

using gcc compilerOnline C Compiler - online editor

#include <stdio.h> /* printf */

int main(void)
{
  printf("\033[0mNormal text\033[0m\n");
  printf("\033[31mRed text\033[0m\n");
  printf("\033[4mUnderlined text\033[0m\n");
  printf("\033[37;104mGray on light blue\033[0m\n");
  printf("\033[1;37;44mBright white on blue\033[0m\n");
  printf("\033[1;37;41mBright white on light red\033[0m\n");
  printf("\033[5;93mBlinking yellow\033[0m\n");

  return 0;
}


using g++ compiler: Online C++ Compiler - online editor

#include <iostream> /* cout, endl */

int main()
{
  using std::cout;
  using std::endl;

  cout << "\033[0mNormal text\033[0m" << endl;
  cout << "\033[31mRed text\033[0m" << endl;
  cout << "\033[4mUnderlined text\033[0m" << endl;
  cout << "\033[37;104mGray on light blue\033[0m" << endl;
  cout << "\033[1;37;44mBright white on blue\033[0m" << endl;
  cout << "\033[1;37;41mBright white on light red\033[0m" << endl;
  cout << "\033[5;93mBlinking yellow\033[0m" << endl;

  return 0;
}



Color codes and Escape Sequences:

n escape sequence includes 3 integer values: an attribute, a foreground color, and a background color. If you don't provide one of the three values, the default will be used.

AttributesForeground colorBackground color
00 = normal
01 = bold
04 = underlined
05 = blinking
07 = reversed
08 = concealed
31 = red
32 = green
33 = orange
34 = blue
35 = purple
36 = cyan
37 = grey
90 = dark grey
91 = light red
92 = light green
93 = yellow
94 = light blue
95 = light purple
96 = turquoise
40 = black
41 = red
42 = green
43 = orange
44 = blue
45 = purple
46 = cyan
47 = grey
100 = dark grey
101 = light red
102 = light green
103 = yellow
104 = light blue
105 = light purple
106 = turquoise


Wednesday, November 13, 2024

Baisc Rust Language Features : Part-5

Rust is a new system programming language replacing C language  rapidly. Rust language is influenced by new programming languages like

  • C#
  • C++
  • Haskell
  • Ruby
  • Swift
Some of the basic features of Rust languages are

  • Type/Memory Safe
  • Does not support Dangling pointers and null pointers.
  • Safe Pointers
  • Does not allow function overloading
  • Doest not uses Garbage Collector.
  • High Speed performance like C/C++
  • Variables are immutable by default meaning once a value is assigned to a variable it can not be changed.

 

Sunday, November 10, 2024

Rust Environment Setup on Windows: Part-4

 

Setting up Rust on Windows OS is two step process. you need 

Make sure you select Desktop Development option in C++ while installing Visual Studio. As Rust uses Visual Studio C++ build tools for building executable files. You must be familiar with command line in order to run quires.

Most modern developing tools are using command line scripts in order to setup, configuring and creating projects. like Microsoft DOTNET Core, Python, Angular, React, NodeJS. 

You must be wondering why i have suggested Rust Rover IDE    instead of VS Code although  my first choice was also VS Code. Issue was that there was no official debugger available  for VS Code.

Creating Simple Selectable Menu in Turbo C++ [graphics mode]

 Here is simple code for creating a menu in graphics mode in turbo c++. you can select menus by pressing up and down arrow keys. #include ...