Vous êtes sur la page 1sur 128

# INDEX

## 1. Find if a number is an Armstrong number

2. Remove all duplicates from an array
3. Convert decimal to binary
4. Hangman Game
5. Hi-Low Game
6. LCM of 2 numbers
7. Pattern
8. Permutation and Combinations
9. Get a number of random numbers
10. To reverse an array of numbers
11. To reverse an array of letters
12. Sort an array
13. Starline pattern
14. Check palindrome
15. Sort a structure
16. Tic Tac Toe Game (2 players)
17. Linear search
18. Binary search
19. Insertion in sorted array
20. Deletion in sorted array
21. Traversal of array
22. Input and display 2D array in matrix form
23. Find row sum of matrix
24. Find column sum of a matrix
25. Find sum of diagonals of a matrix
26. Create a file
27. Append to a file
29. Copy to another File
30. Search In A File
31. Modification of File
32. Deletion of record
33. Insertion of record
34. Sorting a file
35. Renaming a file
36. Link list as a stack
37. Link list as a queue

SQL Programs
1. Create a table of Students
2. Display those who have PCM
3. Display average marks of all students
4. Display info of those whose marks lie in 90 to
100
5. Display info of those who have Commerce
and have marks greater than 85
6. Display info of those who doesn’t have PCB
7. Display info of those whose name starts with
the letter K
8. Filter Names Having 6 letters
9. Add a Column of max marks having value 100
10. Sort the table according to marks
11. Find total number of students
12. Find total Number of streams
13. Find Maximum marks of all the streams
Armstrong Number
#include <iostream.h>

#include <conio.h>

#include <stdlib.h>

void main()

clrscr();

int i,l=0,num,s=0;

i=num;

while (i>0)

l = i%10;

s = s+ (l*l*l);

i = i/10;

if (s==num)

else

## cout << num << " Is Not An Armstrong Number";

}
getch();

}
Remove Duplicates from array
#include <iostream.h>

#include <conio.h>

void main()

clrscr();

int a[50];

int n, i, j, count=0;

cout << "How Many Numbers Do You Want To Enter?(Max 50): ";

cin >> n;

## for (i=0; i<n; i++)

cout << "Enter Number " << i+1 << ": ";

## for (j=i+1; j<n; j++)

{
if (a[i] == a[j])

a[j] = 0;

j=0;

if (a[i] == 0)

count++;

## for (i=0; i<n; i++)

if (a[i] != 0)

a[j] = a[i];

j++;

}
for (i= (n - count); i<n; i++)

a[i] = 0;

## cout << a[i] << " ";

getch();

}
Convert Decimal TO Binary
#include <stdio.h>

#include<conio.h>

#include<iostream.h>

int main()

clrscr();

int n,p,c,k,count=0;

cin>>n;

p=n;

while(p)

p=p/10;

count++;

## cout<<"in binary number system is:";

if (count=1)

count=2;

c=count*count*count;

## for (c; c >= 0; c--)

k = n >> c;

if (k & 1)

cout<<"1";

else

cout<<"0";
}

cout<<"\n";

getch();

return 0;

}
Hangman Game
#include <conio.h>

#include <iostream.h>

#include <string.h>

#include <stdlib.h>

#include <ctype.h>

char secret_name[15];

char name_entered[15];

int chnc = 5;

## char countries[10][20] = {"INDIA", "CHINA", "JAPAN", "NEWZEALAND", "TANZANIA", "TURKEY", "TAJIKISTAN",

"MOZAMBIQUE", "LUXEMBOURG"};

void init_name()

## for (int i=0; i<15; i++)

secret_name[i] = '\0';

};

void disp_screen()

int i;

gotoxy(3,12);

## gotoxy (24, 3);

cout << "Chances: " << chnc;

};

void main()

clrscr();

int i, lvl, l, n;

char ch;

## cout << " WELCOME TO HANGMAN!" << endl;

cout << "\n\nThere Are Three Levels To Choose From.\nThen There Comes A Series Of Asteriks and You Have To
Uncover Them By Guessuing The Word Letter By Letter.If You Guess The Correct Letter The Asterik Will Be
Uncovered.\nYou HAve 5 Chances To Do That!.\nAll The Best!";

## cin >> lvl;

switch (lvl)

case 1: randomize();

n = random(10000) % 3;

break;

case 2: randomize();

