Showing posts with label cplusplus. Show all posts
Showing posts with label cplusplus. Show all posts

C / C++ program to print the table for a particular number

Leave a Comment
/* The following C/C++ program will print the table of any number entered. The following program can be extended to print tables for 'n' numbers by inserting the table() function in a loop or making multiple call of it */

Code:
#include<iostream>
#include<conio.h>
using namespace std;
void table (int a)
{
int i=1;
while (i<=10)
{
cout<<a<<"*"<<i<<"="<<a*i<<endl;
i++;
}
}
int main ()
{
int a;
cout<<"Enter Number:";
cin>>a;
cout<<endl<<"Table of Number :"<<a<<endl;
table(a);
getche();
return 0;
}


Output:
Output of C / C++ program to print the table for a particular number
Output of C / C++ program to print the table for a particular number

Read More...

C / C++ Program to calculate element wise sum of 2 arrays : element wise addition

Leave a Comment
/* The following C / C++ program require user to enter the elements of arrays having equal number of array elements. Equal number of array elements are required in this program. This program can be extended to any of the data type & to the 'n' number of arrays simultaneously*/

Code:
#include<iostream>
#include<conio.h>
using namespace std;
void main ()
{
int long a[100],b[100],c[100];
int d=0,n;
cout<<"Number of Elements in Arrays: ";
cin>>n;
cout<<"Enter For Array 1"<<endl;
while (d<n)
{
cout<<"Enter the element number "<<d+1<<" : ";
cin>>a[d];
d=d+1;
}
d=0;
cout<<"Enter For Array 2"<<endl;
while (d<n)
{
cout<<"Enter the element number "<<d+1<<" : ";
cin>>b[d];
d=d+1;
}
d=0;
while (d<n)
{
c[d]=a[d]+b[d];
d=d+1;
}
d=0;
cout<<"\nResult of element wise sum of array elements:\n";
while (d<n)
{
cout<<c[d]<<"\t";
d=d+1;
}
getche();
}


Output
Output of C / C++ Program to calculate element wise sum of 2 arrays
Output of C / C++ Program to calculate element wise sum of 2 arrays

Read More...

C / C++ Program For Entering Grade & Getting an Automated Remark Using If-Else statements : Grade Automatic Feedbacking / Remarking System

Leave a Comment
/* In the following C / C++ program we need to enter the grade, the student got in the exam & the program will give an automated remark about that grade */

Code:-
#include<iostream>
#include<conio.h>
using namespace std;
void main ()
{
char a;
cout<<"Enter Grade You Got : ";
cin>>a;
if (a=='A' || a=='a')
{
cout<<"Excellent";
}
else if (a=='B' || a=='b')
{
cout<<"Very Good";
}
else if (a=='C' || a=='c')
{
cout<<"Good";
}
else if (a=='D' || a=='d')
{
cout<<"Satisfactory";
}
else if (a=='E' || a=='e')
{
cout<<"Acceptable";
}
else if (a=='F' || a=='f')
{
cout<<"You Failed!";
}
else
{
cout<<"Entered grade is not valid";
}
getche();
}



Output:
C / C++ Program For Entering Grade & Getting an Automated Remark Using If-Else statements : Grade Automatic Feedback / Remarking System
C / C++ Program For Entering Grade & Getting an Automated Remark Using If-Else statements : Grade Automatic Feedback / Remarking System

Read More...

C / C++ Program to find the Smallest number from the array of integers

Leave a Comment
/* The following C / C++ Program will find the smallest number among numbers in the integer array thus entered by the user. We have used while loop to read & write the array*/

Code:-
#include<iostream>
#include<conio.h>
using namespace std;
void main ()
{
int a[100];
int min,b=0,c,n;
cout<<"\nEnter the total number of elements in array(<100):";
cin>>n;
while (b<n)
{
cout<<"Enter the element number "<<b<<" : ";
cin>>c;
a[b]=c;
b=b+1;
}
b=0;
min=a[b];
//assuming that the 1st element is the minimum
while (b<n)
{
if (a[b]<=min)
//if anything else is found to be more larger than the current minimum
{
min=a[b];
}
b=b+1;
}
cout<<"\nSmallest number is : "<<min;
getche();
}



Output:
C / C++ Program to find the Smallest number from the array of integers: Output
C / C++ Program to find the Smallest number from the array of integers
Read More...

C / C++ Program to find the Largest number from the array of integers

Leave a Comment
/* The following C / C++ Program will find the largest number among numbers in the integer array thus entered by the user. We have used while loop to read & write the array*/

Code:-
#include<iostream>
#include<conio.h>
using namespace std;
void main ()
{
int a[100];
int max,b=0,c,n;
cout<<"\nEnter the total number of elements in array(<100):";
cin>>n;
while (b<n)
{
cout<<"Enter the element number "<<b<<" : ";
cin>>c;
a[b]=c;
b=b+1;
}
b=0;
max=a[b];
//assuming that the 1st element is the maximum
while (b<n)
{
if (a[b]>=max)
//if anything else is found to be more larger than the current maximum
{
max=a[b];
}
b=b+1;
}
cout<<"\nLargest number is : "<<max;
getche();
}



Output:
C / C++ Program to find the Largest number from the array of integers
C / C++ Program to find the Largest number from the array of integers

Read More...

C / C++ Program that count lines, integers, lower case letters, uper case letters, special case letters, words, spaces, consonants & vowels in a paragraph.

Leave a Comment
/* The  following C / C++ Program will count lines, integers, lower case letters, uper case letters, special case letters, words, spaces, consonants & vowels in a paragraph. User has to just enter the words/sentence/paragraph */

//CODE:-
#include<iostream>
#include<iomanip>
#include<stdlib.h>
using namespace std;
int main()
{
const int maxlength = 1000;
char text[maxlength] = {0};
cout<<"Enter few words:\n\n";
cin.getline(text,maxlength);
cout<<"You Have Entered:\n"<<text<<endl;
int space=0;
int vow=0;
int consonants=0;
int special=0;
int ucase=0;
int lcase=0;
int intr=0;
int line=0;
for(int i = 0 ; text[i] != '\0' ; i++)
{
if(isalpha(text[i]))
{
if(text[i]>=65 && text[i]<=90)
{
ucase++;
}
else if(text[i]>=97 && text[i]<=122)
{
lcase++;
}
switch(tolower(text[i]))
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
vow++;
break;
default:
consonants++;
break;
}}
else if(text[i]==' ')
{
space++;
}
else if((text[i]>=0&&text[i]<=47)||(text[i]>=58&&text[i]<=64)||(text[i]>=91&&text[i]<=96)||(text[i]>=123&&text[i]<=127))
{
special++;
}
else if(text[i]>=48 && text[i]<=57)
{
intr++;
}
else if(text[i]=='\n')
{
line++;
}
}
cout<<"No. of vowels="<<vow<<endl;
cout<<"No. of consonants="<<consonants<<endl;
cout<<"No. of spaces="<<space<<endl;
cout<<"No. of words="<<space+1<<endl;
cout<<"No. of special letters="<<special<<endl;
cout<<"No. of upper case letters="<<ucase<<endl;
cout<<"No. of lower case letters="<<lcase<<endl;
cout<<"No. of integers="<<intr<<endl;
cout<<"No. of lines="<<line;
system("pause");
return 0;
}


