SETHA SITE INFORMATION

  • Increase font size
  • Default font size
  • Decrease font size
C/C++

How to Clear Screen in C++?

E-mail Print PDF
This article shows C++ code to clear screen.
  • Use header file: #include<stdlib.h>
  • Use function: system("cls")
Example:
#include<iostream>
#include<stdlib.h>

using namespace std;

int main()
{
    cout<<"Hello world!";
    system("cls");
    cout<<"Hi World!";
    return 0;
}

 

Pascal Triangle in Turbo C++

E-mail Print PDF
The code below is written in Turbo C++ to produces a pascal triangle.
#include<iostream.h>
#include<conio.h>

double fact(int n)
{
	if(n==0) return 1;
	else return n*fact(n-1);
}

void main()
{
	clrscr();
	for(int i=0; i<=10;i++)
	{
		for(int j=0; j<=i; j++)
		{
			gotoxy(40-2*i+4*j, 2*i+1);
			cout<<fact(i)/(fact(j)*fact(i-j));
		}
	}
	getch();
}
 

Calculate Factoriel in Turbo C++

E-mail Print PDF
Code below is the C++ programming language uses to calculate factorial of value n using recursive function (return n*fact(n-1).
n! = 1 x 2 x 3 x 4 x ... x n
long fact(int n)
{
	if(n==0) return 1;
	else return n*fact(n-1);
}
 

Using window, textbackground, textcolor, gotoxy in Turbo C++

E-mail Print PDF

The below code is written in Turbo C++. It includes the uses of window, textbackground, textcolor, and gotoxy functions. There are 8 main colors in this context. (0:BLACK, 1:BLUE, 2:GREEN, 3:CYAN, 4:RED, 5:MAGENTA, 6:BROWN, 7:LIGHTGRAY)

1) Two Windows Example
#include<stdio.h>
#include<conio.h>

void main()
{
	//full screen window w: 80, h: 50
	window(1,1,80,50);
	textbackground(0);//black color
	clrscr();
	textcolor(15); //white color
	gotoxy(1,1); cprintf("WINDOW-1");

	//window 2
	window(10,10,40,20);
	textbackground(1); //blue color
	clrscr();
	textcolor(15); //white color
	gotoxy(1,1); cprintf("WINDOW-2");
	//pause screen
	getch();
}
Download Source Code Here
 
2) 8 Windows Example
#include<stdio.h>
#include<conio.h>

void main()
{
	for(int i=0; i<=7; i++)
	{
		window(1+5*i,1+3*i,80-5*i,50-3*i);
		textbackground(7-i);//black color
		clrscr();
		textcolor(i); //white color
		gotoxy(2,2); cprintf("WINDOW-%d",8-i);
	}

	//pause screen
	getch();
}
Download Source Code Here
 
3) 16 Windows Example
#include<stdio.h>
#include<conio.h>

void main()
{
	for(int i=0; i<=15; i++)
	{
		window(1+5*i,1,5+5*i,50);
		textbackground(7-i);//black color
		clrscr();
		textcolor(i); //white color
		gotoxy(2,2); cprintf("%d",i+1);
	}

	//pause screen
	getch();
}
Download Source Code Here
 

Create Simple English Typing in Turbo C++

E-mail Print PDF

This article shows you how to create a very simple English Typing in C++ programming with Turbo C++ IDE. In this sample, you will see the uses of gotoxy and textcolor for setting cursor position and coloring text respectively.

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<dos.h>

//create simple typing
void main()
{
	clrscr(); //clear screen
	//suppose there are two lesson
	char *lesson[]={"asdf jkl; fdsa ;lkj",	//lesson 1
			"asfg ;khg ghfj dksl"}; //lesson 2
	int numLes=0,i=0;
	char ch;
	gotoxy(1,20);
	cprintf("Press  to exit.");
	while(1){
	    textcolor(7);
	    gotoxy(10,12);
	    cprintf("%s",lesson[numLes]);
	    gotoxy(1,4);
	    cprintf("Lesson: %d",numLes+1);
	    textcolor(14);
	    gotoxy(10+i,12);
	    cprintf("%c",lesson[numLes][i]);
	    //get key press code
	    ch=getch();
	    if(ch==27) exit(1); //press ESC
	    else
	    {
		if(ch==lesson[numLes][i]) i+=1; //type correct
		else
		{  //type incorrect
			sound(500); //make beep sound
			delay(100);
			nosound();
		}
		if(lesson[numLes][i]=='\0')
		{ //end of string
			i=0;
			numLes=(numLes==1)?0:1; //switch lesson 1-2-1
		}
	    }
	}
}
Download Source Code Here
 
  • «
  •  Start 
  •  Prev 
  •  1 
  •  2 
  •  3 
  •  4 
  •  5 
  •  Next 
  •  End 
  • »


Page 1 of 5