oops hi

Download as pdf or txt
Download as pdf or txt
You are on page 1of 67

INDEX

S.NO DATE TITLE PAGE.NO SIGN

1
Tower of Hanoi Using Recursion
2
Binary Search Tree Using Traversal
3
Stack Using Linked List
4
Circular Queue
5
Quick Sort
6
Heap Sort
7
Knapsack Problem Using Greedy Method
8 Search Element in a Tree Using Divide And
Conquer
9
Matrix
10
Virtual Function
11
Parameterized Constructor
12
Friend Function
13
Function Overloading
14
Single Inheritance
15
Employee Details Using Files
EX.NO:01
TOWER OF HANOI USING RECURSION

DATE:

AIM:

To write a program for Tower of Hanoi using C++.

ALGORITHM:

Step 1: Open turbo C++ window.

Step 2: Declare the header files

#include<iostream.h>

#include<conio.h>

Step 3: Create a function

Void TowerOfHanoi()

Step 4: Use the loop statements.

if(num>0) {

TowerOfHanoi(num-1,A,C,B);

Cout<<”Move a Disk”<<num<<”From”<<” “<<A

<<”To”<<” “<<C<<endl<<endl;

TowerOfHanoi(num-1,B,A,C);

Step 5: Save the program.

Step 6: Compile and Run the program.

Step 7: Close the program.


PROGRAM CODING:
#include<iostream.h>

#include<conio.h>

void TowerOfHanoi(int,char,char,char);

void main()

int numOfDisk;

clrscr();

cout<<”enter the no of disks”<<endl;

cin>>numOfDisk;

TowerOfHanoi(numOfDisk,’A’,’B’,’C’);

cout<<endl;

getch();

void TowerOfHanoi(int num,char A,char B,char C)

if(num>0)

TowerOfHanoi(num-1,A,C,B);

Cout<<”Move a Disk”<<num<<”From”<<” “<<A<<”To”<<” “<<C<<endl<<endl;

TowerOfHanoi(num-1,B,A,C);

}
OUTPUT:

RESULT:
Thus the given C++ program has been executed successfully and output was verified.
EX.NO:2
BINARY SEARCH TREE USING TRAVERSAL
DATE:

AIM:

Write a program to traverse through binary search tree using traversals.

ALGORITHM:

Step 1: Open turbo C++ window.

Step 2: Declare the header file

#include<iostream.h>

#include<conio.h>

Step 3: Declare the variables data, left, right.

Step 4: In binary search tree traversal we are using

Void preorder_traversal(tree *root)

Void inorder_traversal(tree *root)

Void postorder_traversal(tree *root)

Step 5: In main function we are declaring values to the root.

Step 6: Save the program.

Step 7: Compile and Run the program.

Step 8: Close the Program.


PROGRAM CODE:
#include<iostream.h>

#include<conio.h>

class Tree

public:

int data;

Tree *left,*right;

Tree(int x)

data=x;

left=NULL;

right=NULL;

};

void preorder_traversal(Tree *root)

if(root==NULL)

return;

cout<<root->data<<" ";

preorder_traversal(root->left);

preorder_traversal(root->right);

void inorder_traversal(Tree *root)

{
if(root==NULL)

return;

inorder_traversal(root->left);

cout<<root->data<<" ";

inorder_traversal(root->right);

void postorder_traversal(Tree *root)

if(root==NULL)

return;

postorder_traversal(root->left);

postorder_traversal(root->right);

cout<<root->data<<" ";

void main()

Tree *root=new Tree(17);

root->left=new Tree(10);

root->right=new Tree(11);

root->left->left=new Tree(7);

root->right->left=new Tree(27);

root->right->right=new Tree(9);

cout<<"Preorder=";

preorder_traversal(root);

cout<<endl;
cout<<"Inorder= ";

inorder_traversal(root);

cout<<endl;

cout<<"Postorder= ";

postorder_traversal(root);

cout<<endl;

getch();

}
OUTPUT:

RESULT:
Thus the given C++ program has been executed successfully and output was verified.
EX.NO:03
STACK USING LINKED LIST