Screenshots:
C / C++ Program that count lines, integers, lower case letters, uper case letters, special case letters, words, spaces, consonants & vowels in a paragraph.
C / C++ Program that count lines, integers, lower case letters, uper case letters, special case letters, words, spaces, consonants & vowels in a paragraph.

Read More...

C / C++ Program to Print A Heart On Screen, using Characters

Leave a Comment
/* The following program will ask about the size of heart you wanna print. Then it will display the heart shape. Try to keep the input value below 20 in order to get symmetric shape. The lower part is essentially a triangle. For the upper half it is just drawing two semi-circles of size radius. So, it chooses the center point for each semicircle, then computes the distance from the center to the current point (basic Pythagorean formula). If that distance is less than the chosen radius from the center of either circle, it prints an a. Otherwise it prints a space. And the lower half is just a triangle*/

//CODE:-
#include <stdio.h>
#include <math.h>
#include<stdlib.h>
int main()
{

    double x, y, size;
    printf("\nHow Big is Your Heart? (Enter <20):");
    scanf("%lf",&size);
    for (x=0; x<size; x++)
    {
        for (y=0; y<=4*size; y++)
        {
            double dist1 = sqrt( pow(x-size,2) + pow(y-size,2) );
            double dist2 = sqrt( pow(x-size,2) + pow(y-3*size,2) );
            if (dist1 < size + 0.5 || dist2 < size + 0.5 )
                 printf("%c",97);
//For 'a'
            else
                 printf(" ");
        }
        printf("\n");
    }
    for (x = 1; x <= 2*size; x++)
    {
        for (y=0; y<x; y++)
        printf(" ");
        for (y=0; y<4*size + 1 - 2*x; y++)
            printf("%c",86);
//for 'V'
        printf("\n");
    }
    system("pause");
    return 0; 
}


SCREENSHOT:
C / C++ Program to Print A Heart On Screen, using Characters: C C++ Heart
C / C++ Program to Print A Heart On Screen, using Characters: C C++ Heart
Read More...

C / C++ program to print the Floyd's Triangle on Screen

Leave a Comment
/* A floyd's triangle is an right angled triangular array of natural numbers. It is defined by filling the rows of the triangle
with the consecutive numbers,starting with 1 in the top left corner:
The sample of this program is :
1
2  3
4  5  6
7  8  9  10

*/ 

#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,a=1,n;
printf("\nEnter the maximum limit:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<i+1;j++)
{
printf("%d ",a);
a=a+1;
}
printf("\n");
}
getch();
return 0;
}


Screenshot:
C / C++ program to print the Floyd's Triangle on Screen
C / C++ program to print the Floyd's Triangle on Screen

Read More...

C++ Program to ShutDown & Restart your Computer system (Applicable in Windows Operating System)

Leave a Comment
/* The following C++ program will ask you about the 2 choices of shutting down & restarting your system. After the option is entered the windows system file is executed, letting the system to restart or Shutdown. In this program the delay is 30 Seconds, but you can increase or decrease it as per your choice*/

#include<iostream>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int main()
{
int c;
cout<<"\nEnter your choice\n";
cout<<"1.Shutdown \n";
cout<<"2.Restart \n";
cin>>c;
switch(c)
{
case 1:cout<<"Your system will be closed after 30 seconds \n\n";
system("c:\\windows\\system32\\shutdown /s /t 30 \n\n");
break;

case 2:cout<<"your system will be restarted in 30 seconds\n\n";
system("c:\\windows\\system32\\shutdown /r /t 30\n\n");
break;

deafault:
cout<<"Invalid Chioce \n\n";
}
getch();
return 0;
}


Note: 
# If you have installed your windows version of other drive, say G:   so you need to change the following c:\\windows\\system32\\shutdown /r /t 30 as g:\\windows\\system32\\shutdown /r /t 30

# If your want to change the system shutdown or restart delay to 45 seconds you need to change the following c:\\windows\\system32\\shutdown /r /t 30 as c:\\windows\\system32\\shutdown /r /t 45.


Screenshot:

C++ Program to ShutDown & Restart your Computer system (Applicable in Windows Operating System)
C++ Program to ShutDown & Restart your Computer system (Applicable in Windows Operating System)
Read More...

Write a C / C++ Program To Multiply Two Integers Without Using Product/Multiply Operator

Leave a Comment
 /*C++ version of Program To Multiply Two Integers Without Using Product/Multiply Operator*/
#include<iostream>
using namespace std;

int main()
{
int a,b,sum=0;
cout<<"Enter The Value Of A: ";
cin>>a;

cout<<"Enter The Vlaue Of B:";
cin>>b;

while(b!=0)
{
sum = sum +a;
b--;
}
cout<<"Product="<<sum<<endl;

system("pause");
return 0;
}


 ----------------------------------------------------------------------------------------------------------
/*C version of Program To Multiply Two Integers Without Using Product/Multiply Operator */

#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,sum=0;
printf("Enter The Value Of A: ");
scanf("%d",&a);

printf("Enter The Vlaue Of B:");
scanf("%d",&b);

while(b!=0)
{
sum = sum +a;
b--;
}
printf("Multiply %d",sum);

getch();
return 0;
}



Output:
 
Write a C / C++ Program To Multiply Two Integers Without Using Product/Multiply Operator
Write a C / C++ Program To Multiply Two Integers Without Using Product/Multiply Operator

Read More...

WAP- Write A C / C++ program to Generate & Print the MAP OF India on screen

3 comments
/* The following C / C++ program when executed generates the MAP OF India & prints it on screen. */

