WELCOME TO MY BLOG BY SHABEEB.K

C,C++ PROGRAMMING: 2013

Search This Blog

Saturday, 28 December 2013

IMPLEMENT LIST USING ARRAY.


  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include<iostream.h>
#include<conio.h>
int count=0;
int list[10];
int size,i;          //veribles
int op,ch,dele;
int flag=1;
class lists
{
public:

void input()
{
cout<<"ENTER ARRAYS SIZE\n";  //reading array size from user
cin>>size;
}

void insert()
{
clrscr();
if(count<size)                   //element can inserted only if count is
{                                  less than array size.
count++;                         //increment count by 1 when next to create
cout<<"ENTER ELEMENT\n";           memory for next element.
cin>>list[count];               //reading array element from user.

}
else                           //if count become equal to the array size 
{                                which means List is full.
cout<<"LIST IS FULL\n";
}

}

void del()                            //Function to delete.
{                   
if(count<=0)
{                                    //List is empty if count is less than
cout<<"THE LIST IS EMPTY\n";           or equal to 0.
}
else                               //choice to delete element.                                  
{     
cout<<"1:TO DELETE FROM TOP\n";   
cout<<"2:TO DELETE FROM BOTTUM\n";
cout<<"3:TO DELETE USING ADDRESS\n";
cin>>ch;


switch(ch)                         
{
case 1 :              //if choice is selected 1 its easly delete by 
count--;                decrement count by 1 to delete element from top.
break;

case 2 :
for(i=1;i<=count;i++)   //if choice is 2 selected to delete element from bottom
{
list[i]=list[i+1]; //update current element of aarray to next element and 
}
count--;           //decrement count by 1.
break;


case 3 :            //if choice selected 3 to delete by entering address of
for(i=1;i<=count;i++)   the element.
{
cout<<"\n"<<i<<" "<<list[i];    //programm to display address and its elements.
}
cout<<"\nENTER ADDRESS TO DELETE\n";  //recieve address from user to delete.
cin>>dele;

list[dele]=NULL;          //make that addressed memory location to NULL.

for(i=dele;i<=count;i++) //update current values of array to next value of array
{                          from specified address "dele"
list[i]=list[i+1];         
}
count--;               //decrement count by 1.
break;
}
}
}


void display()       //function to display elements of list.
{
if(count==0)         //List is empty if count is equal to 0.
{
cout<<"THE LIST IS EMPTY\n";
}
else               //else display element.
{
cout<<"ELEMENTS IN THE LIST\n";
for(i=1;i<=count;i++)
{
cout<<list[i]<<",";
}
}
}
};



void main()
{

lists s;
if(flag==1)
{
clrscr();
s.input();
flag=0;
}

cout<<"\n1:TO INSERT ITEM\n";
cout<<"2:TO DELETE ITEM\n";
cout<<"3:TO DISPLAY ITEM\n";
cin>>op;

switch(op)
{
case 1 : s.insert(); main();  
break;
case 2 : s.del(); main();
break;
case 3 : s.display(); main();
break;
}
}

Saturday, 30 November 2013

DISPLAY NUMBERS IN DIOGNALY


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<iostream.h>
#include<conio.h>
int n=1,i=0;
class numbers
{
public:

void display()
{
cout<<"\n";
for(i=1;i<=n;i++)
{
cout<<" "<<i;
}
}

void next()
{
if(n<20)
{
n++;
display();
next();
}
}
};

void main()
{
numbers s;
clrscr();
s.display();
s.next();
getch();
}

Friday, 29 November 2013

DISPLAY MULTIPLICATION FROM 1 to ANY LIMIT.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<iostream.h>
#include<conio.h>
int value=1,p,i;
int limit;
class multiplication
{

public:

void read()
{
cout<<"Enter limit of multiplication displayed\n";
cin>>limit;
}

void calculate()
{
for(i=1;i<=10;i++)
{
p=(value*i);
cout<<i<<"x"<<value<<"="<<p<<"\n";;
}
}

void next()
{
if(value<limit)
{
cout<<"\n";
value++;
calculate();
next();
}
}
};

void main()
{
multiplication s;
clrscr();
s.read();
s.calculate();
s.next();
getch();
}

CONVERT A MATRIX INTO NONE ZERO SPARSE MATRIX


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20][20],r,c,j,i;
clrscr();
cout<<"ENTER ORDER\n";
cin>>r; cin>>c;
cout<<"ENTER ELEMENT\n";
for(i=0;i<r;i++)
{
printf("\n");
for(j=0;j<c;j++)
{
cin>>a[i][j];
}
}

printf("ORIGINAL MATRIX\n");
for(i=0;i<r;i++)
{
printf("\n");
for(j=0;j<c;j++)
{
printf(" %d ",a[i][j]);
}
}
printf("\n\n\n");
printf("NONE ZERO SPARSE MATRIX\n");