n = random(10000) % 3 + 3;

break;

case 3: randomize();

n = random(10000) % 3 + 6;

break;

}
strcpy(name_entered, countries[n]);

l = strlen(name_entered);

## for (i=0; i<l; i++)

secret_name[i] = '*';

int count = 0;

clrscr();

disp_screen();

## for (i=0; i<l; i++)

if (toupper(ch) == name_entered[i])

secret_name[i] = toupper(ch);

count++;

if (count == 0)

chnc--;

}
if (chnc == 0)

goto finish;

disp_screen();

gotoxy(3, 14);

finish: getch();

}
Chances: 5

HHHHHHHHUU

nter A Guess:

Chances: S

t1JZAMB IQUE

## EnCongrats! You Figured It Out!

High-Low Game
#include <iostream.h>

#include <conio.h>

#include <stdlib.h>

#include <ctype.h>

void main()

clrscr();

int ch;

char choice;

## case 1: cout << "The Rules Are Simple:"

<< "\nThe Computer Generates A Number And You Have To Guess The Number 0 < n < 1000"

<< "\nThe Computer Will Then Tell You If Its Higher Or Lower Than The Actual Number"

## cin >> choice;

if (toupper(choice) == 'Y')

ch = 2;

goto play;

exit(0);

case 2: clrscr();

count = 0;

randomize();

n = random(10000);

n = n % 1000;

## cout << "The Computer Has Decided The Number!";

while (guess != n)

if (guess > n)

count ++;

## cout << "The Number Is Greater Than It" << endl;

count++;

cout << "Congartulations! You Took " << count + 1 << " Number Of Guesses";

## cin >> choice;

if (toupper(choice) == 'Y')

ch = 2;

goto play;

break;

getch();

}
LCM of 2 Numbers
#include <iostream.h>

#include <conio.h>

void main()

clrscr();

## cin >> n2;

while (n % n1 != 0)

n = n2 * i;

i++;

## cout << "\n\n\nThe LCM Of The 2 Numbers Is: " << n;

getch();

}
Pattern
#include <iostream.h>

#include <conio.h>

void main()

clrscr();

int i, j;

## cout << endl;

getch();

}
Permutation And Combination
#include <iostream.h>

#include <conio.h>

#include <math.h>

float fact(int a)

int i;

float ans=1;

ans = ans * i;

return ans;

float ans;

return ans;

## float ncr(int n, int r)

float ans;
ans = fact(n) / (fact(n-r) * fact(r));

return ans;

void main()

clrscr();

int ch, n, r;

## cin >> ch;

switch (ch)

case 1: clrscr();

cin >> n;

cin >> r;

## cout << "\nAnswer: " << npr(n,r);

break;

case 2: clrscr();

cin >> n;

cin >> r;

## cout << "\nAnswer: " << ncr(n,r);

break;

getch();}
Get A Number Of Unique Random Numbers
#include <iostream.h>

#include <stdlib.h>

#include <conio.h>

void main()

clrscr();

a[i] = 0;

cin >> n;

## for (i=0; i<n; i++)

again: randomize();

## for (j=0; j<n; j++)

{
if (a[j] == rand_no)

goto again;

a[i] = rand_no;

## cout << rand_no << endl;

getch();

}
To reverse An Array Of Numbers
#include <iostream.h>

#include <conio.h>

void main()

clrscr();

int a[50], n, i;

cin >> n;

## for (i=0; i<n; i++)

cout << "Enter Number " << i+1 << ": ";

## cout << endl << a[i];

getch();

}
Enter Number Of Elements: 5
Enter Number 1: 1
Enter Number z: 3
Enter Number 3: 5
Enter Number 4: 7
Enter Number 5: 9

## TI1e Reversed Array Is:

9
7
5
3
1
To Reverse An Array of Letters
#include <iostream.h>

#include <string.h>

#include <dos.h>

#include <conio.h>

void main()

clrscr();

char text[20];

int l;

int i;

## cin >> text;

l = strlen(text);

## cout << "The reverse of your string is";

for (i = l; i >= 0 ; i -= 1)

## cout << "Press Any Key to exit";

getch();

}

1
Sorting An Array
#include <iostream.h>

#include <conio.h>

void main()

clrscr();

cin >> n;

## for (i=0; i<n; i++)

cout << "Enter Number " << i+1 << ": ";

## if (num[i] > num[j])