#include<iostream>
using namespace std;
int main (void) {
    int a=10, b=0, c=10;
    char* bits ="TFy!QJu ROo TNn(ROo)SLq SLq ULo+UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^NBELPeHBFHT}TnALVlBLOFAkHFOuFETpHCStHAUFAgcEAelclcn^r^r\\tZvYxXyT|S~Pn SPm SOn TNn ULo0ULo#ULo-WHq!WFs XDt!";
    a = bits[b];
    while (a != 0) {
        a = bits[b];
        b++;
        while (a > 64) {
            a--;
            if (++c == 'Z') {
                c /= 9;
                putchar(c);
            } else {
                putchar(33 ^ (b & 0x01));
            }
        }
    }
  
system("pause");
}



Output :
WAP- Write A C / C++ program to Generate & Print the MAP OF India on screen
WAP- Write A C / C++ program to Generate & Print the MAP OF India on screen

More details about this code:
Basically, the string is a run-length encoding of the image: Alternating characters in the string say how many times to draw a space, and how many times to draw an exclamation mark consecutively. Here is an analysis of the different elements of this program:

The encoded string

The first 31 characters of this string are ignored. The rest contain instructions for drawing the image. The individual characters determine how many spaces or exclamation marks to draw consecutively.

Outer for loop

This loop goes over the characters in the string. Each iteration increases the value of b by one, and assigns the next character in the string to a.

Inner for loop

This loop draws individual characters, and a newline whenever it reaches the end of line. The number of characters drawn is a - 64. The value of c goes from 10 to 90, and resets to 10 when the end of line is reached.
Read More...

Write A C Program (WAP) to Print The Taj Mahal On Screen : C Graphics

2 comments
 
Write A C Program (WAP) to Print The Taj Mahal On Screen : C Graphics
Write A C Program (WAP) to Print The Taj Mahal On Screen : C Graphics

/* A C Program To Print The Taj Mahal on screen*/

#include<graphics.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
#include<process.h>

int main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:/TC/BGI");
int h=40;
line(0,440,639,440);



int l=-20;
line(28+l,400+h,33+l,333+h);
line(86+l,400+h,80+l,333+h);
//||||||||||||||||||||||||||||||Ist stage||||||||||||||||||||||||||||||||||||||||||||//
line(23+l,328+h,32+l,334+h);
// slant
line(88+l,328+h,80+l,334+h);
// slant
line(83+l,323+h,75+l,334+h);
// slant
line(75+l,323+h,70+l,332+h);
line(66+l,323+h,65+l,332+h);
// slant
line(57+l,323+h,57+l,332+h);
// slant
line(30+l,323+h,39+l,334+h); // slant
line(38+l,323+h,45+l,332+h);
line(48+l,323+h,51+l,332+h);
// slant

ellipse(57+l,320+h,350,190,34,5);
ellipse(57+l,327+h,350,190,34,5);
ellipse(57+l,337+h,0,180,25,5);
line(22+l,320+h,22+l,328+h);
line(91+l,320+h,91+l,327+h);
setfillstyle(6,15);
floodfill(60+l,320+h,15);

setfillstyle(10,15);

floodfill(60+l,320+h+15,15);


line(35+l,315+h,38+l,242+h);
line(80+l,315+h,75+l,242+h);

//||||||||||||||||||||||||||||||2ststage||||||||||||||||||||||||||||||||||||||||||||//
int t=-93;
line(23+4+l,328+t+3+h,32+5+l,334+t+h);
// slant
line(88+l,328+t+2+h,76+l,334+t+h);
// slant

line(78+l,323+t+3+h,71+l,332+t+h);
line(66+l,323+t+2+h,65+l,332+t+h);
// slant
line(57+l,323+t+2+h,57+l,332+t-2+h);
// slant

line(35+l,323+t+3+h,45-3+l,332+t+h);
line(48+l,323+t+2+h,51+l,332+t-2+h);
// slant

ellipse(57+l,320+t+3+h,360,190,30,5);
ellipse(57+l,327+t+3+h,360,190,30,5);
ellipse(57+l,337+t-1+h,0,180,18,5);

line(26+l,320+t+3+h,26+l,328+t+2+h);
line(88+l,320+t+3+h,88+l,327+t+3+h);
setfillstyle(6,15);
floodfill(60+l,320+h+t,15);
setfillstyle(10,15);
floodfill(60+l,320+h-35,15);

//||||||||||||||||||||||||||||||3rd stage||||||||||||||||||||||||||||||||||||||||||||//

line(38+l,225+h,41+l,152+h);
line(75+l,225+h,72+l,152+h);



t=-182;
line(32+l,328+t+4+h,32+7+l,334+t+h);
// slant
line(80+l,328+t+4+h,73+l,334+t+h);
// slant
line(76+l,323+t+5+h,71+l,332+t+h);
line(66+l,323+t+4+h,65+l,332+t+h);
// slant
line(57+l,323+t+4+h,57+l,332+t-2+h);
// slant
line(39+l,323+t+6+h,45+l,332+t+1+h);
line(48+l,323+t+4+h,51+l,332+t+h);
// slant

ellipse(57+l,320+t+6+h,360,190,24,5);
ellipse(57+l,327+t+4+h,360,190,24,5);
ellipse(57+l,337+t-1+h,0,170,16,5);

line(32+l,320+t+6+h,32+l,328+t+3+h);
line(81+l,320+t+6+h,81+l,327+t+3+h);

setfillstyle(6,15);
floodfill(60+l,322+h+t,15);
setfillstyle(10,15);
floodfill(60+l,322+h+t+30,15);
//GGF################TOWER%%%%%%%%%%
ellipse(51+l,132+h,340,216,4,15);
ellipse(62+l,131+h,327,216,4,15);
ellipse(72+l,132+h,327,216,2,15);
ellipse(42+l,132+h,327,216,2,15);
ellipse(57+l,107+h,0,170,16,5);
line(40+l,107+h,40+l,140+h);
line(75+l,107+h,75+l,140+h);

line(34+l,107+h,40+l,107+h);
line(75+l,107+h,81+l,107+h);

line(34+l,107+h,28+l,102+h);
//slant
line(81+l,107+h,87+l,102+h);

line(28+l,102+h,34+l,98+h);
line(87+l,102+h,81+l,98+h);

line(34+l,98+h,58+l,95+h);
line(58+l,95+h,81+l,98+h);


ellipse(65+l,92+h,104,190,30,30);

ellipse(50+l,92+h,350,76,30,30);

line(58+l,61+h,58+l,63+h);
circle(58+l,58+h,3);
line(58+l,55+h,58+l,53+h);
circle(58+l,50+h,2);
line(58+l,48+h,58+l,47+h);
circle(58+l,45+h,1);
line(58+l,44+h,58+l,41+h);
setfillstyle(6,15);
floodfill(60+l-2,322+h+t-60,15);

setfillstyle(10,15);
floodfill(60+l-2,322+h+t-30,15);


//=================================IIst tower============================//

 l=547;


line(28+l,400+h,33+l,333+h);
line(86+l,400+h,80+l,333+h);
//||||||||||||||||||||||||||||||Ist stage||||||||||||||||||||||||||||||||||||||||||||//
line(23+l,328+h,32+l,334+h); // slant
line(88+l,328+h,80+l,334+h);
// slant
line(83+l,323+h,75+l,334+h);
// slant
line(75+l,323+h,70+l,332+h);
line(66+l,323+h,65+l,332+h);
// slant
line(57+l,323+h,57+l,332+h);
// slant
line(30+l,323+h,39+l,334+h);
// slant
line(38+l,323+h,45+l,332+h);
line(48+l,323+h,51+l,332+h);
// slant

ellipse(57+l,320+h,350,190,34,5);
ellipse(57+l,327+h,350,190,34,5);
ellipse(57+l,337+h,0,180,25,5);
line(22+l,320+h,22+l,328+h);
line(91+l,320+h,91+l,327+h);
setfillstyle(6,15);
floodfill(60+l,320+h,15);

setfillstyle(10,15);

floodfill(60+l,320+h+15,15);


line(35+l,315+h,38+l,242+h);
line(80+l,315+h,75+l,242+h);

//||||||||||||||||||||||||||||||2st stage||||||||||||||||||||||||||||||||||||||||||||//
t=-93;
line(23+4+l,328+t+3+h,32+5+l,334+t+h);
// slant
line(88+l,328+t+2+h,76+l,334+t+h);
// slant

line(78+l,323+t+3+h,71+l,332+t+h);
line(66+l,323+t+2+h,65+l,332+t+h);
// slant
line(57+l,323+t+2+h,57+l,332+t-2+h);
// slant

line(35+l,323+t+3+h,45-3+l,332+t+h);
line(48+l,323+t+2+h,51+l,332+t-2+h);
// slant

ellipse(57+l,320+t+3+h,360,190,30,5);
ellipse(57+l,327+t+3+h,360,190,30,5);
ellipse(57+l,337+t-1+h,0,180,18,5);

line(26+l,320+t+3+h,26+l,328+t+2+h);
line(88+l,320+t+3+h,88+l,327+t+3+h);
setfillstyle(6,15);
floodfill(60+l,320+h+t,15);

 setfillstyle(10,15);
floodfill(60+l,320+h-35,15);

//||||||||||||||||||||||||||||||3rd stage||||||||||||||||||||||||||||||||||||||||||||//

line(38+l,225+h,41+l,152+h);
line(75+l,225+h,72+l,152+h);



t=-182;
line(32+l,328+t+4+h,32+7+l,334+t+h);
// slant
line(80+l,328+t+4+h,73+l,334+t+h);
// slant

line(76+l,323+t+5+h,71+l,332+t+h);
line(66+l,323+t+4+h,65+l,332+t+h);
// slant
line(57+l,323+t+4+h,57+l,332+t-2+h);
// slant

line(39+l,323+t+6+h,45+l,332+t+1+h);
line(48+l,323+t+4+h,51+l,332+t+h);
// slant

ellipse(57+l,320+t+6+h,360,190,24,5);
ellipse(57+l,327+t+4+h,360,190,24,5);
ellipse(57+l,337+t-1+h,0,170,16,5);

line(32+l,320+t+6+h,32+l,328+t+3+h);
line(81+l,320+t+6+h,81+l,327+t+3+h);

setfillstyle(6,15);
floodfill(60+l,322+h+t,15);
setfillstyle(10,15);
floodfill(60+l,322+h+t+30,15);
ellipse(51+l,132+h,340,216,4,15);
ellipse(62+l,131+h,327,216,4,15);
ellipse(72+l,132+h,327,216,2,15);
ellipse(42+l,132+h,327,216,2,15);
ellipse(57+l,107+h,0,170,16,5);
line(40+l,107+h,40+l,140+h);
line(75+l,107+h,75+l,140+h);

line(34+l,107+h,40+l,107+h);
line(75+l,107+h,81+l,107+h);

line(34+l,107+h,28+l,102+h);
//slant
line(81+l,107+h,87+l,102+h);

line(28+l,102+h,34+l,98+h);
line(87+l,102+h,81+l,98+h);

line(34+l,98+h,58+l,95+h);
line(58+l,95+h,81+l,98+h);


ellipse(65+l,92+h,104,190,30,30);

ellipse(50+l,92+h,350,76,30,30);

line(58+l,61+h,58+l,63+h);
circle(58+l,58+h,3);
line(58+l,55+h,58+l,53+h);
circle(58+l,50+h,2);
line(58+l,48+h,58+l,47+h);
circle(58+l,45+h,1);
line(58+l,44+h,58+l,41+h);
setfillstyle(6,15);
floodfill(60+l-2,322+h+t-60,15);

setfillstyle(10,15);
floodfill(60+l-2,322+h+t-30,15);
ellipse(51+l,132+h,340,216,4,15);
ellipse(62+l,131+h,327,216,4,15);
ellipse(72+l,132+h,327,216,2,15);
ellipse(42+l,132+h,327,216,2,15);
ellipse(57+l,107+h,0,170,16,5);
line(40+l,107+h,40+l,140+h);
line(75+l,107+h,75+l,140+h);

line(34+l,107+h,40+l,107+h);
line(75+l,107+h,81+l,107+h);

line(34+l,107+h,28+l,102+h);
//slant
line(81+l,107+h,87+l,102+h);

line(28+l,102+h,34+l,98+h);
line(87+l,102+h,81+l,98+h);

line(34+l,98+h,58+l,95+h);
line(58+l,95+h,81+l,98+h);


ellipse(65+l,92+h,104,190,30,30);

ellipse(50+l,92+h,350,76,30,30);

line(58+l,61+h,58+l,63+h);
circle(58+l,58+h,3);
line(58+l,55+h,58+l,53+h);
circle(58+l,50+h,2);
line(58+l,48+h,58+l,47+h);
circle(58+l,45+h,1);
line(58+l,44+h,58+l,41+h);


//=================================Ist tower========================//

//+++++++++++++++++++++++++++++++++TAJ mahal++++++++++++++++++++++++//

rectangle(275,290,365,440);
// inner
rectangle(268,283,372,440);
// //inner
setfillstyle(1,15);
floodfill(274,294,15);
line(280,440,280,350);

ellipse(315,349,130,180,35,40);
ellipse(275,280,290,326,53,40);

line(360,440,360,350);
ellipse(325,349,360,50,35,40);
ellipse(361,280,216,255,53,40);
setfillstyle(9,7);
floodfill(277,386,15);
putpixel(277,386,14);

line(280,360,359,360);
line(280,364,359,364);
setfillstyle(1,15);
floodfill(281,362,15);

rectangle(295+4,370,345-4,440);
rectangle(292+4,367,348-4,440);
setfillstyle(1,15);
floodfill(294+4,369,15);
rectangle(296,378,344,380);
floodfill(301,379,15);


line(302,405,302,440);
line(338,405,338,440);
ellipse(327,405,108,180,25,20);

ellipse(313,405,360,74,25,20);

setfillstyle(7,15);

line(329,390,329,440);
line(310,391,310,440);
line(311,402,329,402);
line(311,422,329,422);
line(302,412,310,412);
line(329,412,338,412);

line(302,428,310,428);
line(329,428,338,428);



int p=-60;
line(302,405+p,302,440+p-20);
line(338,405+p,338,440+p-20);
ellipse(327,405+p,108,180,25,20);

ellipse(313,405+p,360,74,25,20);
setfillstyle(7,15);
floodfill(311,406,15);
line(329,390+p,329,440+p-20);
line(310,391+p,310,440+p-20);
line(311,402+p,329,402+p);
line(311,422+p-7,329,422+p-7);
line(302,412+p,310,412+p);
line(329,412+p,338,412+p);



////////////////////////////////////2nd portion/////////////////////


rectangle(245,260,400,440);
// inner
rectangle(230,245,415,440);
// inner

rectangle(230,425,275,440);
setfillstyle(1,15);
floodfill(231,426,15);
floodfill(249,426,15);
rectangle(230+135,425,275+140,440);

floodfill(231+160,426,15);
floodfill(249+159,426,15);


line(415,290,415,440);
line(420,245,420,440);

line(415,240,415,205);
line(420,240,420,205);


line(225,245,225,440);
//vertical
line(230,250,230,440);

line(225,240,225,205);
//vertical
line(230,240,230,205);

line(222,240,425,240);
line(222,245,425,245);
//horizontal

ellipse(222,242.5,90,270,2.5,2.5);
ellipse(425,242.5,270,90,2.5,2.5);

rectangle(231,230,414,239);



ellipse(227,206,0,180,9,1);
ellipse(227,204,0,180,9,1);
putpixel(220,204,15);
putpixel(220,205,15);
putpixel(220,206,15);
putpixel(235,204,15);
putpixel(235,205,15);
putpixel(235,206,15);
ellipse(227,203,0,180,6,7);
line(227,195,227,192);
int r=190;

ellipse(227+r,206,0,180,9,1);
ellipse(227+r,204,0,180,9,1);
putpixel(220+r,204,15);
putpixel(220+r,205,15);
putpixel(220+r,206,15);
putpixel(235+r,204,15);
putpixel(235+r,205,15);
putpixel(235+r,206,15);

ellipse(227+r,203,0,180,6,7);
line(227+r,195,227+r,192);


ellipse(315,170,140,210,105,100);
ellipse(330,170,330,40,105,100);

ellipse(292,167,105,140,75,95);
ellipse(353,167,40,75,75,95);

ellipse(323,78,350,190,60,8);
ellipse(323,77,350,190,60,8);



ellipse(240,24,321,358,78,71);
ellipse(192,40,342,7,128,100);

ellipse(448,30,180,203,128,100);
ellipse(443,5,194,220,128,100);
ellipse(438,-9,203,234,128,100);
ellipse(198,-6,310,340,128,100);

ellipse(319,30,0,360,7,2);

floodfill(320,29,15);
circle(319,24,3);
line(319,20,319,18);
circle(319,14,4);
line(319,9,319,0);
circle(319,2,1);
line(316,6,322,6);
line(316,6,314,4);
line(322,6,324,4);
ellipse(321,258,48,130,140,50);
ellipse(321,255,48,130,140,50);

ellipse(321,241,48,130,140,50);
ellipse(321,238,48,130,140,50);
delay(300);
setfillstyle(10,15);

floodfill(322,160,15);
setfillstyle(6,15);

floodfill(322,193,15);




rectangle(150,283,225,294);
line(150,298,225,298);

line(150,240,150,440);
//pole
line(146,240,146,440);

line(150,299,150,440);
//pole
line(146,299,146,440);


r=-80;
int n=34;

ellipse(227+r,206+n,0,180,9,1);
ellipse(227+r,204+n,0,180,9,1);
putpixel(220+r,204+n,15);
putpixel(220+r,205+n,15);
putpixel(220+r,206+n,15);
putpixel(235+r,204+n,15);
putpixel(235+r,205+n,15);
putpixel(235+r,206+n,15);

ellipse(227+r,203+n,0,180,6,7);
line(227+r,195+n,227+r,192+n);

l=128;
h=150;

ellipse(51+l,132+h-7,340,216,4,15);
ellipse(62+l,131+h-7,327,216,4,15);
ellipse(72+l,132+h-7,327,216,2,15);
ellipse(42+l,132+h-7,327,216,2,15);
ellipse(57+l,107+h,0,170,16,5);
line(40+l,107+h,40+l,140+h-7);
line(75+l,107+h,75+l,140+h-7);

line(34+l,107+h,40+l,107+h);
line(75+l,107+h,81+l,107+h);

line(34+l,107+h,28+l,102+h);
//slant
line(81+l,107+h,87+l,102+h);

line(28+l,102+h,34+l,98+h);
line(87+l,102+h,81+l,98+h);

line(34+l,98+h,58+l,95+h);
line(58+l,95+h,81+l,98+h);


ellipse(65+l,92+h,104,190,30,30);

ellipse(50+l,92+h,350,76,30,30);

line(58+l,61+h,58+l,63+h);
circle(58+l,58+h,3);
line(58+l,55+h,58+l,53+h);
circle(58+l,50+h,2);
line(58+l,48+h,58+l,47+h);
circle(58+l,45+h,1);
line(58+l,44+h,58+l,41+h);


line(100-5,240+15,100-5,440);
//pole
line(96-5,240+15,96-5,440);

r=-134;
n=49;
ellipse(227+r,206+n,0,180,9,1);
ellipse(227+r,204+n,0,180,9,1);
putpixel(220+r,204+n,15);
putpixel(220+r,205+n,15);
putpixel(220+r,206+n,15);
putpixel(235+r,204+n,15);
putpixel(235+r,205+n,15);
putpixel(235+r,206+n,15);

ellipse(227+r,203+n,0,180,6,7);
line(227+r,195+n,227+r,192+n);


line(146,294,97,302);
line(146,298,97,306);

line(146,283,97,291);


rectangle(155,302,220,364);
rectangle(155,302+70,220,364+75);

int q=-133;
int d=-2;
line(302+q-5,405+d,302+q-5,440+d);
line(338+q+5,405+d,338+q+5,440+d);
ellipse(327+q+5,405+d,108,180,35,30);

ellipse(313+q-5,406+d,360,74,35,30);


d=-77;
line(302+q-5,405+d,302+q-5,440+d);
line(338+q+5,405+d,338+q+5,440+d);
ellipse(327+q,405+d,105,180,30,25);

ellipse(313+q,405+d,360,80,30,25);
putpixel(163,300,11);
setfillstyle(6,15);
floodfill(163,330,15);
floodfill(160,380,15);

line(141,305,141,360);
line(101,310,101,365);
line(141,305,101,310);
line(141,360,101,365);


int x=70;
line(141,305+x,141,440);
line(101,310+x,101,440);
line(141,305+x,101,310+x);



q=-200;
line(302+q+4,405+d,302+q+4,440+d);
line(338+q-1,405+d,338+q-1,440+d-2);
ellipse(327+q,405+d,105,180,20,15);
ellipse(313+q+4,405+d,360,80,20,15);

d=1;
line(302+q+4,405+d,302+q+4,440+d-2);
line(338+q-1,405+d,338+q-1,440+d-2);
ellipse(327+q,405+d,105,180,20,15);
ellipse(313+q+4,405+d,360,80,20,15);

rectangle(178,415,197,439);
setfillstyle(7,15);
floodfill(179,416,15);
rectangle(178,415-75,197,440-76);
setfillstyle(7,15);
floodfill(179,415-75+1,15);

line(130-3,417,130-3,440);
line(113+3,420,113+3,440);

line(113+3,420,130-3,417);
putpixel(114,423,4);
line(113,440,130,440);
floodfill(114+3,423,15);



int a=-76;
line(130-3,417+a,130-3,440+a-3);
line(113+3,420+a,113+3,440+a);

line(113+3,420+a,130-3,417+a);
putpixel(114,423,4);
floodfill(114+3,423+a,15);



line(10,400+h,615,400+h);



int e=270;
rectangle(150+e,283,226+e,294);
line(146+e+4,294,225+e,294);
line(146+e+4,298,225+e,298);


line(150+e+80,240,150+e+80,440); //pole
line(146+e+80,240,146+e+80,440);

line(150+e+80,299,150+e+80,440); //pole
line(146+e+80,299,146+e+80,440);





l=400;
h=+149;
ellipse(51+l,132+h-7,340,216,4,15);
ellipse(62+l,131+h-7,327,216,4,15);
ellipse(72+l,132+h-7,327,216,2,15);
ellipse(42+l,132+h-7,327,216,2,15);
ellipse(57+l,107+h,0,170,16,5);
line(40+l,107+h,40+l,140+h-7);
line(75+l,107+h,75+l,140+h-7);

line(34+l,107+h,40+l,107+h);
line(75+l,107+h,81+l,107+h);

line(34+l,107+h,28+l,102+h);
//slant
line(81+l,107+h,87+l,102+h);

line(28+l,102+h,34+l,98+h);
line(87+l,102+h,81+l,98+h);

line(34+l,98+h,58+l,95+h);
line(58+l,95+h,81+l,98+h);


ellipse(65+l,92+h,104,190,30,30);

ellipse(50+l,92+h,350,76,30,30);

line(58+l,61+h,58+l,63+h);
circle(58+l,58+h,3);
line(58+l,55+h,58+l,53+h);
circle(58+l,50+h,2);
line(58+l,48+h,58+l,47+h);
circle(58+l,45+h,1);
line(58+l,44+h,58+l,41+h);

r=270;
n=n-15;

ellipse(227+r,206+n,0,180,9,1);
ellipse(227+r,204+n,0,180,9,1);
putpixel(220+r,204+n,15);
putpixel(220+r,205+n,15);
putpixel(220+r,206+n,15);
putpixel(235+r,204+n,15);
putpixel(235+r,205+n,15);
putpixel(235+r,206+n,15);

ellipse(227+r,203+n,0,180,6,7);
line(227+r,195+n,227+r,192+n);



line(146+e+135,302,97+e+135,294);
line(146+e+135,306,97+e+135,298);

line(146+e+135,291,97+e+135,283);



line(100-5+e+190,240+15,100-5+e+190,440);
//pole
line(96-5+e+190,240+15,96-5+e+190,440);

r=325;
n+=15;
ellipse(227+r,206+n,0,180,9,1);
ellipse(227+r,204+n,0,180,9,1);
putpixel(220+r,204+n,15);
putpixel(220+r,205+n,15);
putpixel(220+r,206+n,15);
putpixel(235+r,204+n,15);
putpixel(235+r,205+n,15);
putpixel(235+r,206+n,15);

ellipse(227+r,203+n,0,180,6,7);
line(227+r,195+n,227+r,192+n);


rectangle(155+e,302,220+e,364);
rectangle(155+e,302+70,220+e,364+75);


q=140;
d-=1;
line(302+q-5,405+d,302+q-5,440+d);
line(338+q+5,405+d,338+q+5,440+d);
ellipse(327+q+5,405+d,108,180,35,30);

ellipse(313+q-5,406+d,360,74,35,30);

d=-77;
line(302+q-5,405+d,302+q-5,440+d);
line(338+q+5,405+d,338+q+5,440+d);
ellipse(327+q,405+d,105,180,30,25);

ellipse(313+q,405+d,360,80,30,25);
putpixel(163,300,11);
setfillstyle(6,15);
floodfill(163,330,15);
floodfill(160,380,15);
e=e-15;
line(141+e+150,305+5,141+e+150,360+5);
line(101+e+150,310-5,101+e+150,365-5);
line(101+e+150,305,141+e+150,310);
line(101+e+150,360,141+e+150,365);

int v=75;
line(141+e+150,305+5+v-5,141+e+150,440);
line(101+e+150,310-5+v-5,101+e+150,440);
line(101+e+150,305+v-5,141+e+150,310+v-5);

e=e+18;
rectangle(178+e,415,197+e,439);
setfillstyle(7,15);
floodfill(179+e,416,15);
int f=-75;
rectangle(178+e,415+f,197+e,439+f);
setfillstyle(7,15);
floodfill(179+e,416+f,15);


e+=130;
line(130-3+e,440+a-2,130-3+e,417+a+2);
line(113+3+e,440+a-2,113+3+e,420+a-2);

line(113+3+e,417+a,130-3+e,420+a);
putpixel(114+e,423,4);
floodfill(114+3+e,423+a,15);

a=1;
line(130-3+e,440+a-2,130-3+e,417+a+2);
line(113+3+e,440+a-2,113+3+e,420+a-2);

line(113+3+e,417+a,130-3+e,420+a);
putpixel(114+e,423,4);
line(113+3+e,440,130-3+e,440);
floodfill(114+3+e,423+a,15);


q=204;
line(302+q+4,405+d,302+q+4,440+d-2);
line(338+q-1,405+d,338+q-1,440+d+2);
ellipse(327+q,405+d,105,180,20,15);
ellipse(313+q+4,405+d,360,80,20,15);
q=204;

d=0;
line(302+q+4,405+d,302+q+4,440+d-1);
line(338+q-1,405+d,338+q-1,440+d);
ellipse(327+q,405+d,105,180,20,15);
ellipse(313+q+4,405+d,360,80,20,15);
line(302+q+4,440,302+q+4,440);




setfillstyle(10,15);
floodfill(322,160,15);
setfillstyle(6,15);

floodfill(322,193,15);
///////////////////////////////////////////////walls//////////////
setfillstyle(9,15);
floodfill(110,294,15);
floodfill(210,290,15);
floodfill(430,290,15);
floodfill(520,290,15);
/////////////////////////////////////////////poles
setfillstyle(6,15);
floodfill(93,394,15);
floodfill(148,394,15);
floodfill(227,394,15);
floodfill(417,394,15);
floodfill(498,394,15);
floodfill(553,394,15);


setfillstyle(9,15);
floodfill(185,224,15);
floodfill(465,224,15);


while(!kbhit())
{
delay(40);
putpixel(random(640),random(248),random(15));
}

system("pause");
return 0;
}



Sample Output:
 
Write A C Program (WAP) to Print The Taj Mahal On Screen : C Graphics
Write A C Program (WAP) to Print The Taj Mahal On Screen : C Graphics
Read More...

Write A C/C++ Program (WAP) To Draw a Fish / Shark Figure using '*' : C++ Graphics

Leave a Comment
/* The following program when executed gives a fish / shark figure made of '*' on the sceen */

#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
int i,j,k=11,a=15,t,t1,f=0,c=0,d=0,b=0; 

//Chenge the parameters 'k' & 'a' for getting your own desired shape of the fish
for(i=1;i<=14;i++)
{
if(i<=6)
{
k+=2;
a-=2;
t=k;
t1=a;
}
else if(i==7 || i==8)
{
c=0;
a=1;
k=31;
}
else{
if(f==0)
{
k=t;
a=t1;
f=1;
}
else
{
a+=2;
k-=2;
}
}
if(i>=4 && i<=6)
{
if(d==0)
{
c=16;
d=1;
}
c-=3;
}
if(i>=9 && i<=11)
{
if(d==1)
{
c=4;
d=0;
}
c+=3;
}
if(i==12)
c=0;
if(i>=5 && i<=6)
b++;
else if(i>=10)
b--;
for(j=1;j<=k+c;j++)
{
if(i<=8 && j>=a && j<=k || j>=k+c-b)
printf("*");
else
if(i>=9 && j>=a && j<=k || j==k+c)
printf("*");
else
printf(" ");
}
printf("\n");
}
system("pause");
}



Sample Output:

Write A C/C++ Program (WAP) To Draw a Fish / Shark Figure using '*'
Write A C/C++ Program (WAP) To Draw a Fish / Shark Figure using '*'
Read More...

C++ Program Code For finding the roots of a quadratic equation

Leave a Comment
/* The following C++ Code will calculate the roots of the quadratic equation, user is prompted to enter the coefficient a, b, & c. The result is displayed after that. */  


#include<iostream.h>
#include<stdlib.h>
#include<math.h>

void main()
{
 float a,b,c,d,r1,r2;
 cout<<"\nFor ax^2+bx+c\n";
 cout<<"Enter value of coefficient a, b & c : ";
 cin>>a>>b>>c;
 d=pow(b,2)-4*a*c;
 if(d==0)
 {
  r2=r1=(-b)/(2*a);
  cout<<"Roots are real & equal";
 }
 else if(d>0)
 {
  r1=-(b+sqrt(d))/(2*a);
  r2=-(b-sqrt(d))/(2*a);
  cout<<"Roots are Real & Distinct";
 }
 else //for case of d<0
 {
  cout<<"Roots are imaginary";
  system("pause");
  exit(0);
 }
 cout<<"\nRoot 1= "<<r1<<"\nRoot 2= "<<r2;
 system("pause");
}


 Screenshots:
C++ Program Code For finding the roots of a quadratic equation
Read More...

C / C++ Program Code to Calculate the sum of digits in a single line of code, iteratively in for loop statement

Leave a Comment
/* The Following C / C++ program code uses only a single line of code in order to calculate the sum of digits present in it. The single line of code is iteratively implemented in the for loop.*/

#include<stdio.h>
#include<stdlib.h>
 void main()
{
int n,s=0;
printf("\nEnter The number : ");
scanf("%d", &n);
for(;n > 0;s+=n%10,n/=10); //Calculation of sum of digits
printf("\nSum of digits is = %d\n", s);
system("pause");
}


Screenshot:
C / C++ Program Code to Calculate the sum of digits in a single line of code, iteratively in for loop statement

Read More...

C++ Program Code to perform binary search on an array of elements, which is arranged in ascending order

Leave a Comment
/* The following C++ Program Code will perform the binary search on a list of elements or array of elements, which is arranged in ascending orderThe user is first asked about the total number of elements & then he is asked to enter those many elements in the list in ascending order. The user can also use any sorting algorithm in order to get rid of this constraint*/
/* See bubble sorting algorithm, insertion sorting algorithm, merge sort algorithm, quick sort algorithm, & selection sort algorithm */

#include<iostream>
#include<stdlib.h>
using namespace std;

template<class T>
T bin(T a[20],T n,T t)
{
                 int l,r,mid;
                 l=0;
                 r=n-1;
                 while(l<=r)
                 {
                                   mid=(l+r)/2;
                                   if(t==a[mid])
                                   return mid;
                                   else
                                   if(t<a[mid])
                                   r=mid-1;
                                   else
                                   l=mid+1;
                 }
                 return -1;
}

