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.

Types of Programming Languages

Programming languages can be divided into different types based on many criteria's but for  simplicity we can divide them in two major types.

  • Application Programming Languages
    • C# (General Purpose)
    • VB/VB.NET (General Purpose)
    • F# (Functional)
    • JAVA (General Purpose)
    • Python (General Purpose)
    • Objective-C (General Purpose)
    • JavaScript/Type Script/Angular JS etc. (Scripting)
  • System Programming Languages
    • C/C++
    • Rust
    • Assembly etc.

Application programming languages such as Java and C# are primarily utilized to create software that directly serves users. These languages are instrumental in developing business applications like spreadsheets, word processors, web and mobile applications.

Systems programming languages like C and C++ are used to construct software and foundational software platforms. They are essential for developing operating systems, game engines, compilers, and more. These languages often demand extensive hardware interaction.

Both application and systems programming languages encounter significant challenges:

  • Writing secure code is difficult.

  • Creating multi-threaded code is challenging.

Normally when some one enters in field of IT or computer science as a programmer or software engineer, he or she will be working in of these two categories (Application Software Development, System Software Development).

99%  of  graduates are working in Application Development field in which they are developing applications like
    
    • Payroll /HR Management/ ERP (Enterprise Resource Planning)/MRP (Material Resource Planning).
    • Websites/Web Applications (ECommerce, Social Media, Blogs, Streaming platforms, Communication Portals, File Sharing, Crypto Currency platforms etc.)
    • Video Games
    • Machine Learning/AI and Data Science.
    • IOT (Internet of Things) /Embedded Systems
    • Computer Graphics and Animations
    • Database Applications

Saturday, November 9, 2024

Why Rest language is so popular? Part-3

Here are the reasons why Rust language is so popular:

Memory Safety: Rust is designed to prevent common programming errors that can lead to security vulnerabilities, such as buffer overflows and null pointer dereferences. This makes it a safer alternative to languages like C and C++.


Performance: Rust offers performance comparable to C and C++, making it an excellent choice for systems programming where efficiency is critical.

Concurrency: Rust has built-in support for safe concurrency, allowing developers to write multi-threaded code without the risk of data races or other concurrency issues.

Modern Features: Rust includes modern programming language features like pattern matching, traits, and an expressive type system, which make it both powerful and flexible.

Developer Satisfaction: Rust consistently ranks high in developer surveys for being loved and desired by programmers. Its emphasis on safety, performance, and productivity resonates well with developers.




 

Who is using Rust Language? Part-2

If you haven’t yet heard, Rust is one of the most promising and most loved programming languages out there.

Here is the list of companies which are using Rust programming language.

  • Microsoft
  • Meta
  • GitHub
  • Cloudflare
  • Amazon
  • NPM
  • Figma
  • Coursera
  • Dropbox

 

What is Rust Programming Language? Part-1

 Rust is a general-purpose programming language emphasizing performance, type safety, and concurrency. It enforces memory safety, meaning that all references point to valid memory. It does so without a traditional garbage collector; instead, both memory safety errors and data races are prevented by the "borrow checker", which tracks the object lifetime of references at compile time.

Software developer Graydon Hoare created Rust as a personal project while working at Mozilla Research in 2006. Mozilla officially sponsored the project in 2009. In the years following the first stable release in May 2015, Rust was adopted by companies including Amazon, Discord, Dropbox, Google (Alphabet), Meta, and Microsoft. In December 2022, it became the first language other than C and assembly to be supported in the development of the Linux kernel.

Platform: Cross Platform

OS: Cross Platform

File Extension: .rs, .rslib

Rust SiteRust Programming Language

Hello World program

fn main() {
    println!("Hello, World!");
}

Variables

Variables in Rust are defined through the let keyword.

fn main() {
    let foo = 10;
    println!("The value of foo is {foo}");
}

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 ...