temp = num[i];

num[i] = num[j];

num[j] = temp;

}
cout << "\n\nThe Sorted Array Is: \n";

## cout << num[i] << endl;

getch();

}
Starline Pattern
#include <iostream.h>

#include <conio.h>

int i;

cout << a;

};

void main()

clrscr();

int n;

char a;

cin >> a;

## cout << "How Many Times Do You Want It To Repeat?: ";

cin >> n;

starline (a,n);
getch();

nter Character: f
ow Many Times Do You Want It To Repeat?: 20

fffffffffffffffffff
Check For Palindrome
#include <iostream.h>

#include <conio.h>

#include <string.h>

#include <stdio.h>

void main()

clrscr();

## cout << "Enter String: ";

cin >> a;

strcpy(a1,a);

strrev(a);

if (strcmpi(a, a1) == 0)

else

## cout << "String Is Not A Palindrome";

getch();

}
Sorting Of Structure
#include <iostream.h>

#include <conio.h>

#include <stdio.h>

#include <string.h>

#include <iomanip.h>

struct stud

int roll;

char name[20];

int marks;

};

void main()

clrscr();

stud s[10];

stud temp;//Temp Will Be Of Student Type as we have to sort whole student data.Not OF Int!

int i, n, j;

cin >> n;

## for (i=0; i<n; i++)

cout << "\nEnter Roll No of Student " << i+1 << ": ";

## cin >> s[i].roll;

cout << "Enter Name of Student " << i+1 << ": ";

gets(s[i].name);

cout << "Enter Marks of Student " << i+1 << ": ";

temp = s[i];

s[i] = s[j];

s[j] = temp;

clrscr();

## cout << "The Sorted List Is\n\n";

cout << setw(7) << "Roll No" << setw(20) << "Name" << setw(7) << "Marks" << endl;

## for (i=0; i<n; i++)

cout << setw(7) << s[i].roll << setw(20) << s[i].name << setw(7) << s[i].marks << endl;

Getch();
TI1e Sorted List Is
Roll No Name Marks
6 Ishita 90
10 Parth 90
13 Shashwat 90
11 Tl.tshar 90
15 Utkarsh 90
Tic Tac Toe Game
#include <iostream.h>

#include <conio.h>

#include <dos.h>

#include <ctype.h>

char board[9] = {'1', '2', '3', '4', '5', '6', '7', '8', '9'};

char p[2][20];

void init_board()

board[0] = '1';

board[1] = '2';

board[2] = '3';

board[3] = '4';

board[4] = '5';

board[5] = '6';

board[6] = '7';

board[7] = '8';

board[8] = '9';

};

void disp_board ()

int i;

## cout << " TIC TAC TOE" << endl

<< p[0] << " <x> " << p[1] << " <o>" << "\n\n";

{

if (i%3 == 0)

};

int chk_win ()

int i;

## if (board[i] == board[i+1] && board[i+1] == board[i+2])

if (board[i] == 'x')

return 1;

## for (i=0; i<3; i++)

{
if (board[i] == board[i+3] && board[i+3] == board[i+6])

if (board[i] == 'x')

return 1;

## if (board[0] == board[4] && board[4] == board[8])

if (board[0] == 'x')

return 1;

## if (board[2] == board[4] && board[4] == board[6])

if (board[2] == 'x')

{
cout << p[0] << " WINS!!";

return 1;

return 0;

};

void main()

again: clrscr();

char a;

init_board();

{

delay (800);

clrscr();

disp_board();

c = i%2;

## cout << "INVALID CHOICE!" << endl;

delay(600);

i--;

else

if (c == 0)

board[ch-1] = 'x';

else if (c == 1)

board[ch-1] = 'o';

clrscr();

disp_board();
if (chk_win() == 1)

break;

else

count ++;

if (count == 9)

## cout << "\nWanna Go Again(Y/N): ";

cin >> a;

if (toupper(a) == 'Y')

goto again;

getch();

}
Linear Search
#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int arr[15],i,num,pos=0;

## cout<<"Enter numbers: \n";

for(i=0;i<10;i++)

cin>>arr[i];

## cout<<"Enter the number to be searched:\n";

cin>>num;

for(i=0;i<10;i++)

if(num==arr[i])

pos=i+1;

## cout<<num<<" found at position "<<pos;break;

if(pos==0)

getch();
Binary Search
#include<iostream.h>

#include<conio.h>

void main()

clrscr();

## int i,arr[10], beg=0, last=9, mid, pos=0,num;

mid=(beg+last)/2;

## cout<<"Enter array in ascending order\n";

for(i=0;i<10;i++)

cin>>arr[i];

## cout<<"Enter number to be searched\n";

cin>>num;

while(beg<last)

if(arr[mid]==num)

pos=mid+1;

## cout<<"Value found at position "<<pos;break;

else if(arr[mid]<num)

beg=mid+1;
else if(arr[mid]>num) last=mid-

1;

mid=(beg+last)/2;

if(pos==0)

getch();

}
Insertion In a Sorted Array
#include<iostream.h>