DATE:

AIM:

To write a program for stack using linked list using C++.

ALGORITHM:

Step 1: Open turbo C++ window.

Step 2: Declare the header files

#include<iostream.h>

#include<conio.h>

#include<malloc.h>

#include<string.h>

Step 3: Create a function for search element.

void push () //used for insert the element into the stack

void pop () //used for delete the element into the stack

Step 4: Display the result using cout.

Step 5: Save the program.

Step 6: Compile and Run the program.

Step 7: Close the program.


PROGRAM CODE:
#include<iostream.h>

#include<malloc.h>

#include<conio.h>

#include<string.h>

struct Node

int data;

struct Node *next;

};

struct Node* top=NULL;

void push(int val)

{ struct Node*newnode=(Node*) malloc(sizeof(Node));

//struct Node*newnode=(struct Node*) malloc(sizeof(struct Node));

newnode->data= val;

newnode->next= top;

top= newnode;

void pop()

if(top == NULL)

cout<<"Stack Under Flow"<<endl;

else

cout<<"the Popped Element Is"<<top->data<<endl;


top= top->next;

void display()

struct Node* ptr;

if(top==NULL)

cout<<"Stack Is Empty";

else

ptr= top;

cout<<"Stack Elements Are-->:";

while(ptr!=NULL)

cout<<ptr->data<<" ";

ptr= ptr->next;

cout<<endl;

cout<<endl;

void main()

int ch,val;
clrscr();

cout<<"1.Push in Stack"<<endl;

cout<<"2.Pop From Stack"<<endl;

cout<<"3.Display Stack"<<endl;

cout<<"4.Exit"<<endl;

do

cout<<"Enter The Choice:->"<<endl;

cin>>ch;

switch(ch)

case 1:

cout<<"Enter The Value To Be Pushed:"<<endl;

cin>>val;

push(val);

break;

case 2:

pop();

break;

case 3:

{
display();

break;

case 4:

cout<<"Exit"<<endl;

break;

default:

cout<<"INVALID CHOICE"<<endl;

while(ch!=4);

getch();

}
OUTPUT:

RESULT:
Thus the given C++ program has been executed successfully and output was verified.
EX.NO:4
CIRCULAR QUEUE
DATE:

AIM:

To write a C++ program to perform various operation in circular queue.

ALGORITHM:

Step 1: Open turbo C++ window.

Step 2: Declare the header file

#include<iostream.h>

#include<conio.h>

Step 3: Declare the variable int cqueue [5]; int front=-1,rear=-1,n=5.

Step 4: Declare the function

Void insertCQ(int val)

Void deleteCQ()

Void displayCQ()

Step 5: Use switch case to execute the program.

Step 6: Display a value using

Cout<<”\n Enter your choice:”<<endl;

Step 7: We are getting a value by using

Cin>>ch;

Step 8: Save the program.

Step 9: Compile and Run the program.

Step 10: Close the program.


PROGRAM CODE:
#include<iostream.h>

#include<conio.h>

int cqueue[5];

int front=-1, rear=-1,n=5;

void insertCQ(int val)

if((front==0 && rear==n-1) || (front==rear+1))

cout<<"~*~*Queue IS OverFlow~*~*\n";

return;

if (front==-1)

front=0;

rear=0;

else

if(rear==n-1)

rear=0;

else

rear=rear+1;

}
cqueue[rear]=val;

void deleteCQ()

if(front==-1)

cout<<"Queue IS Underflow\n";

return;

cout<<"Element deleted from The Queue Is-->:"<<cqueue[front]<<endl;

if(front == rear)

front=-1;

rear=-1;

else

if(front==n-1)

front=0;

else

front=front+1;

void displayCQ()