for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
if(a[i][j]!=0)
{
printf("\n %d  %d  %d ",(i+1),(j+1),a[i][j]);
}
}
}
getch();
}

Thursday, 28 November 2013

FIND POWER OF A NUMBER.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<iostream.h>
#include<conio.h>
long long value=1;
class power
{
public:
int base;
int exp;


void read()
{
cout<<"ENTER BASE NUMBER\n";
cin>>base;
cout<<"ENTER EXPONENT NUMBER\n";
cin>>exp;
}

void find()
{
while(exp!=0)
{
value=value*base;
exp--;
}
cout<<value;
}
};

void main()
{
clrscr();
power s;
s.read();
s.find();
getch();
}

PROGRAMM FOR BANKING OPERATTION DEPOSIT , WIDRWA AND SHOW CURENT BALANCE.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include<iostream.h>
#include<conio.h>
int flag=0;
int dep=0;
int wid=0;

int balance=0;
class bank
{
public:

void deposit()
{
display();
cout<<"ENTER AMOUNT\n";
cin>>dep;
balance=balance+dep;
display();
}


void widraw()
{

display();
if(balance>500)
{
cout<<"ENTER AMOUNT TO WIDRAW\n";
cin>>wid;
}
else
{
cout<<"\nACCCOUNT BALANCE IS LOW! "<<balance<<"\n";
}



if(balance>wid)
{
if(balance-wid>=500)
balance=(balance-wid);
display();
}
else
{
cout<<"TRANSACTION CANNOT PROCCEED INSUFFICIANT BALANCE\n";
display();
}
}

void display()
{
cout<<"CURRENT BALANCE: "<<balance<<"\n";
}
};



void main()
{

if(flag==0)
{
clrscr();
}

flag=1;
bank s;
int ch;

cout<<"\n1:DEPOSIT\n2:WIDRAW\n3:SHOW BALANCE\n";
cin>>ch;

switch(ch)
{
case 1 : s.deposit(); main();
break;
case 2 : s.widraw();  main();
break;
case 3 : s.display(); main();
break;
}
getch();
}




LEANEAR SEARCH


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<iostream.h>
#include<conio.h>
int m[10]={8,4,8,5,6,4,7,8,7,8};
int n=10;
int flag;
class search
{
public:

int i,el;

void input()
{
cout<<"\nELEMENTS IN THE LIST\n";
for(i=0;i<n;i++)
{
cout<<m[i]<<",";
}
cout<<"\nENTER ELEMENT TO SEARCH\n";
cin>>el;
}


void se()
{
flag=1;
for(i=0;i<n;i++)
{
if(m[i]==el)
{
cout<<"\nELEMENT "<<m[i]<<" FOUND AT LOCATION "<<i<<"\n";
flag=0;
}
}

if(flag==1)
{
cout<<"SEARCH UNSUCCESSFUL\n";
}
}
};

void main()
{
clrscr();
search s;
s.input();
s.se();

getch();
}

CREATE TEXT FILE.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#include<stdio.h>
#include<iostream.h>
#include<conio.h>
void main()
{
char a[80];
cout<<"ENTER A STRING CHARACTER\n";
cin>>a;

FILE *fp; //fp set pointer to FILE.

fp=fopen("CPROGRAM.txt","a"); //syntax to create a text named "CPROGRAM.txt" file. 
fprintf(fp,"\n%s",a);     //syntax to write data to "CPROGRAM.txt" file that u entred  character.
fclose(fp);           //syntax to save this file.
cout<<"FILE ""CPROGRAM"" IS CREATED\n  To see this file  check your TC/BIN location or location programm where ur stored this programm.\n";
getch();
}


FILE LOCATION:

Wednesday, 27 November 2013

CONVERT NAMES TO NUMBERS.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
#include<iostream.h>
#include<conio.h>
#include<string.h>
char a[27]="0ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int len=0,size,i,j=0;
int num[10];
int flag=0;

class string
{
public:

struct strings
{
char name[10];


}std[10];


void read()
{

cout<<"ENTER NAME\n";

cin>>std[0].name;

len=strlen(std[0].name);

}

void calculate()
{
for(i=1;i<=27;i++)
{
if(a[i]==std[0].name[j])
{
num[j]=i;
}
}
}

void loop()
{

if(j<=len)
{
j++;


calculate();
loop();
}

}

void display()
{

for(i=0;i<len;i++)
{
cout<<num[i]<<",";
}
}
};

void main()
{
len=0;
size=0;
i=0;
j=0;
char ch;
string s;
if(flag==0)
{
clrscr();
flag=1;
}

s.read();
s.calculate();
s.loop();
s.display();

cout<<"\n\nDO U CALULATE NEXT NAME Y/N \n";
cin>>ch;

if(ch=='y' || ch=='Y')
{
main();
}
else
{
getch();

cout<<"\npress N to EXIT else press Y to continue";
cin>>ch;
if(ch=='Y' || ch=='y')
{
main();
}
}
getch();
}

BINARY SEARCH


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include<iostream.h>
#include<conio.h>

int low=0;
int flag=0;
int j=0;

class searching
{
public:

int a[50];
int mid,high;
int i;
int size;
int el;

void read()
{
cout<<"ENTER ARRAY SIZE\n";  //input array size to enter elements if u enter array size 5 then u can insert 5 elements into array. 
cin>>size;

cout<<"ENTER ELEMENTS\n";  

for(i=0;i<size;i++)
{
cin>>a[i];                  //enter elements to array untile array size full.
}
}

void input()          ti  //a funcon to enter input to search for an element from already entred array.
{
cout<<"ENTER ELEMENTS to search\n";
cin>>el;                  
high=size;          //initilized high is equals to size.
}

void search()
{
j++;

mid=(high+low)/2;  //calculating midle value of sorted array

if(el==a[mid])      //to check if search for an element found at any location in array. 
{
cout<<"ELEMENT "<<el<<" FOUND AT LOCATION "<<mid<<"\n";  //if element is found this message is displayed to the user.

flag=1;                                                  //element is found so we set flag=1 for a reference.
}

                      

if(el<a[mid])                                         //if search for element< middle value  we set high=mid
{
high=mid;       
}
else                                             
{
low=mid;                                               //if search for element>midle value is we set low=mid
}

if(j<=size && el!=a[mid])              //continue the search fundtion untile element is found.
{
search();
}

if(flag==0)
{
cout<<"ELEMENT WAS NOT FOUND\n";          //if flag=0 which means search for element not found at any lcation.
}
}
};

void main()
{
clrscr();
searching s;

s.read();  //calling read function.
s.input(); //calling input function.
s.search(); //search function.
getch();
}

Tuesday, 26 November 2013

QUEUE


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include<iostream.h>
#include<conio.h>
int front=0,rear=0; //initializing varible for needed  operations in queue.
int flag=0;
int i,size;

int q[10];
class qu
{
public:


void insert()  //Function to insert elements into queue.
{

if(rear>=size)    //insertion is not possible if rear met to its maximum size of queue,
{
cout<<"QUEUE IS FULL\n";
}
               //element can be inserted if rear less than size of queue
else
{
rear++;  //increment rear by 1.
cout<<"ENTER ELEMENT TO ADD\n";
cin>>q[rear];               //element is stored on q[rear] and rear vlue is incremented by 1 for each insertion until rear become equal to size.
}
}

void dele()   // function to deletion is possible only if there is atlest 1 element in queue. that is rear>0.
{
if(rear>0)
{
front++;
q[front]=NULL;

for(i=1;i<=rear;i++)
{
q[i]=q[i+1];   //deletion of an front element in queue will leads to a NULL value in front so rewrite all the element back to avoid NULL space.
}
rear--;         //decrement rear by 1.
front--;            //decrement front by 1.
}
else
{
cout<<"QUEUE IS EMPTY\n";
}
}

void display()      //function to disply element in the queue.
{

if(rear>0)
{
for(i=1;i<=rear;i++)
{
cout<<q[i]<<",";
}
}
else
{
cout<<"QUEUE IS EMPTY\n";
}
}
};

void main()
{
int ch;

qu s;

if(flag==0)
{
clrscr();
cout<<"ENTER ARRAY SIZE\n";  //recieve size of queue from user.
cin>>size;
flag=1;
}

cout<<"\n\n1:INSERT\n2:DELETE\n3:DISPLAY\n";
cin>>ch;
switch(ch)  //choice for user to select their function to insert,delete and display
{
case 1 : s.insert(); main();
break;
case 2 : s.dele(); main();
break;
case 3 : s.display(); main();
break;
default : cout<<"INVALID KEY VALUE\n";
break;
}

getch();
}



Saturday, 16 November 2013

MATRIX

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include<iostream.h>
#include<conio.h>
class matrix
{
public:

int m[10][10];             //initializing varibles needed for operations in matrix.
int i;
int j;
int r,c;


void read()
{
cout<<"ENTER ORDER OF MATRIX\n";      //Recieve the total number of rows and columun from user.
cin>>r>>c;
cout<<"ENTER ELEMENTS\n";
for(i=0;i<r;i++)
{
cout<<"\n";
for(j=0;j<c;j++)                            //programm to insert elements to array to create the matrix according to the order specified by the user
{
cin>>m[i][j];          //store rows and columns elements in m[i][j]
}
}
cout<<"\n";
}

void display()       //function to display elements in array as matrix order.
{                                                            

cout<<r<<"x"<<c<<" MATRIX \n";
cout<<"ROW   :"<<r<<"\n";
cout<<"COLUMN:"<<c<<"\n\n";
for(i=0;i<r;i++)
{
cout<<"\n";
for(j=0;j<c;j++)
{
cout<<m[i][j]<<"\t";
}
}

}
};

void main()        //calling functions.
{
matrix s;
clrscr();
s.read();
s.display();
getch();
}

Friday, 8 November 2013

BUBBLE SORT


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include<iostream.h>
#include<conio.h>
int j;
class sorting
{
int a[500];
int i;
int temp;
int size;
public:

void in()
{
cout<<"ENTER ARRAY SIZE\n";  //instruction to the user to specify array size.
cin>>size;

cout<<"ENTER ELEMENT\n";    //programm to insert element in the array until array size full;
for(i=0;i<size;i++)
{
cin>>a[i];
}
}

void search()
{
j++;                   //increment j by 1.
for(i=0;i<size;i++)
{
if(a[i]<=a[i-1])         //swap values if a[i]<=a[i-1].         
{

temp=a[i]+a[i-1];             

a[i]=temp-a[i];

a[i-1]=temp-a[i-1];
}
}
}

void dis()          //function to display each sorted elements.
{

cout<<"\n";
cout<<"sorting: "<<j<< "-> ";

for(i=0;i<size;i++)
{
cout<<a[i]<<",";
}


while(j<size)        //continue search and display function to sort the all elements complietly untile j<size
{
search(); dis();        
}



}
};

void main()      //calling functions
{
clrscr();
sorting s;
s.in();
s.search();
s.dis();

getch();
}










Sunday, 3 November 2013

FIND LARGEST NUMBER FROM n NUMBERS

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<iostream.h>
#include<conio.h>
class largenumber
{
long big,n,i,a[50];      //varibles needeed for calculation.

public:

void read()
{
cout<<"ENTER LENGTH HOW MANY NUMBER U WANT TO ENTER\n";
cin>>n;                                        //reciveve array size from user.
cout<<"ENTER "<<n<<" NUMBERS\n";

for(i=0;i<n;i++)
{
cin>>a[i];        //enter array elements until i met equal to maximum size of array.
}
}

void calculate()          //calculation to find largest number ffrom list of numbers in array..
{
big=a[0];

for(i=0;i<n;i++)
{
if(big<=a[i])
big=a[i];
}
}

void display()    
{
cout<<"\nENTERED NUMBERS\n";
for(i=0;i<n;i++)            //display entred array elements to user.
{
cout<<a[i]<<",\t";
}
cout<<"\nTHE GREATER NUMBER IS: "<<big;    //display  biggest number from the array.
 }
};

void main()
{
clrscr();
largenumber s1;

s1.read();
s1.calculate();
s1.display();
getch();
}


Saturday, 12 October 2013

STACK


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include<stdio.h>
#include<iostream.h>
#include<conio.h>

int i,ch,top=0,stack[10];        //varibles needed for stack operation.

void menu();         //function declaration.
void push();
void pop();
void show();

void main()
{

menu();

}




void menu()
{

cout<<"\n\n\n1:PUSH\n2:POP\n3:SHOW\n";  //user choices to select for their preference PUSH, POP OR SHOW  element IN stack.
cin>>ch;

switch(ch)
{
case 1 : push(); main();   //if user select choice 1 functions push(); executed and come back to main();
break;

case 2 : pop(); main();     //if user select choice 2 functions pop(); executed and come back to main();   
break;

case 3 : show(); main();    //if user select choice 1 functions push(); executed and come back to main();

 break;
}
}

void push()         //push  is a function to insert element to stack.
{
clrscr();
if(top<=9)
{

cout<<"ENTER ELEMENT TO ADD\n"; 
cin>>stack[top];
top++;                             //increment top by  1
}
else
{
cout<<"STACK IS FULL\n";
}
}

void pop()         //function to delete a element from stack.
{
if(top<=0)
{
cout<<"STACK IS EMPTY\n";
}
else
{
--top;
cout<<"\n"<<stack[top]<<" IS DELETED FROM STACK\n";
}
}

void show()              //function to show elements of stack.
{
cout<<"\n\n\n";
if(top>0)
{

for(i=0;i<top;i++)
{
cout<<stack[i]<<",";
}
}
else                                            //if no elements in stack it will display 'STACK IS EMPTY'.
{
cout<<"STACK IS EMPTY\n";
}
}

Monday, 23 September 2013

DISPLAY NATURAL NUMBERS IN REVERS ORDER

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
int a[10]={1,2,3,4,5,6,7,8,9,10};

clrscr();
for(i=10;i>=1;i--)
{
printf("%d,",a[i]);
}
getch();
}