#include<conio.h>

int arr[15];

int findpos(int x)

int pos;

for(int i=0;i<10;i++)

## if(arr[i]<=x && arr[i+1]>x)

pos=++i;

return pos;

void main()

clrscr();

int i,num,location;

## cout<<"Enter numbers in ascending order\n";

for(i=0;i<10;i++)

cin>>arr[i];

## cout<<"Enter new number to be added\n";

cin>>num;

location=findpos(num);
for(i=11;i>location;i--)

arr[i]=arr[i-1];

arr[location]=num;

## cout<<"New array \n";

for(i=0;i<11;i++)

cout<<arr[i]<<" ";

getch();

}
Deletion from An Array
#include<iostream.h>

#include<conio.h>

int arr[10];

int findpos(int x)

int pos=0;

for(int i=0;i<10;i++)

if(arr[i]==x)

pos=++i;

return pos;

void main()

clrscr();

int i,num,location;

## cout<<"Enter numbers \n";

for(i=0;i<10;i++)

cin>>arr[i];

## cout<<"Enter number to be deleted\n";

cin>>num;

location=findpos(num);

if (location==0)

cout<<"Array remains \n";

for(i=0;i<10;i++)

cout<<arr[i]<<" ";

else

for(i=location-1;i<9;i++)

arr[i]=arr[i+1];

## cout<<"New array \n";

for(i=0;i<9;i++)

cout<<arr[i]<<" ";

getch();

}
Traversal In An Array
#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int a[10],i;

## cout<<"Enter elements of array\n";

for(i=0;i<10;i++)

cin>>a[i];

## cout<<"The elements of array are\n";

for(i=0;i<10;i++)

cout<<a[i]<<" ";

getch();

}
Input And Display Members OF 2D array In
Matrix Form
#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int a[3][3],i,j;

for(i=0;i<3;i++)

for(j=0;j<3;j++)

cin>>a[i][j];

## cout<<"The elements of 2D array in matrix form are\n";

for(i=0;i<3;i++)

for(j=0;j<3;j++)

cout<<a[i][j]<<" ";

if(j==2)

cout<<endl;

getch();

}
i
To Find Row Sum Of Matrix
#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int a[3][3],i,j,r,sum=0;

for(i=0;i<3;i++)

for(j=0;j<3;j++)

cin>>a[i][j];

cin>>r;

for(i=0;i<3;i++)

for(j=0;j<3;j++)

if(i==r-1)

sum+=a[i][j];

## cout<<"Required sum is "<<sum;

getch();

}
sum
To Find Column Sum Of A Matrix
#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int a[3][3],i,j,r,sum=0;

for(i=0;i<3;i++)

for(j=0;j<3;j++)

cin>>a[i][j];

cin>>r;

for(i=0;i<3;i++)

for(j=0;j<3;j++)

if(j==r-1)

sum+=a[i][j];

## cout<<"Required sum is "<<sum;

getch();
sum i
To Find Diagonal Sum Of A Matrix
#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int a[3][3],i,j,r,sum1=0,sum2=0;

for(i=0;i<3;i++)

for(j=0;j<3;j++)

cin>>a[i][j];

for(i=0;i<3;i++)

for(j=0;j<3;j++)

if(i==j)

sum+=a[i][j];

## cout<<"Required sum is "<<sum;

getch();
Create A File
#include <fstream.h>

#include <conio.h>

#include <stdio.h>

#include <iomanip.h>

#include <string.h>

#include <process.h>

class student

public:

int roll;

char name[20];

int marks;

void input()

gets(name);

## cin >> marks;

void display()

{
cout << setw (7) << roll << setw (10) << name << setw (8) << marks << endl;

};