{
int f=front, r=rear;

if(front==-1)

cout<<"QUEUE IS EMPTY!!!"<<endl;

return;

cout<<"QUEUE ELEMENTS ARE --->>\n";

if(f<=r)

while(f<=r)

cout<<cqueue[f]<<" ";

f++;

else

while(f<=n-1)

cout<<cqueue[f]<<" ";

f++;

f=0;

while(f<=r)

{
cout<<cqueue[f]<<" ";

f++;

cout<<endl;

void main()

int ch,val;

clrscr();

cout<<"(1)-->INQUEUE--\n";

cout<<"(2)-->DEQUEUE--\n";

cout<<"(3)-->DISPLAY--\n";

cout<<"(4)-->EXIT--\n";

do

cout<<"ENTER--YOUR--CHOICE-->:"<<endl;

cin>>ch;

switch(ch)

case 1:

cout<<"Input For Inqueue-->:"<<endl;

cin>>val;

insertCQ(val);

break;
case 2:

deleteCQ();

break;

case 3:

displayCQ();

break;

case 4:

cout<<"**!!EXIT!!**\n";

break;

default:

cout<<"!!!INCORRECT CHOICE~*~*~\n";

while(ch!=4);

getch();

}
OUTPUT:

RESULT:
Thus the given C++ program has been executed successfully and output was verified.
EX.NO:05

QUICK SORT
DATE:

AIM:
To write a c++ program to perform quick sort.

ALGORITHM:

Step 1: Start the program

Step 2: Using function variables void quick_sort(int[],int,int)

Step 3: Declare the necessary variables int partition (int[],int,int)

Step 4: Enter the sorting values(a,0,n-1)

Step 5: Use the for condition and if(1<u)

Step 6: Then enter the partition value j=partition(a,1,u)

Quick_sort(a,1,j-1);quick_sort(a,j+1,u)

Step 7: And then using the int partition value and declare the value

Int I,v,temp,j;v=a[1];i=1;j=u+1;using do while statement

Step 8: Display the output using cout.

Step 9: Save the program.

Step10: Compile and Run the program.

Step11: Close the program


PROGRAM CODING:
#include<iostream.h>

#include<conio.h>

void quicksort(int low,int n,int s[]);

int partition(int low,int high,int pp,int s[]);

void quicksort(int low,int high,int s[])

if(high>low)

int pp=partition(low,high,pp,s);

quicksort(low,pp-1,s);

quicksort(pp+1,high,s);

cout<<"\n";

for(int i=low;i<high;i++)

cout<<"\tS:"<<s[i];

int partition(int low,int high,int pp,int s[])

int i,j,pi,temp,temp1;

pi=s[low];

j=low;

for(i=low;i<=high;i++)
{

if(s[i]<pi)

j++;

temp=s[i];

s[i]=s[j];

s[j]=temp;

pp=j;

temp1=s[low];

s[low]=s[pp];

s[pp]=temp1;

return(pp);

void main()

textcolor(GREEN);

textbackground(BLUE);

clrscr();

int n,i,s[20],low;

low=1;

cout<<"\n Enter The Total Number-->:";

cin>>n;

cout<<"Enter The Value>>>>:";


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

cin>>s[i];

quicksort(low,n,s);

getch();

}
OUTPUT:

RESULT:
Thus the given C++ program has been executed successfully and output was verified.
EX.NO:6
HEAP SORT
DATE:

AIM:

Write a program to sort an array of an element using quick sort.

ALGORITHM:

Step 1: Open turbo C++ window.

Step 2: Declare the header file

#include<iostream.h>

#include<conio.h>

Step 3: Declare the necessary variables.

Step 4: Check the left and right elements by using if condition.

Step 5: Create a method heapify for swapping the elements.

Step 6: Print the elements using cout

Step 7: In the main function declare an array

Step 8: Print the Elements for before sorting and after sorting using cout.

Step 9: Save the program.

Step 10: Compile and Run the program.

Step 11: Close the Program.


PROGRAM CODE:
#include<iostream.h>

#include<conio.h>

void heapify(int a[],int n,int i){

int largest=i;

int left=2*i+1;

int right=2*i+2;

if(left<n&&a[left]>a[largest])

largest=left;

if(right<n&&a[right]>a[largest])

largest=right;

if(largest!=i)

int temp=a[i];

a[i]=a[largest];

a[largest]=temp;

heapify(a,n,largest);

void heapsort(int a[],int n)

for(int i=n/2-1;i>=0;i--)

heapify(a,n,i);

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

{ //swap(a[0],a[i]);
int temp=a[0];

a[0]=a[i];

a[i]=temp;

heapify(a,i,0);

void printArr(int a[],int n)

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

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

void main()

int a[]={47,9,22,42,27,25,0};

int n=sizeof(a)/sizeof(a[0]);

clrscr();

cout<<"BEFORE SORTING ARRAY ELEMENTS ARE--->:\n"<<endl;

printArr(a,n);

heapsort(a,n);

cout<<"\n AFTER SORTING ARRAY ELEMENTS ARE--->:\n"<<endl;

printArr(a,n);

getch();

}
OUTPUT:

RESULT:
Thus the given C++ program has been executed successfully and output was verified.
EX.NO:7
KNAPSACK PROBLEM
DATE:

AIM:

To write a program to solve the knapsack problem using greedy method.

ALGORITHM:

Step 1: Open turbo C++ window.

Step 2: Declare the necessary header files

#include<iostream.h>

#include<conio.h>

Step 3: Declare the variable int a, int b.

Step 4: Create a function

int knapsack(int W,int wt[],int valu[],int n){

If(n==0||w==0)

Return 0;

Step 5: Declare the main function.

Step 6: Declare profit,weight,w.

Step 7: Display the output using

Cout<<”\n knapsack(W,weight,profit,n)

Step 8: Save the Program

Step 9: Compile and Run the program.


PROGRAM CODE:
#include<iostream.h>

#include<conio.h>

int max(int a,int b) {

return(a>b)?a:b;

int knapSack(int W,int wt[],int val[],int n)

if(n==0||W==0)

return 0;

if(wt[n-1]>W)

return knapSack(W,wt,val,n-1);

else

return max(

val[n-1]+knapSack(W-wt[n-1],wt,val,n-1),knapSack(W,wt,val,n-1));

void main(){

int profit[]={60,100,120};

int weight[]={10,20,30};

int W=50;

clrscr();

int n= sizeof(profit)/sizeof (profit[0]);

cout<<"--->"<<knapSack(W,weight,profit,n);

getch();

}
OUTPUT:

RESULT:
Thus the given C++ program has been executed successfully and output was verified.
-EX.NO:08
DIVIDE AND CONQUER

DATE:

AIM:

To write a program for Searching element in tree using divide and conquer
in C++.

ALGORITHM:

Step 1: Open turbo C++ window.

Step 2: Declare the header files

#include<iostream.h>

#include<conio.h>

Step 3: Create a function for search element.

Void binary_search ()

Step 4: using the if statements into the binary_search function.

Step 5: Save the program.

Step 6: Compile and Run the program.

Step 7: Close the program.


PROGRAM CODE:
#include<iostream.h>

#include<conio.h>

int binary_search(int a[],int key,int len)

int low=0;

int high=len-1;

while(low<=high)

int mid=(low+(high-low)/2);

if(a[mid]==key)

return mid;

if(key<a[mid])

high=mid-1;

else

low=mid+1;

return -1;

}
void main()

int a[10]={1,3,5,7,9,11,13,15,17,21};

int key = 5;

int position=binary_search(a,key,10);

clrscr();

cout<<"\t\t*~*~*~DIVIDE AND CONQUER USING BINARY SEARCH*~*~*~"<<endl;

cout<<"\n\n";

if(position==-1)

cout<<"\tNOT FOUND!!!"<<endl;

else

cout<<"\tTHE ELEMENT FOUNDED IN POSITION IS---->:"<<position<<endl;

getch();

}
OUTPUT:

RESULT:
Thus the given C++ program has been executed successfully and output was verified.
-EX.NO:09
MATRIX

DATE:

AIM:

To write a program for 8 Queen problem using matrix in C++.

ALGORITHM:

Step 1: Open turbo C++ window.

Step 2: Declare the header files

#include<iostream.h>

#include<conio.h>

Step 4: Create a function for Print the result

Void bool isvalid ()

Void bool search()

Step 5:check the queen in the matrix using bool isvalid`() function.

Step6: search the queen in the matrix using bool bool search()

Function.

Step 7: Save the program.

Step 8: Compile and Run the program.

Step 9: Close the program.


PROGRAM CODE:
#include <iostream>

using namespace std;

const int NUMBER_OF_QUEENS = 8; // Constant: eight queens

int queens[NUMBER_OF_QUEENS];

bool isValid(int row, int column)

for (int i = 1; i <= row; i++)

if (queens[row - i] == column // Check column

|| queens[row - i] == column - i // Check upper left diagonal

|| queens[row - i] == column + i) // Check upper right diagonal

return false; // There is a conflict

return true; // No conflict

void printResult(int row)

cout << "\n---------------------------------\n";

for (row; row < NUMBER_OF_QUEENS; row++)

for (int column = 0; column < NUMBER_OF_QUEENS; column++)

printf(column == queens[row] ? "| Q " : "| ");

cout << "|\n---------------------------------\n";

bool search(int row)


{

if (row == NUMBER_OF_QUEENS) // Stopping condition

return true;

for (int column = 0; column < NUMBER_OF_QUEENS; column++)

queens[row] = column; // Place a queen at (row, column)

if (isValid(row, column) && search(row + 1))

return true; // Found, thus return true to exit for loop

return false;

void main()

int inputRow;

cout << "Enter the row to search from:" << endl;

cin >> inputRow;

search(inputRow); to 7

printResult(inputRow);

}
OUTPUT:

RESULT:
Thus the given C++ program has been executed successfully and output was verified.
EX.NO:10
VIRTUAL FUNCTION
DATE:

AIM:

Write a program to perform virtual function using C++.

ALGORITHM:

Step 1: Open turbo C++ window.

Step 2: Declare the header file

#include<iostream.h>

#include<conio.h>

Step 3: Declare a variable like x, y.

Step 4: Print the result using cout

Step 5: Save the Program.

Step 6: Compile and Run the program.

Step 7: Close the program.


PROGRAM CODING:
#include<iostream.h>

#include<conio.h>

class A{

int x;

public:

void display(){

x=5;

cout<<"Value of X Is--->:"<<x<<endl;

};

class B:public A{

int y;

public:

void display(){

y=5;

cout<<"Value Of Y Is--->:"<<y<<endl;

};

void main(){

A*a;

B b;

a=&b;

a->display();

getch();}
OUTPUT:

RESULT:
Thus the given C++ program has been executed successfully and output was verified.
EX.NO:11
PARMETERIZED CONSTRUCTOR

DATE:

AIM:

To write a program for parameterized constructor using C++.

ALGORITHM:

Step 1: Open turbo C++ window.

Step 2: Declare the header file

#include<iostream.h>

#include<conio.h>

Step 3: Declare the variables a, b, c.

Step 4: Create a function

Void add ()

C=a+b;

Cout<<”total:”<<c<<endl;

Step 5: Save the program.

Step 6: Compile and Run the program.

Step 7: Close the program.


PROGRAM CODING:
#include<iostream.h>

#include<conio.h>

class math

Private:

int a,b,c;

public:

math(int x,int y)

a=x;

b=y;

void add()

c=a+b;

cout<<”Total”<<c;

};

void main()

math o(10,25);

clrscr();

o.add();

}
OUTPUT:

RESULT:
Thus the given C++ program has been executed successfully and output was verified.
EX.NO:12
FRIEND FUNCTION

DATE:

AIM:

To write a C++ program to perform friend function.

ALGORITHM:

Step 1: Open turbo C++ window.

Step 2: Declare the header file

#include<iostream.h>

#include<conio.h>

Step 3: Declare a variable char str[20];

Step 4: Create a function like

Void get()

Void show()

Step 5: Create an object like a, b.

Step 6: Check the string using string comparision function

If(strcmp(s.str,a.str)==0)

Cout<<”\n they are equal”<<endl;

else

cout<<”\n they are not equal”<<endl;

Step 7: Save the program.

Step 8: Compile and Run the program.

Step 9: Close the program.


PROGRAM CODING:
#include<iostream.h>

#include<conio.h>

#include<string.h>

class string

char str[20];

public:

void get()

cout<<"\n Enter The String-->:";

cin>>str;

void show()

cout<<"\n The String Is --->:"<<str<<endl;

friend string operator==(string s,string a)

int c;

if(strcmp(s.str,a.str)==0)

cout<<"\n They Are Same"<<endl;

else

cout<<"\n They Are Not Same"<<endl;

}
};

void main()

string a,b;

clrscr();

cout<<"\t\t\t*******FRIEND FUNCTION*******"<<endl;

a.get();

a.show();

b.get();

b.show();

a==b;

getch();

}
OUTPUT:

RESULT:
Thus the given C++ program has been executed successfully and output was verified.
EX.NO:13
FUNCTION OVERLOADING
DATE:

AIM:

Write a C++ program to perform function overloading.

ALGORITHM:

Step 1: Open turbo C++ window.

Step 2: Declare the header file

#include <iostream.h>

#include<conio.h>

Step 3: Declare the variable like a, r, d, e, l, b, t.

Step 4: Create a function like

Void measure::shape (int r);

Void measure::shape (int l, int b)

Step 5: Call a function using an object obj

Obj. shape (r);

Step 6: We are using switch case to execute the program.

Step 7: Save the program.

Step 8: Compile and Run the program.

Step 9: Close the program.


PROGRAM CODE:
#include<iostream.h>

#include<conio.h>

class measure {

public:

void shape(int r);

void shape(int l,int b);

void shape(float t,int d,int e);

void shape(long a);

void shape(float c,long int g);

void shape(double j);

void shape(float h,double f);

};

void measure::shape(int r)

cout<<"Area Of The Circle Is->"<<3.14*r*r;

void measure::shape(int l,int b)

cout<<"Area Of The Rectangle Is->"<<l*b;

void measure::shape(float t,int d,int e)

cout<<"Area Of The Triangle Is->"<<t*d*e;

}
void measure::shape(long a)

cout<<"Area Of The Square Is->"<<a*a;

void measure::shape(float c,long int g)

cout<<"Area Of The Cone Is->"<<0.3*3.14*c*c*g;

void measure::shape(double j)

cout<<"Area Of The Sphere Is->"<<1.3*3.14*j*j*j;

void measure::shape(float h,double f)

cout<<"Area Of The Cylinder Is->"<<3.14*f*f*h;

void main() {

int r,d,e,l,b;

double t,c,h;

long a;

int ch;

double j,f;

long int g;

clrscr();

measure obj;
cout<<"\t CALCULATION OF AREAS & VOLUME";

cout<<"\n\n1.Area of Circle:";

cout<<"\n\n2.Area of Rectangle:";

cout<<"\n\n3.Area of Triangle:";

cout<<"\n\n4.Area of Square:";

cout<<"\n\n5.volume of Cone:";

cout<<"\n\n6.volume of Sphere:";

cout<<"\n\n7.volume of Cylinder:";

cout<<"\n\n\t\t Enter Your Choice-->";

cin>>ch;

switch (ch){

case 1:

cout<<"Enter the Radius Of Circle\n";

cin>>r;

obj.shape(r);

break;

case 2:

cout<<"Enter the Sides Of Rectangle\n";

cin>>l>>b;

obj.shape(l,b);

break;

case 3:

cout<<"Enter the Sides Of Triangle\n";

cin>>d>>e;

obj.shape(0.5,d,e);
break;

case 4:

cout<<"Enter the Sides Of Square\n";

cin>>a;

obj.shape(a);

break;

case 5:

cout<<"Enter The Radius Of Cone\n";

cin>>c;

cout<<"Enter The Height Of Cone\n";

cin>>g;

obj.shape(c,g);

break;

case 6:

cout<<"Enter The Radius Of Sphere\n";

cin>>j;

obj.shape(j);

break;

case 7:

cout<<"Enter The Radius Of Cylinder\n";

cin>>f;

cout<<"Enter The Height Of Cylinder\n";

cin>>h;

obj.shape(h,f);

break;
default:

cout<<"\n WRONG CHOICE";

getch();

}
OUTPUT:

RESULT:
Thus the given C++ program has been executed successfully and output was verified.
EX.NO:14
SINGLE INHERITANCE

DATE:

AIM:

To write a program for single inheritance in C++

ALGORITHM:

Step 1: Open turbo C++ window.

Step 2: Declare the header file

#include<iostream.h>

#include<conio.h>

Step 3: Declare the variable name, roll no, tam, eng, mat, tot, and avg.

Step 4: Create a function

Void get data ();

Void display ();

Step 5: Create an object for derived class n s;

Step 6: Call a function by using an object

s.getdata ();

s.display ();

Step 7: Save the program.

Step 8: Compile and Run the program.

Step 9: Close the program.


PROGRAM CODE:
#include<iostream.h>

#include<conio.h>

class st

protected:

int tam,eng,mat,tol,avg,rollno;

char name[10];

public:

void getdata()

cout<<"Enter The Name:->"<<endl;

cin>>name;

cout<<"Enter The RollNo:->"<<endl;

cin>>rollno;

cout<<"Enter The Tamil Mark:->"<<endl;

cin>>tam;

cout<<"Enter The English Mark:->"<<endl;

cin>>eng;

cout<<"Enter The Maths Mark:->"<<endl;

cin>>mat;

tol=tam+eng+mat;

avg=tol/3;

}
};

class n:public st

public:

void display()

cout<<"***~~STUDENTS DETAILS~~~***"<<endl;

cout<<"NAME:->"<<name<<endl;

cout<<"ROLL NO:->"<<rollno<<endl;

cout<<"TAMIL:->"<<tam<<endl;

cout<<"ENGLISH:->"<<eng<<endl;

cout<<"MATHS:->"<<mat<<endl;

cout<<"TOTAL:->>"<<tol<<endl;

cout<<"AVERAGE:->>"<<avg<<endl;

};

void main(){

n s;

clrscr();

cout<<"***~~~DEMONSTRATE SINGLE INHERITANCE***~~~"<<endl;

s.getdata();

s.display();

getch();

}
OUTPUT:

RESULT:
Thus the given C++ program has been executed successfully and output was verified.
EX.NO:15
EMPLOYEE DETAILS USING FILE
DATE:

AIM:

Write a C++ program to perform employee details using files.

ALGORITHM:

Step 1: Open turbo C++ window.

Step 2: Declare the header file

#include<fstream.h>

#include<iostream.h>

Step 3: Ofsteam is used to create and write to the file.

Step 4: Getting employee name and age.

Step 5: Read a file using ifstream.

Step 6: Display the details using ofstream

Outfile<<data<<endl;

Step 7: Display the details using ifstream

Cout<<data<<endl;

Step 8: Close the file using

Outfile.close();

Infile.close();

Step 9: Save the Program.

Step 10: Compile and Run the program.

Step 11: Close the Program


PROGRAM CODING:
#include<iostream.h>

#include<fstream.h>

#include<conio.h>

void main() {

char data[100];

clrscr();

cout<<"\t\t\t*******EMPLOYEE DETAILS USING FILES*******"<<endl;

ofstream outfile;

outfile.open("afile.dat");

cout<<"Writing To The File"<<endl;

cout<<"Enter Employee Name-->";

cin.getline(data,100);

outfile<<data<<endl;

cout<<"Enter Employee Age--->";

cin>>data;

cin.ignore();

outfile<<data<<endl;

outfile.close();

ifstream infile;

infile.open("afile.dat");

cout<<"Reading From The File"<<endl;

infile>>data;

cout<<data<<endl;

infile>>data;
cout<<data<<endl;

infile.close();

getch();

}
OUTPUT:

RESULT:
Thus the given C++ program has been executed successfully and output was verified.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy