#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
union REGS i,o;
struct SREGS s;
initmouse();
showmouse();
void changecursor(int *shape);
int cursor1[32]={ 0x0000,0xf00f,0xe007,0xc003,
		 0x8001,0x0000,0x0000,0x0000,
		 0x0000,0x0000,0x0000,0x8001,
		 0xc003,0xe00f,0xf00f,0x0000,

		 0xffff,0x0ff0,0x1ff8,0x3ffc,
		 0x799e,0xf99f,0xffff,0xffff,
		 0xffff,0xffff,0xffff,0x7ffe,
		 0x3c3c,0x1ff8,0x0ff0,0xffff,
		 };
int cursor2[32]={ 0xe00f,0xf10f,0xf81f,0x8c63,
		  0x0001,0x0001,0x0001,0x0001,
		  0x8003,0xc007,0xc007,0x8003,
		  0x8003,0xc7c7,0xffff,0xffff,

		  0x1010,0x0820,0x0440,0x739c,
		  0xfbbe,0xfffe,0xfffe,0xfffe,
		  0x7ffc,0x3ff8,0x3ff8,0x7ffc,
		  0x7d7c,0x3838,0x0000,0x0000,
		 };
int cursor3[32]={ 0xffff,0xffff,0xffff,0xe03f,
		  0xc01e,0x800c,0x0801,0x8001,
		  0xc003,0x8003,0x0001,0x8009,
		  0xc01c,0xe03e,0xffff,0xffff,

		  0x0000,0x0000,0x0000,0x1fc0,
		  0x3fe1,0x7ff3,0xf7fe,0x7ffe,
		  0x3ffc,0x7ffc,0xfffe,0x7ff6,
		  0x3fe3,0x1fc1,0x0000,0x0000,
		};
int cursor4[32]={ 0xc003,0xdffb,0xd00b,0xd00b,
		  0xd00b,0xd00b,0xd00b,0xd00b,
		  0xdffb,0xc003,0xfc3f,0xfc3f,
		  0x0000,0x0000,0x0000,0x0000,

		  0x3ffc,0x2004,0x2ff4,0x2ff4,
		  0x2ff4,0x2ff4,0x2ff4,0x2ff4,
		  0x2004,0x3ffc,0x03c0,0x03c0,
		  0xffff,0xffff,0xffff,0xffff,
		};

void main()
{
  int gd=DETECT,gm, xx,yy,b;
  initgraph(&gd,&gm,"c:\tc\bgi ");
  gotoxy(10,1);
  cout<<"Press any key and move the cursor to change shape
";
  gotoxy(60,25);
  cout<<"made by NIGI";
  changecursor(cursor1);
  showmouse();
  getch();
  changecursor(cursor2);
  showmouse();
  getch();
  changecursor(cursor3);
  showmouse();
  getch();
  changecursor(cursor4);
  showmouse();
  getch();

}
initmouse()
{
  i.x.ax=0;
  int86(0x33,&i,&o);
  return(o.x.ax);
}
showmouse()
{
  i.x.ax=1;
  int86(0x33,&i,&o);
  return(o.x.ax);
}
void changecursor(int *shape)
{
  i.x.ax=9;
  i.x.bx=0;
  i.x.cx=0;
  i.x.dx=(unsigned)shape;
  segread(&s);
  s.es=s.ds;
  int86x(0x33,&i,&o,&s);
} 

C++ Online Compiler

Write, Run & Share C++ code online using OneCompiler's C++ online compiler for free. It's one of the robust, feature-rich online compilers for C++ language, running on the latest version 17. Getting started with the OneCompiler's C++ compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as C++ and start coding!

Read inputs from stdin

OneCompiler's C++ online compiler supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample program which takes name as input and print your name with hello.

#include <iostream>
#include <string>
using namespace std;

int main() 
{
    string name;
    cout << "Enter name:";
    getline (cin, name);
    cout << "Hello " << name;
    return 0;
}

About C++

C++ is a widely used middle-level programming language.

  • Supports different platforms like Windows, various Linux flavours, MacOS etc
  • C++ supports OOPS concepts like Inheritance, Polymorphism, Encapsulation and Abstraction.
  • Case-sensitive
  • C++ is a compiler based language
  • C++ supports structured programming language
  • C++ provides alot of inbuilt functions and also supports dynamic memory allocation.
  • Like C, C++ also allows you to play with memory using Pointers.

Syntax help

Loops

1. If-Else:

When ever you want to perform a set of operations based on a condition If-Else is used.

if(conditional-expression) {
   //code
}
else {
   //code
}

You can also use if-else for nested Ifs and If-Else-If ladder when multiple conditions are to be performed on a single variable.

2. Switch:

Switch is an alternative to If-Else-If ladder.

switch(conditional-expression){    
case value1:    
 // code    
 break;  // optional  
case value2:    
 // code    
 break;  // optional  
......    
    
default:     
 code to be executed when all the above cases are not matched;    
} 

3. For:

For loop is used to iterate a set of statements based on a condition.

for(Initialization; Condition; Increment/decrement){  
  //code  
} 

4. While:

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while (condition) {  
// code 
}  

5. Do-While:

Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.

do {  
 // code 
} while (condition); 

Functions

Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increases re-usuability and modularity. Function gets run only when it is called.

How to declare a Function:

return_type function_name(parameters);

How to call a Function:

function_name (parameters)

How to define a Function:

return_type function_name(parameters) {  
 // code
}