void main()

clrscr();

int n2;

student s1;

fstream f;

## cin >> n2;

switch (n2)

case 1: cout << "Enter Name Of File (Add '.txt' at end): ";

gets(fname);

do

gets (str);

f << str;

## } while (ch == 'Y' || ch == 'y');

f.close();

getch();

break;

case 2: cout << "Enter Name Of File (Add '.dat' at end): ";

gets(fname);

do

s1.input();

## cin >> ch;

} while (ch == 'y' || ch == 'Y');

f.close();

getch();

break;

}
Append a File
#include <fstream.h>

#include <conio.h>

#include <stdio.h>

#include <iomanip.h>

#include <string.h>

#include <dos.h>

#include <process.h>

class student

public:

int roll;

char name[20];

int marks;

void input()

gets(name);

## cin >> marks;

void display()
{

cout << setw (7) << roll << setw (10) << name << setw (8) << marks << endl;

};

void main()

clrscr();

int n2;

student s1;

fstream forg;

## cin >> n2;

switch (n2)

case 1: cout << "Enter Name Of File (Add '.txt' at end): ";

gets(fname);

if (!forg)

getch();

break;

do

gets (str);

## } while (ch == 'Y' || ch == 'y');

forg.close();

getch();

break;

case 2: cout << "Enter Name Of File (Add '.dat' at end): ";

gets(fname);

## forg.open (fname, ios::out | ios::binary | ios::app | ios::nocreate);

if (!forg)

{
cout << "File Doesnt Exist!!";

getch();

break;

do

s1.input();

## } while (ch == 'y' || ch == 'Y');

forg.close();

getch();

break;

}
#include <fstream.h>

#include <conio.h>

#include <stdio.h>

#include <iomanip.h>

#include <string.h>

#include <dos.h>

#include <process.h>

class student

public:

int roll;

char name[20];

int marks;

void input()

gets(name);

## cin >> marks;

void display()
{

cout << setw (7) << roll << setw (10) << name << setw (8) << marks << endl;

};

void main()

clrscr();

## char fname[20], str[50], ch, str1[20];

int n2;

student s1;

fstream f;

cout << "Enter Name Of File You Want To Read From: ";

gets(fname);

## f.open (fname , ios::in | ios::binary);

cout << setw (7) << "Roll No" << setw (10) << "Name" << setw (8) << "Marks" << endl;

## while (f.read ((char *) &s1, sizeof(s1)))

s1.display();

getch();
Copy A File
#include <fstream.h>

#include <conio.h>

#include <stdio.h>

#include <iomanip.h>

#include <string.h>

#include <dos.h>

#include <process.h>

class student

public:

int roll;

char name[20];

int marks;

void input()

gets(name);

## cin >> marks;

void display()
{

cout << setw (7) << roll << setw (10) << name << setw (8) << marks << endl;

};

void main()

clrscr();

## char fname[20], str[50], ch, str1[20];

student s1;

fstream f, fnew;

cout << "Enter Name Of File You Want To Copy FROM: ";

gets(fname);

if(!f)

## cout << "File Doesnt Exists!!";

getch();

cout << "Enter Name Of File You Want To Copy TO: ";

gets(fname);
fnew.open (fname, ios::out | ios::binary | ios::noreplace);

if(!fnew)

getch();

## fnew.write ((char*) &s1, sizeof(s1));

f.close();

fnew.close();

getch();

}
Search In A File
#include <fstream.h>

#include <conio.h>

#include <stdio.h>

#include <iomanip.h>

#include <string.h>

#include <dos.h>

#include <process.h>

class student

public:

int roll;

char name[20];

int marks;

void input()

gets(name);

## cin >> marks;

void display()
{

cout << setw (7) << roll << setw (10) << name << setw (8) << marks << endl;

};

void main()

clrscr();

long pos;

## fstream forg, fnew;

cout << "Enter The Name Of The File (Add '.dat'): ";

gets(fname);

if (!forg)

getch();

break;

}
cout << "Okay!";

delay (500);

clrscr();

## cin >> n2;

switch (n2)

case 1: clrscr();

## cout << "Enter Name You Want To Search: ";

gets (str1);

cout << setw (7) << "Roll No" << setw (10) << "Name" << setw (8) << "Marks" << endl;

## if (strcmpi (str1, s1.name) == 0)