int main()
{
    int a[20],n,t,p,i;
    cout<<"\nEnter number of elements :";
    cin>>n;
    cout<<"\nAs binary search algorithm works in sorted array!";
    cout<<"\nEnter "<< n <<" values in ascending order : ";
    for(i=0;i<n;i++)
    cin>>a[i];
    cout<<"\nEnter the element to find : ";
    cin>>t;
    p=bin(a,n,t);
    if(p!=-1)
    cout<<"\nThe element is found at "<<p+1<<" position";
    else
    cout<<"\nElement Not Found!!";
    system("pause");
    return 0;
}


Screenshot:
C++ Program Code to perform binary search on an array of elements, which is arranged in ascending order

Read More...

C++ Program Code for the implementation of bubble sorting algorithm on an array

Leave a Comment
 /* The following C++ Program Code is for the implementation of bubble sorting algorithm. It also use the concept of the template class, so no need of worry about the input array's data type. The user is first asked about the total number of elements that are to be in the list. Then he enters the data, after it the program again process the data, & shows the output sorted array. */

#include<iostream>
#include<stdlib.h>
using namespace std;


template <class T>
void bubble(T a[],int n)
{
     int i,j,t;
     for(i=0;i<n;i++)
     {
                     for(j=0;j<n-i-1;j++)
                     {
                                       if(a[j]>a[j+1])
                                       {
                                                    t=a[j];
                                                    a[j]=a[j+1];
                                                    a[j+1]=t;
                                       }
                     }
     }
}

int main()
{
    int a[100],i,n;
    cout<<"\nEnter number of element : ";
    cin>>n;
    cout<<"\n Enter elements( Use Spacebar as separator )\n";
    for(i=0;i<n;i++)
    {
                    cin>>a[i];
    }
    cout<<"\n\nBefore sorting \n";
    for(i=0;i<n;i++)
    {
                    cout<<a[i]<<"\t";
    }
    bubble(a,n);
    cout<<"\n\nAfter sorting \n";
    for(i=0;i<n;i++)
    {
                    cout<<a[i]<<"\t";
    }
    cout<<endl;
    system("pause");
    return 0;
}


Screenshot:
C++ Program Code for the implementation of bubble sorting algorithm on an array

Read More...

C++ program code to implement the circular linked list, utilizing the concept of template class

Leave a Comment
/* The following C++ Program Code will be used to implement the circular linked list. The user is asked first to create the circular linked list, & when he is done entering the element in the list , he will enter 0. After creation to the initial circular list, he is given the option of insertion, deletion & display of the circular linked list thus created. Also provided with the program exit option. */

#include<iostream>
#include<stdlib.h>
using namespace std;

template<class T>
class node
{
     public:
              T data;
              node<T> *next;
};

template<class T>
class list
{
      private:
              node<T> *first;
      public:
      list();
      ~list();
      void create();
      void del();
      void ins();
      void disp();
};

template<class T>
list<T>::list()
{
               first=NULL;
}

template<class T>
list<T>::~list()
{
                node<T> *next;
                while(first)
                {
                            next=first->next;
                            delete first;
                            first=next;
                }
}

template<class T>
void list<T>::create()
{
                     T a;
                     node<T> *cur,*ptr;
                     first=NULL;
                     cout<<"\nEnter data : ";
                     cin>>a;
                     while(a)
                     {
                             cur=new node<T>;
                             cur->data=a;
                             cur->next=NULL;
                             if(first==NULL)
                             first=cur;
                             else
                             ptr->next=cur;
                             ptr=cur;
                             cout<<"\nEnter data : ";
                             cin>>a;
                     }
              ptr->next=first;  
}

template<class T>
void list<T>::ins()
{
                 node<T> *cur,*ptr,*exmp;
                 T ele;
                 char ch;
                 ptr=exmp=first;
                 cur=new node<T>;
                 cout<<"\nEnter data : ";
                 cin>>cur->data;
                 cur->next=NULL;
                 cout<<"\nDo you want to insert at first [y/n] ? : ";
                 cin>>ch;
                 if(ch=='Y'||ch=='y')
                 {
                                     while(ptr->next!=first)
                                     {
                                                          ptr=ptr->next;
                                     }
                                     cur->next=first;
                                     first=cur;
                                     ptr->next=first;
                 }
                 else 
                 {
                     cout<<"\nAfter which element you want to insert ? : ";
                     cin>>ele;
                     do
                     {
                              if(exmp->data==ele)
                              {
                                                 cur->next=exmp->next;
                                                 exmp->next=cur;
                              }
                              exmp=exmp->next;
                     }while(exmp!=first);
                 }
}

template<class T>
void list<T>::del()
{
                     T ele;
                     char ch;
                     node<T> *ptr,*ptr1;
                     ptr=ptr1=first;
                     cout<<"\nDo you want to delete the first element [y/n] ? : ";
                     cin>>ch;
                     if(ch=='y'||ch=='Y')
                     {
                            while(ptr->next!=first)
                            {
                                                   ptr=ptr->next;                 
                            }
                            first=ptr1->next;
                            ptr->next=first;
                      }
                     else
                     {
                         cout<<"\nWhich element to delete? : ";
                         cin>>ele;
                         do
                         {
                                  if(ptr1->next->data==ele)
                                  {
                                                           ptr1->next=ptr1->next->next;
                                                           break;
                                  }
                                  ptr1=ptr1->next;
                         }while(ptr1!=first);
                      }
}

template<class T>
void list<T>::disp()
{
     node<T> *ptr;
     ptr=first;
     do
     {
             cout<<ptr->data<<"---->";
             ptr=ptr->next; 
     }while(ptr!=first);
}

int main()
{
    int n;
    list <int> x;
    cout<<"\nEnter the elements to create initial list (Enter 0 when done)\n";
    x.create();
    do
    {
                   cout<<"\n 1.Insert Element \n2.Delete Element \n3.Display Element \n4.Exit \n";
                   cout<<"\nEnter option : ";
                   cin>>n;
                   switch(n)
                   {
                            case 1: x.ins();
                            break;
                            case 2: x.del();
                            break;
                            case 3: x.disp();
                            break;
                            case 4: exit(0);
                            break;
                            default: cout<<"\nWrong Choice Entered!";
                   }
    }while(n<=4);
    system("pause");
    return 0;
}


Screenshot:
C++ program code to implement the circular linked list, utilizing the concept of template class

Read More...