DSA Ashish Aaher 01
DSA Ashish Aaher 01
Roll no: 01
namespace std;
struct Node
{ int value;
Node* next;
};
= 10;
Node* table[TABLE_SIZE];
int hashFunc on(int value) { return
value % TABLE_SIZE;
public:
= nullptr;
if (!table[idx])
{ table[idx] =
newNode;
} else { Node*
(curr->next) curr =
curr->next; curr->next
= newNode;
cout << "Inserted " << value << " at index " << idx << endl;
"Element " << value << " found at index " << idx << endl;
return idx;
} curr =
curr->next;
cout << "Element " << value << " not found\n";
return -1;
curr = curr->next;
} if (!curr) { cout << "Element " << value << " not
return; } if
(!prev) { table[idx] =
curr->next; } else
{ prev->next =
curr->next;
} delete curr; cout << "Deleted " << value << "
};
int main() {
Hashing h; int choice,
num;
Menu:\n"
>> choice;
switch (choice)
{ case 1:
h.insertElement(num);
break; case 2:
h.display(); break;
case
h.searchElement(num);
break; case 4: cout <<
num;
h.deleteElement(num);
break; case
5:
return 0;
}
Output :
1. Insert
2. Display
3. Search
4. Delete 5. Exit
Choice: 1
1. Insert
2. Display
3. Search
4. Delete 5. Exit
Choice: 1
1. Insert
2. Display
3. Search 4. Delete
5. Exit
Choice: 1
1. Insert
2. Display
3. Search
4. Delete
5. Exit Choice: 2 a[0] : -> 98701543210 a[1] : -> 12345017891 a[2] : a[3] : a[4] : a[5] : ->
5555555555
a[01] :
a[7] :
a[8] :
a[9] :
1. Insert
2. Display
3. Search
4. Delete
5. Exit
Choice: 3
1. Insert
2. Display
3. Search
4. Delete 5. Exit
Choice: 4
1. Insert
2. Display
3. Search
12345017891
a[2] : a[3] : a[4] :
a[01] :
a[7] :
a[8] :
a[9] :
Telephone Book Menu:
1. Insert
2. Display
3. Search
4. Delete 5. Exit
Choice: 5 Exi
ng...
Name : Aher Ashish Vinod ; Roll no: 01 ; Seat Number : S40001080101
Practical No 2:
Implement all the functions of a dictionary (ADT)
using hashing and handle collisions using
chaining with / without replacement. Data: Set of
(key, value) pairs, Keys are mapped to values,
Keys must be comparable, Keys must be unique
Standard Opera ons: Insert (key, value),
Find(key), Delete(key)
#include<iostream>
#include<string.h>
#include<iostream>
#include<string.h>
class HashFunc on
{ typedef struct
hash
{ long key;
char name[10];
} hash;
hash h[10];
public:
HashFunc on();
{ h[i].key = -1;
strcpy(h[i].name, "NULL");
{ int index =
find(k); if(index
== -1)
{ h[index].key = -1;
strcpy(h[index].name, "NULL");
{ if(h[i].key
== k)
{
cout << "\n\t" << h[i].key << " is Found at " << i << " Loca on with name " <<
h[i].name;
return i;
i;
cout << "\n\th[" << i << "]\t" << h[i].key << "\t\t" << h[i].name;
do
{ if(cnt >=
10)
break;
if(h[hi].key == -1)
{ h[hi].key =
k;
strcpy(h[hi].name, n);
else
{ if(h[hi].key %
10 != hi)
{ temp =
h[hi].key;
strcpy(ntemp, h[hi].name);
h[hi].key = k;
{ if(h[i].key ==
-1)
{ h[i].key =
temp;
strcpy(h[i].name, ntemp);
flag = 1; break;
-1)
{ h[i].key =
temp;
strcpy(h[i].name, ntemp);
break;
}
} } else
i++)
{ if(h[i].key ==
-1)
h[i].key = k; strcpy(h[i].name,
n);
flag = 1; break;
{ if(h[i].key ==
-1)
{ h[i].key =
k;
strcpy(h[i].name, n);
break;
ans;
int main()
long k; int
ans;
HashFunc on obj;
do
{
cout << "\n\t***Telephone(ADT)*****"; cout <<
"\n\t1.insert\n\t2.Display\n\t3.Find\n\t4.Delete\n\t5.Exit"; cout <<
{ case
1:
obj.insert();
break; case 2:
obj.display(); break;
case 3:
= obj.find(k); if(index
== -1)
break; case
4:
break;
cout << "\n\t.... Do you want to con nue in main menu: y/n";
//out put
/*
***Telephone(ADT)*****
1.insert
2.Display
3.Find
4.Delete
5.Exit
***Telephone(ADT)*****
1.insert
2.Display
3.Find
4.Delete
5.Exit
50174587014 toshal
h[5] -1 NULL h[01]
45014501 ayush h[7]
874015780157 dinesh h[8]
01015783401 tushar h[9]
-1 NULL
*/
Practical No:3
#include<string.h> using
namespace std;
name[20]; node*
next; node*
down;
int flag;
};
ch[20];
int n, i;
public: node*
create(); void
insertb(); void
insertc(); void
inserts(); void
insertss(); void
displayb();
};
node* Gll::create() { node*
p = new(node); p->next =
NULL; p-
>down = NULL;
p->name;
return p;
void Gll::insertb() { if
(head == NULL)
{ t1 =
create();
head = t1;
already exists.";
no book.";
insert? ";
(head->flag == 0)
head->down = t1;
head->flag = 1;
no book.";
} else { cout << "\nEnter the name of the chapter on which you want to enter
the sec on: "; cin >> ch; temp = head; if (temp->flag == 0) { cout
enter? ";
t2 = temp->down;
} else
{ while
(t2->next !=
NULL) { t2 = t2-
>next;
t2->next = t1;
break;
temp = temp->next;
"\nEnter the name of chapter on which you want to enter the sec on: "; cin >>
} else { temp =
temp->name)) {
cout << "\nEnter the name of the sec on in which you want to enter the
subsec on: ";
cin >> ch; if (temp->flag
sec ons.";
} else
{ t2 = temp->down;
cin >> n;
for (i = 0; i < n; i++)
{ t1 = create();
if (t2->flag == 0)
{ t2->down = t1;
t2->flag = 1;
else
while (t2->next !=
NULL) { t2 = t2-
>next;
t2->next = t1;
}
} break;
t2 = t2->next;
temp = temp->next;
if (temp->flag == 1) {
"\n\t\tNAME OF
>name;
t1 = temp; if
(t1->flag == 1) { t1
= t1->down;
while (t1 != NULL) { cout << "\n\t\t\t\tNAME OF
t2 = t1; if (t2->flag == 1) { t2 =
t2 = t2->next;
} t1 =
t1->next;
temp = temp->next;
int main() {
Gll g; int
x; while
(1)
{ cout
<< "\n\nEnter
your choice:
"; cout
<< "\n1.
Insert book";
cout << "\n2.
Insert
chapter";
Insert sec
on";
Insert subsec
on";
Display
book";
cout <<
"\n01. Exit";
cin >> x;
switch (x)
{ case 1:
g.insertb(); break;
case
2:
g.insertc(); break;
case
3:
g.inserts(); break;
case
4:
g.insertss(); break;
case
5:
g.displayb(); break;
case
01: exit(0);
} return
0;
1. Insert book
2. Insert chapter
3. Insert sec on
4. Insert subsec on
5. Display book
6. Exit1
1. Insert book
2. Insert chapter
3. Insert sec on
4. Insert subsec on
5. Display book
6. Exit2
1. Insert book
2. Insert chapter
3. Insert sec on
4. Insert subsec on
5. Display book
6. Exit3
Enter the name of the chapter on which you want to enter the sec on: hashing
1. Insert book
2. Insert chapter
3. Insert sec on
4. Insert subsec on
5. Display book
6. Exit4
Enter the name of chapter on which you want to enter the sec on: hashing
Enter the name of the sec on in which you want to enter the subsec on: hash_table
1. Insert book
2. Insert chapter
3. Insert sec on
4. Insert subsec on
5. Display book
6. Exit5
1. Insert book
2. Insert chapter
3. Insert sec on
4. Insert subsec on
5. Display book
6. Exit01
*/
node
v. Search a value
#include<iostream>
#include<cstdlib> using
namespace std;
class node
{ public:
int info;
node* le ;
node* right; };
class BST {
public: node*
root;
BST() { root
= NULL;
};
---------" << endl; cout << "Opera ons on BST" << endl; cout << "---------------
--------" << endl; cout << "1. Insert Element" << endl; cout << "2. Display" <<
endl; cout << "3. Min value" << endl; cout << "4. Height" << endl; cout <<
"5. Mirror of node" << endl; cout << "01. Preorder" << endl; cout << "7.
Inorder" << endl; cout << "8. Postorder" << endl; cout << "9. No. of nodes in
longest path" << endl; cout << "10. Search an element" << endl; cout << "11.
Quit" << endl; cout << "Enter the choice: "; cin >> choice;
switch (choice)
{ case 1:
temp = new node(); cout << "Enter
break;
case
2:
case
3:
cout << "Min value of tree: " << bst.min(bst.root) << endl;
break;
case
4:
break;
case
5:
bst.mirror(bst.root); bst.display(bst.root,
1);
break;
endl;
break;
case
9:
of nodes in
longest path
<<
bst.height(bst.
root) <<
endl;
break;
case
10:
searchdata;
bst.search(bst.root, searchdata);
break;
case
11:
exit(1);
default:
newnode) {
}
if (tree->info == newnode->info) { cout <<
return;
}
if (tree->info > newnode->info)
{ if (tree->le != NULL)
{ insert(tree->le , newnode);
} else { tree->le
= newnode; tree->le
->le = NULL;
->right =
tree->le NULL;
cout << "Node added to le " << endl;
} } else { if (tree->right !=
NULL) { insert(tree->right,
newnode);
tree>right->le = NULL;
{ if (ptr != NULL)
}
// Min value func on int BST::min(node* root) { if (root
} else {
= temp->le ;
return temp->info;
BST::height(node* root)
{ if (root == NULL) {
return 0;
}
int le Height = height(root->le ); int rightHeight = height(root->right);
return (le Height > rightHeight ? le
Height : rightHeight) + 1;
BST::mirror(node* root) { if
root>right = temp;
mirror(root->le );
mirror(root->right);
BST::preorder(node* ptr) { if
preorder(ptr->le );
preorder(ptr->right);
BST::inorder(node* ptr) { if
(ptr != NULL) {
inorder(ptr->right);
BST::postorder(node* ptr) { if
(ptr != NULL)
{ postorder(ptr->le );
postorder(ptr->right); cout
{ cout <<
return;
} if (ptr->info == searchdata)
searchdata) { search(ptr->right,
searchdata);
} else { search(ptr->le ,
searchdata);
-----------------------
1. Insert Element
2. Display
3. Min value
4. Height
5. Mirror of node
6. Preorder
7. Inorder
8. Postorder
11. Quit
-----------------------
-----------------------
1. Insert Element
2. Display
3. Min value
4. Height
5. Mirror of node
6. Preorder
7. Inorder
8. Postorder
11. Quit
Node added to le
-----------------------
Opera ons on BST
-----------------------
1. Insert Element
2. Display
3. Min value
4. Height
5. Mirror of node
6. Preorder
7. Inorder
8. Postorder
11. Quit
Node added to le
-----------------------
-----------------------
1. Insert Element
2. Display
3. Min value
4. Height
5. Mirror of node
6. Preorder
7. Inorder
8. Postorder
-----------------------
-----------------------
1. Insert Element
2. Display
3. Min value
4. Height
5. Mirror of node
6. Preorder
7. Inorder
8. Postorder
11. Quit
Display: 5019015327
9843
4354
39501
-----------------------
-----------------------
1. Insert Element
2. Display
3. Min value
4. Height
5. Mirror of node
6. Preorder
7. Inorder
8. Postorder
11. Quit
-----------------------
-----------------------
1. Insert Element
2. Display
3. Min value
4. Height
5. Mirror of node
6. Preorder
7. Inorder
8. Postorder
11. Quit
-----------------------
1. Insert Element
2. Display
3. Min value
4. Height
5. Mirror of node
6. Preorder
7. Inorder
8. Postorder
11. Quit
Mirror: 39501
4354
9843
5019015327 ---------------------
--
1. Insert Element
2. Display
3. Min value
4. Height
5. Mirror of node
6. Preorder
7. Inorder
8. Postorder
11. Quit
-----------------------
-----------------------
1. Insert Element
2. Display
3. Min value
4. Height
5. Mirror of node
6. Preorder
7. Inorder
8. Postorder
11. Quit
-----------------------
-----------------------
1. Insert Element
2. Display
3. Min value
4. Height
5. Mirror of node
6. Preorder
7. Inorder
8. Postorder
11. Quit
-----------------------
-----------------------
1. Insert Element
2. Display
3. Min value
4. Height
5. Mirror of node
6. Preorder
7. Inorder
8. Postorder
-----------------------
-----------------------
1. Insert Element
2. Display
3. Min value
4. Height
5. Mirror of node
6. Preorder
7. Inorder
8. Postorder
11. Quit
not found...
-----------------------
-----------------------
1. Insert Element
2. Display
3. Min value
4. Height
5. Mirror of node
6. Preorder
7. Inorder
8. Postorder
11. Quit
Prac cal No : 5
Construct an expression tree from the given prefix
expression eg. +--a*bc/def and traverse it
DEPARTMENT OF Ar ficial Intelligence and
Data using postorder traversal(non recursive) and
then delete the en re tree
#include<iostream>
#include<stack>
#include<string>
using namespace std;
struct
Node{ char
data;
Node* le ;
Node* right;
};
Node* newNode(char
data){ Node* node = new
Node; node->data = data;
node>le = NULL;
node->right
s;
= prefix[i]; if(isdigit(ch) ||
isalpha(ch)){
s.push(newNode(ch));
} else {
Node* node = newNode(ch);
node->le = s.top();
s.pop();
node->right = s.top();
s.pop();
s.push(node);
} }
return s.top();
void postorderTraversal(Node*
stack<Node*> s;
|| prev->right ==
curr){ if(curr->le ){
s.push(curr->le );
} else if(curr->right){
s.push(curr->right);
} else if(curr->le ==
prev){ if(curr->right){
s.push(curr->right);
prev = curr;
void deleteTree(Node*
stack<Node*> s;
|| prev->right ==
curr){ if(curr->le ){
s.push(curr->le );
} else if(curr->right){
s.push(curr->right); }
s.pop(); }
prev = curr;
/*student@ioe-aids-151:~$ ./a.out
Postorder Traversal: a b c * - d e / - f +
*/
#include<string.h> using
namespace std;
};
{ int
i,j;
for(i=0;i<10;i++)
{ strcpy(city_index[i],"xx");
} for(i=0;i<10;i++)
{ for(j=0;j<10;j++)
{ am[i][j]=0;
int flight::create()
{ int
city_count=0,j,si,di,wt;
char s[10],d[10],c; do
{ cout<<"\n\tEnter Source
City : ";
on City : ";
cin>>d; for(j=0;j<10;j++)
break
condi on
city_count++;
for(j=0;j<10;j++)
if(strcmp(city_index[j],d)==0)
break; }
if(j==10) // same for des na on
{ strcpy(city_index[city_count],d);
city_count++;
for(j=0;j<10;j++)
if(strcmp(city_index[j],s)==0) si=j;
if(strcmp(city_index[j],d)==0) di=j;
return(city_count);
count
{ int i,j;
for(i=0;i<city_count;i++)
cout<<"\t"<<city_index[i]; cout<<"\n";
for(i=0;i<city_count;i++)
{ cout<<"\t"<<city_index[i]; for(j=0;j<city_count;j++) //
j is
cout<<"\t"<<am[i][j];
} cout<<"\n";
int main()
{ flight f; int
n,city_count;
char c;
do
case 1:
city_count=f.create(); break;
case 2:
f.display(city_count); break;
case 3:
return 0;
} cout<<"\n\t Do you Want to Con nue in Main
1. Create
2. Adjacency Matrix
3. Exit
1. Create
2. Adjacency Matrix
3. Exit
A B C D
A 0 100 0 300
B 0 0 200 0
C 0 0 0 0 D0 0 0 0
data structures
#include<iostream> using
namespace std;
e, visited[20];
public:
void input();
void display();
void
minimum();
};
void tree::input()
{ visited[i] =
0;
cin >> e;
cout << "Enter the end branches of connec ons (l, u): ";
cin >> l >> u; cout << "Enter the phone company charges for
void tree::display()
{ for(j = 0; j < v;
j++)
{ cout <<
} cout
<< endl;
}
void tree::minimum()
{ int p = 0, q = 0, total = 0,
min;
for(int count = 0; count < (v-1); count++) // Loop un l we have included (v-1) edges
{ min =
999;
{ for(j = 0;
j < v; j++)
{ if(min >
a[i][j])
{ min =
a[i][j]; p = i;
q
= j;
cout << "Minimum cost connec on is: " << (p+1) << " -> " << (q+1) << " with charge:
" << min << endl;
cout << "The minimum total cost of connec ons of all branches is: " << total << endl; }
int main()
{ int
ch; tree
t;
do
{
cout << "Prim's Algorithm\n"; cout << "\n1.
Input\n2. Display\n3. Minimum\n4. Exit\n"; cout <<
switch(ch)
{ case
1:
2:
t.display(); break;
case
3:
t.minimum();
break; case 4:
again.\n";
} while(ch != 4);
return 0;
/* output
Prim's Algorithm
1. Input
2. Display
3. Minimum
4. Exit
Enter the phone company charges for this connec on: 101
Enter the phone company charges for this connec on: 200
Enter the phone company charges for this connec on: 201
Enter the phone company charges for this connec on: 300
Enter the phone company charges for this connec on: 301
Prim's Algorithm
1. Input
2. Display
3. Minimum
4. Exit
Adjacency matrix:
Prim's Algorithm
1. Input
2. Display
3. Minimum
4. Exit
Minimum
The minimum total cost of connec ons of all branches is: 0100
Prim's Algorithm
1. Input
2. Display
3. Minimum
4. Exit
*/
each key?
#include<iostream> using
namespace std;
print(int, int);
int r[20][20], n;
int main()
{ int
i;
cout << "\n Program for Op mal Binary Search Tree (OBST)\n";
con_obst();
0;
void con_obst(void)
{ int i, j, k,
l;
(i = 0; i < n; i++)
{ c[i][i]
= 0.0;
r[i][i] = 0;
wt[i][i] = b[i];
1]; r[i][i + 1] = i + 1;
c[n][n] = 0.0;
r[n][n] = 0; wt[n][n]
= b[n];
(i = 2; i <= n; i++)
{ for (j = 0; j <= n - i;
j++)
c[l][j + i]))
i]; r[j][j + i] = l;
"w[0][" << n << "]:: " << wt[0][n] << endl; cout
<< "c[0][" << n << "]:: " << c[0][n] << endl;
cout << "r[0][" << n << "]:: " << r[0][n] << endl;
{ if (l1 >=
r1)
return;
if (root != 0)
{
// If the le child exists, print it if (r[l1][root - 1] != 0)
cout << "\nLe child of " << root << " is " << r[l1][root - 1];
cout << "\nRight child of " << root << " is " << r[root][r1];
// Right subtree
Output:
p[2]: 0.5
w[0][2]:: 0.9
*/
#include<iostream> using
namespace std;
struct HBTNode {
int Key;
char Mean[10];
HBTNode* le ;
HBTNode* right;
} *Root;
void create_HBT() {
= NULL;
Newnode->right = NULL;
if(Root == NULL) {
Root = Newnode;
= Root; while(!done)
{ if(Newnode>Key <
current->Key)
{ if(current->le == NULL)
{ current->le = Newnode;
done = 1; }
else { current =
current->le ;
} } else
{ if(current->right ==
NULL) {
current->right = Newnode;
done = 1; }
else { current =
current->right;
if(root) {
cout << "\n\t" << root->Key << "_" << root>Mean;
display_HBT(root->le );
display_HBT(root->right);
}
void sorted_List(struct HBTNode* root) {
if(root) {
>right);
current;
current->Key)
{ current =
current->le ;
level++; comp++;
= current->right;
<< "\n\t Key: " << Key; cout << "\n\t Found
at Level: " << level; cout << "\n\t No. of
int main() {
cout << "\n------***A C++ program to implement Dic onary using Height-Balanced
Tree.***-----\n";
cout << "\n2. Display Keywords and meanings in height balanced tree.";
Find_Keyword(1);
return 0;
Enter Keyword: 3
Enter Keyword: 2
Enter Keyword: 4
Enter Keyword: 1
Enter Keyword: 5
3_Three
2_Two
1_one
4_FOur
5_Five
keyword-meaning
1_one
2_Two
3_Three
4_FOur
5_Five
Key: 1
Found at Level: 2
*/
par cular subject. Find out maximum and minimum marks obtained in that subject.
#include<iostream> using
namespace std;
struct Node
Node *right;
}*root;
{
struct Node *tmp; tmp =
new struct Node;
cout<<"\n\t Enter Marks:
"; cin>>tmp->marks; tmp>le
= NULL; tmp->right =
void create_BST()
if(root == NULL)
*newnode)
{
if(Root->le == NULL) Root-
>le = newnode;
else insert(Root->le ,
newnode);
} else
{
if(Root->right == NULL)
insert(Root->right ,
newnode); }
*Root)
if(Root != NULL)
cout<<" "<<Root-
>marks; preorder(Root-
>le ); preorder(Root-
>right);
}
}
//.....Func on to Convert BST into MAX Heap Tree void
Parent->right->marks;
Parent->right->marks = Parent->marks;
Parent->marks = val;
int main()
{ int cnt , i,
j;
root = NULL; i = j = 0;
{ newnode = createNode();
insert(root , newnode);
}
//.....Step 3: Display BST cout<<"\n\n
MaxHeapify(root);
MaxHeapify(root->le );
MaxHeapify(root->right);
MaxHeapify(root); //.....Step 5: Display MAX
Heap Tree cout<<"\n\n A er Heapifying
BST........."; cout<<"\n\n Max Heap Tree
Preorder Traversal: "; preorder(root);
Output:
Enter Marks: 01
Enter Marks: 30
Enter Marks: 20
Enter Marks: 40
Enter Marks: 70
Enter Marks: 80
A er Heapifying BST.........
Maximum Marks: 80
#include<iostream>
#include<fstream>
#include<cstring>
char address[20];
void accept()
{ cout<<"\n\tEnter Roll
Division:"; cin>>div;
cin>>address;
} void
accept3()
} int
getRollNo()
{ return
rollNo;
} void
show() {
cout<<"\n\t"<<rollNo<<"\t\t"<<name<<"\t\t"<<div<<"\t\t"<<address;
} }; int
main()
{ int
i,n,ch,ch1,rec,start,count,add,n1,add2,start2,n2,y,a,b,on,oname,add3,start3,n3,y1,add4,star
t4,n4;
char name[20],name2[20];
tel t1;
count=0; fstream
g,f; do
cout<<"\n>>>>>>>>>>>>>>>>>>>>>>MENU<<<<<<<<<<<<<<<<<<<<";
switch(ch)
{ case
1:
f.open("StuRecord.txt",ios::out); x:t1.accept();
f.write((char*) &t1,(sizeof(t1))); cout<<"\nDo you want
f.close();
break;
} case
2:
f.open("StuRecord.txt",ios::in);
f.read((char*) &t1,(sizeof(t1)));
{ t1.show();
f.read((char*) &t1,(sizeof(t1)));
f.open("StuRecord.txt",ios::in|ios::out);
f.read((char*)&t1,(sizeof(t1)));
while(f) { if(rec==t1.rollNo)
f.seekg(0,ios::beg);
start=f.tellg(); n1=(add-start)/(sizeof(t1));
f.seekp((n1-1)*sizeof(t1),ios::beg); t1.accept();
f.write((char*) &t1,(sizeof(t1)));
f.close();
count++; break;
}
f.read((char*)&t1,(sizeof(t1)));
} if(count==0)
edit"; cin>>name;
f.open("StuRecord.txt",ios::in|ios::out);
f.read((char*)&t1,(sizeof(t1))); while(f)
y=(strcmp(name,t1.name)); if(y==0)
f.seekg(0,ios::beg); start2=f.tellg();
n2=(add2start2)/(sizeof(t1));
f.seekp((n2-1)*sizeof(t1),ios::beg); t1.accept();
f.write((char*) &t1,(sizeof(t1)));
f.close();
break; }
f.read((char*)&t1,(sizeof(t1))); }
modify"; cin>>on;
f.open("StuRecord.txt",ios::in|ios::out);
f.read((char*) &t1,(sizeof(t1)));
while(f) { if(on==t1.rollNo)
{
cout<<"\n\tNumber found"; add3=f.tellg();
f.seekg(0,ios::beg); start3=f.tellg();
n3=(add3start3)/(sizeof(t1));
f.seekp((n3-1)*(sizeof(t1)),ios::beg); t1.accept2();
f.write((char*)&t1,(sizeof(t1)));
f.close(); break;
edit"; cin>>name2;
f.open("StuRecord.txt",ios::in|ios::out);
f.read((char*)&t1,(sizeof(t1)));
while(f)
y1=(strcmp(name2,t1.name)); if(y1==0)
f.seekg(0,ios::beg); start4=f.tellg();
n4=(add4start4)/(sizeof(t1));
f.seekp((n4-1)*sizeof(t1),ios::beg); t1.accept3();
f.write((char*) &t1,(sizeof(t1)));
f.close(); break;
f.read((char*)&t1,(sizeof(t1)));
cout<<"Please Enter the Roll No. of Student Whose Info You Want to Delete: "; cin>>roll;
f.open("StuRecord.txt",ios::in);
g.open("temp.txt",ios::out);
f.read((char *)&t1,sizeof(t1));
while(!f.eof())
if (t1.getRollNo() != roll)
g.write((char *)&t1,sizeof(t1));
f.read((char *)&t1,sizeof(t1)); } cout << "The record with the roll no. " <<
roll << " has been deleted " << endl; f.close();
g.close();
remove("StuRecord.txt");
rename("temp.txt","StuRecord.txt")
; break; case 8: cout<<"\n\tThank
you";
break;
}while(ch!=8);
}
Output :
>>>>>>>>>>>>>>>>>>>>>>MENU<<<<<<<<<<<<<<<<<<<<<
2.Show
8.Exit
Address: Wonderland
1.Yes
2.No: 1
Enter Roll Number : 102
1.Yes
2.No: 1
1.Yes
2.No: 2
>>>>>>>>>>>>>>>>>>>>>>MENU<<<<<<<<<<<<<<<<<<<<<
2.Show
>>>>>>>>>>>>>>>>>>>>>>MENU<<<<<<<<<<<<<<<<<<<<<
2.Show
8.Exit
Record found
>>>>>>>>>>>>>>>>>>>>>>MENU<<<<<<<<<<<<<<<<<<<<<
2.Show
8.Exit
Name found
>>>>>>>>>>>>>>>>>>>>>>MENU<<<<<<<<<<<<<<<<<<<<<
2.Show
3.Search & Edit(number)
8.Exit
Number found
>>>>>>>>>>>>>>>>>>>>>>MENU<<<<<<<<<<<<<<<<<<<<<
2.Show
8.Exit
>>>>>>>>>>>>>>>>>>>>>>MENU<<<<<<<<<<<<<<<<<<<<<
2.Show
Please Enter the Roll No. of Student Whose Info You Want to Delete: 202
The record with the roll no. 202 has been deleted
>>>>>>>>>>>>>>>>>>>>>>MENU<<<<<<<<<<<<<<<<<<<<<
2.Show
8.Exit
Thank you
*/
#include<iostream>
#include<fstream> using
namespace std;
int main()
{
ofstream fout;
ifstream fin;
file.....\n";
cout<<"\n Loca on: "<<fin.tellg();
cout<<"\n Shi control to...";
fin.seekg(014 , ios::beg);
cout<<"\n Loca on:
"<<fin.tellg(); cout<<" Reading....
{ fin.get(c);
cout<<c;
file."; fin.close();
return 0;
Output:
Loca on: 0