s1.display();

break;

break;
case 2: clrscr();

## cout << "Enter Roll Number You Want To Search: ";

cin >> n;

cout << setw (7) << "Roll No" << setw (10) << "Name" << setw (8) << "Marks" << endl;

## while (forg.read ((char*) &s1, sizeof(s1)))

if (s1.roll == n)

s1.display();

break;

break;

forg.close();

getch();

}
Modification Of File
#include <fstream.h>

#include <conio.h>

#include <stdio.h>

#include <iomanip.h>

#include <string.h>

#include <dos.h>

#include <process.h>

class student

public:

int roll;

char name[20];

int marks;

void input()

gets(name);

## cin >> marks;

void display()
{

cout << setw (7) << roll << setw (10) << name << setw (8) << marks << endl;

};

void main()

clrscr();

long pos;

## fstream forg, fnew;

cout << "Enter The Name Of The File (Add '.dat'): ";

gets(fname);

## cout << "Okay!";

delay (500);

forg.close();

clrscr();
cout << "1. By Name"

do

switch (n2)

gets(str);

## while (forg.read ((char *) &s1, sizeof(s1)))

if (strcmpi(s1.name, str) == 0)

## pos = forg.tellg() - sizeof(s1);

break;

break;

case 2: cout << "Enter Roll number You Want To Edit: ";

cin >> n;
while (forg.read ((char *) &s1, sizeof(s1)))

if (s1.roll == n)

## pos = forg.tellg() - sizeof(s1);

break;

break;

case 3: cout << "Enter Record Number You Want To Modify With: ";

cin >> n;

break;

forg.seekg(pos);

s1.input();

clrscr();

## cout << "New Data: \n\n\n";

cout << setw (7) << "Roll No" << setw (10) << "Name" << setw (8) << "Marks" << endl;
forg.close();

s1.display();

forg.close();

## } while (ch == 'y' || ch == 'Y');

getch();

}
Delete A Record
#include <fstream.h>

#include <conio.h>

#include <stdio.h>

#include <iomanip.h>

#include <string.h>

#include <dos.h>

#include <process.h>

class student

public:

int roll;

char name[20];

int marks;

void input()

gets(name);

## cin >> marks;

void display()
{

cout << setw (7) << roll << setw (10) << name << setw (8) << marks << endl;

};

void main()

clrscr();

long pos;

## fstream forg, fnew;

cout << "Enter The Name Of The File (Add '.dat'): ";

gets(fname);

delay (500);

clrscr();

## cout << "1. By Name"

<< "\n2. By Roll Number"

switch (n2)

## case 1: cout << "Enter Name You Want To Delete: ";

gets(str);

if (strcmpi(str, s1.name) != 0)

## fnew.write ((char*) &s1, sizeof(s1));

break;

case 2: cout << "Enter Roll Number Of Record You Want To Delete: ";

cin >> n;

if (s1.roll != n)

## fnew.write ((char*) &s1, sizeof(s1));

}
}

break;

case 3: cout << "Enter The Record Number You Want To Delete: ";

cin >> n;

i++;

if (i != n)

break;

forg.close();

fnew.close();

remove (fname);

## cout << "\n\nNew Data:\n\n ";

cout << setw (7) << "Roll No" << setw (10) << "Name" << setw (8) << "Marks" << endl;
forg.open (fname, ios::in | ios::binary);

## while (forg.read ((char*) &s1, sizeof(s1)))

s1.display();

forg.close();

getch();

}
Insert A Record
#include <fstream.h>

#include <conio.h>

#include <stdio.h>

#include <iomanip.h>

#include <string.h>

#include <dos.h>

#include <process.h>

class student

public:

int roll;

char name[20];

int marks;

void input()

gets(name);

## cin >> marks;

void display()
{

cout << setw (7) << roll << setw (10) << name << setw (8) << marks << endl;

};

void main()

clrscr();

long pos;

## fstream forg, fnew;

cout << "Enter The Name Of The File (Add '.dat'): ";

gets(fname);

## fnew.open ("newstudent.dat", ios::out | ios::binary);

cout << "Enter The Roll Number After Which You Want To Add: ";

cin >> n;

## fnew.write ((char*)&s1, sizeof(s1));

if (s1.roll == n)

s2.input();

forg.close();

fnew.close();

remove (fname);

## cout << "\n\nNew Data:\n\n ";

cout << setw (7) << "Roll No" << setw (10) << "Name" << setw (8) << "Marks" << endl;

## while (forg.read ((char*) &s1, sizeof(s1)))

s1.display();

forg.close();

getch();

}
Sorting A File
#include <fstream.h>

#include <conio.h>

#include <stdio.h>

#include <iomanip.h>

#include <string.h>

#include <dos.h>

#include <process.h>

class student

public:

int roll;

char name[20];

int marks;

void input()

gets(name);

## cin >> marks;

void display()
{

cout << setw (7) << roll << setw (10) << name << setw (8) << marks << endl;

};

void main()

clrscr();

long pos;

## fstream forg, fnew;

cout << "Enter The Name Of The File (Add '.dat'): ";

gets(fname);

s3[i] = s1;

i++;

{

## if (s3[j].roll < s3[k].roll)

temp = s3[k];

s3[k] = s3[j];

s3[j] = temp;

cout << setw (7) << "Roll No" << setw (10) << "Name" << setw (8) << "Marks" << endl;

forg.close();

## forg.write ((char*) &s3[j], sizeof(s3[j]));

s3[j].display();

forg.close();

getch();

}
Rename A File
#include <fstream.h>

#include <conio.h>

#include <stdio.h>

void main()

clrscr();

gets(str);

## cout << “Enter New Name: “;

gets(str1);

rename(str, str1);

getch();

}
#include <iostream.h>

#include <conio.h>

struct node

int e;

};

class stack

## node *top, *ptr;

public:

stack()

top = NULL;

~stack()

while(ptr != NULL)

ptr = top;

delete ptr;

}
void push();

void display();

void pop();

};

void stack::push()

## cin >> ptr->e;

if (top == NULL)

top = ptr;

else

top = ptr;

void stack::display()

if (top == NULL)

else

{
ptr = top;

## cout << ptr->e << " ";

void stack::pop()

ptr = top;

if (top == NULL)

else

delete ptr;

void main()

stack s1;
int n;

do

clrscr();

## cout << "\n\nYour Choice: ";

cin >> n;

switch(n)

case 1: clrscr();

s1.push();

break;

case 2: clrscr();

s1.display();

getch();

break;

case 3: clrscr();

s1.pop();

getch();

break;

}

}while (n!=4);

## cout << "\n\nThanks For Using!!";

getch();

}
#include <iostream.h>

#include <conio.h>

struct node

int e;

};

class queue

## node *front, *rear, *ptr;

public:

queue()

rear = NULL;

front = NULL;

void queins();

void quedel();

void quedisp();

};

void queue::queins()

## ptr = new node; ptr-

cout << "Enter Element: ";

## cin >> ptr->e;

if (rear == NULL)

## front = rear = ptr;

else

rear = ptr;

void queue::quedisp()

if (front == NULL)

## cout << "Empty Queue!";

else

ptr = front;

while (ptr!=NULL)

## cout << ptr->e << " ";

}
void queue::quedel()

ptr = front;

if (front == NULL)

else

delete ptr;

## cout << "\nDeleted";

if (front == NULL)

rear = NULL;

void main()

queue q1;

int n;

do

{
clrscr();

## cout << "\n\nYour Choice: ";

cin >> n;

switch(n)

case 1: clrscr();

q1.queins();

break;

case 2: clrscr();

q1.quedisp();

getch();

break;

case 3: clrscr();

q1.quedel();

getch();

break;

}while (n!=4);

## cout << "\n\nThanks For Using!!";

getch();

1. Insert
2. Display Enter Element: Zl
3. Delete
14. Exit
our Choice: 1

1. Insert
- Display
- Delete
!4. Exit
fe 21 22
our Choice: 2_

1. Insert
- Display
- Delete
lerrent: 20
14 . Exit
1 e leted-
our Choice: 3
Table For SQL Programs
CREATE A TABLE OF STUDENTS
Display those Having PCM
Display Average Marks Of All Students
Display Info Of those whose marks lie in
90 to 100
Display info of those who have commerce
and have marks greater than 85
Display Info Of those who doesn’t have
PCB
Display Info Of those whose name Starts
with “K”
Filter Names Having 6 Letters
Add A column Of Max Marks having value
100
Sort Table By Marks
Find Total Number Of Students
Find Total Number Of Streams
Find Maximum Marks OF All The Streams