Professional Documents
Culture Documents
Simple Black N White
Simple Black N White
Ans.
#include<iostream.h>
#include<conio.h>
const int size=40;
int array[size],n;
void bubble_sort()
{ int temp;
for(int j=0;j<i;j++)
{
if(array[j]<array[j+1])
{
temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
}
}
}
}
void main()
{
clrscr();
cout<<"Enter number of elements of the array(max 40):";
cin>>n;
cout<<"Enter Array Elements:";
for(int i=0;i<n;i++)
cin>>array[i];
bubble_sort();
cout<<"Sorted array:\n";
for(i=0;i<n;i++)
cout<<array[i]<<" ";
getch();
}
OUTPUT
Ans.
#include<iostream.h>
#include<conio.h>
const int size=40;
int array[size],n;
void Ins_sort()
{
int tmp,j;
array[0]=-32678;
for(int k=1;k<=n;k++)
{
j=k-1;
tmp=array[k];
while(tmp<array[j])
{
array[j+1]=array[j];
j--;
}
array[j+1]=tmp;
}
}
void main()
{
clrscr();
cout<<"Enter number of elements of array(max 40):";
cin>>n;
cout<<"Enter Array Elements:";
for(int i=1;i<=n;i++)
cin>>array[i];
Ins_sort();
cout<<"Sorted Array:\n";
for(i=1;i<=n;i++)
cout<<array[i]<<" ";
getch();
}
OUTPUT
Ans.
#include<iostream.h>
#include<conio.h>
const int size=40;
int array[size],n;
void sel_sort()
{
int small,pos,temp;
for(int i=0;i<n;i++)
{
small=array[i];
pos=i;
for(int j=i+1;j<n;j++)
{
if(array[j]<small)
{
small=array[j];
pos=j;
}
}
temp=array[i];
array[i]=array[pos];
array[pos]=temp;
}
}
void main()
{
clrscr();
cout<<"Enter the number of elements of the array(max 40):";
cin>>n;
cout<<"Enter Array Elements:";
for(int i=0;i<n;i++)
cin>>array[i];
sel_sort();
cout<<"Sorted Array:\n";
for(i=0;i<n;i++)
cout<<array[i]<<" ";
getch();
}
OUTPUT
Ans.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class Person
{
char name[31];
int age;
public:
void getperson()
{
cout<<"Enter Name:";
gets(name);
cout<<"\nEnter Age:";
cin>>age;
}
void putperson()
{
cout<<"\nName:";
puts(name);
cout<<"\nAge:"<<age;
}
};
Enter Name:ojasvi
Enter Age:26
Enter Roll No.:12125
Enter Marks:89
Enter Subject:C++
Enter Emplyment Details(y/n):N
Name:ojasvi
Age:26
Roll No.:12125
Marks:89
Subject:C++
Employed:N
Q-5.Implementation of Multiple Inheritance
Ans.
#include<iostream.h>
#include<string.h>
#include<stdio.h>
#include<conio.h>
class person
{
char name[31],gender;
int age;
public:
int getage()
{
return age;
}
void getinfo()
{
cout<<"Enter Name:";
gets(name);
cout<<"Enter Gender:";
cin>>gender;
cout<<"Enter Age:";
cin>>age;
}
void putinfo()
{
cout<<"\nName:";
puts(name);
cout<<"\nGender:"<<gender;
cout<<"\nAge:"<.<age;
};
class Qualifications
{
int exp;
char degree[31];
public:
int getexp()
{
return exp;
}
void getquali()
{
cout<<"Enter Degree Name:";
gets(degree);
cout<<"Enter Experience:";
cin>>exp;
}
void putquali()
{
cout<<"\nDegree:";
puts(degree);
cout<<"\nExperience:"<<exp;
}
};
class job:public person,public Qualifications
{
char y_n[5];
void res()
{
if(getexp()>3&&getage()<45)
strcpy(y_n,"Yes");
else
strcpy(y_n,"No");
}
public:
void in()
{
getinfo();
getquali();
res();
}
void out()
{
putinfo();
putquali();
cout<<"\nJob:";
puts(y_n);
}
}J;
void main()
{
clrscr();
J.in();
J.out();
getch();
}
OUTPUT
Enter Name:ojasvi
Enter Gender:M
Enter Age:26
Enter Degree Name:B.Tech Computers
Enter Experience:4
Name:ojasvi
Gender:M
Age:26
Degree:B.Tech Computers
Experience:4
Job:Yes
Q-6.Count the no. of vowels in a given file
Ans.
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
OUTPUT
Enter file name:vowels.txt
The no. of vowels in file:14
Q-7.A Menu driven Program to calculate TSA and Volume of Cube,
Cuboid, Cylinder depending upon users choice.
Ans.
#include<iostream.h>
#include<conio.h>
void Tsa_Volume(int a)
{
cout<<"\nVolume:"<<a*a*a;
cout<<"\nTotal Surface Area:"<<6*a*a;
}
void Tsa_Volume(int a,int b,int c)
{
cout<<"\nVolume:"<<a*b*c;
cout<<"\nTotal Surface Area:"<<2*(a*b+b*c+a*c);
}
void Tsa_Volume(int a,int b)
{
cout<<"\nVolume:"<<(22*a*a*b)/7;
cout<<"\nTotal Surface Area:"<<(2*22*a*(b+a))/7;
}
void main()
{
int a,b,c;
int choice;
do
{
clrscr();
cout<<"\t\tSurface Area & Volume Calculator \n";
cout<<"\t1.Cube\n\t2.Cuboid\n\t3.Cylinder\n\t4.Exit\nEnter your
Choice :";
cin>>choice;
switch(choice)
{
case 1: cout<<"Enter Side of cube:";
cin>>a;
Tsa_Volume(a);
break;
case 2: cout<<"Enter Length,Bredth,Height of the cuboid:";
cin>>a>>b>>c;
Tsa_Volume(a,b,c);
break;
case 3: cout<<"Enter Radii of Cuboid:";
cin>>a;
cout<<"Enter Height of Cuboid:";
cin>>b;
Tsa_Volume(a,b);
break;
case 4: return ;
default:cout<<"Wrong Choice!!!!";
break;
}
getch();
}while(choice!=4) ;
}
OUTPUT
Volume:125
Total Surface Area:150
Q-9. Define a class STUDENT with following specifications:
Ans.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class student
{
int addno;
char name[21];
int Class;
int rollno;
public:
void getdata()
{
cout<<"Enter Addmission No.:";
cin>>addno;
cout<<"Enter Name:";
gets(name);
cout<<"Enter Class:";
cin>>Class;
cout<<"Enter Roll No.:";
cin>>rollno;
}
void showdata()
{
cout<<"\nAddmission No.:"<<addno;
cout<<"Name:";
puts(name);
cout<<"\nClass:"<<Class;
cout<<"\nRoll No.:"<<rollno;
}
}J[10];
void main()
{
for(int i=0;i<10;i++)
{
cout<<"\nStudent "<<i<<endl;
J[i].getdata();
}
for(i=0;i<10;i++)
{
cout<<"\nStudent "<<i<<endl;
J[i].showdata();
}
getch();}
OUTPUT
Student 1
Enter Admission No.:102
Enter Name:ojasvi
Enter Class:12
Enter Roll No.:12105
.
.
.
.
Student 1
Admission No.:102
Name:ojasvi
Class:12
Roll No.:12105
.
.
.
Q-10.Program to display the size of a file in bytes
Ans.
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char filename[21];
cout<<"ENter File name:";
gets(filename);
ifstream fin(filename,ios::in);
if(!fin)
{
cout<<"Cannot open file.Aborting!!!";
return;
}
fin.seekg(0,ios::end);
long bytes=fin.tellg();
cout<<"\nFile size is "<<bytes<<" bytes.";
getch();
}
OUTPUT
Ans.
#include<iostream.h>
#include<conio.h>
int A[40],B[40],C[60];
int m,n,mn;
void Merge()
{
int a=0,b=0,c=0;
while(a<m&&b<n)
{
if(A[a]<B[b])
C[c++]=A[a++];
else
C[c++]=B[b++];
}
if(a<m)
while(a<m)
C[c++]=A[a++];
else
while(b<n)
C[c++]=B[b++];
}
void main()
{
cout<<"Enter number of elements of Array A:";
cin>>m;
cout<<"Enter elements of Array A:\n";
for(int i=0;i<m;i++)
cin>>A[i];
cout<<"Enter number of elements of Array B:";
cin>>n;
cout<<"Enter elements of Array B:\n";
for(i=0;i<n;i++)
cin>>B[i];
mn=m+n;
if(mn<=60)
Merge();
else
{
cout<<"Array C cannot be created!!Overflow!!!";
return;
}
cout<<"\nTHe sorted Array C :\n";
for(i=0;i<mn;i++)
cout<<C[i]<<" ";
getch();}
OUTPUT
Ans.
#include<iostream.h>
#include<conio.h>
struct Node
{
int info;
Node *next;
} *start,*newptr,*save,*ptr;
Node *Create_New_Node(int n)
{
ptr=new Node;
ptr->info=n;
ptr->next=NULL;
return ptr;
}
void InsertBeg(Node *np)
{
if(start==NULL)
start=np;
else
{
save=start;
start=np;
np->next=save;
}
}
void Display(Node *np)
{
while(np!=NULL)
{
cout<<np->info<<"->";
np=np->next ;
}
cout<<"!!!\n";
}
void main()
{
start=NULL;
int inf;
char ch='y';
while(ch=='y'||ch=='Y')
{
Ans.
#include<iostream.h>
#include<conio.h>
struct Node
{
int info;
Node *next;
} *start,*newptr,*save,*ptr,*rear;
Node *Create_New_Node(int n)
{
ptr=new Node;
ptr->info=n;
ptr->next=NULL;
return ptr;
}
void Insert(Node *np)
{
if(start==NULL)
start=rear=np;
else
{
rear->next=np;
rear=np;
np->next=save;
}
}
void Display(Node *np)
{
while(np!=NULL)
{
cout<<np->info<<"->";
np=np->next ;
}
cout<<"!!!\n";
}
int Delnode()
{
if(start==NULL)
{
cout<<"Underflow!!!\n";
return 1;
}
else
{
ptr=start;
start=start->next;
delete ptr;
return 0;
}
}
void main()
{
start=rear=NULL;
int inf;
char ch='y';
while(ch=='y'||ch=='Y')
{
Insert(newptr);
cout<<"\nPress Y to enter more nodes,N to exit...\n ";
cin>>ch;
}
int r;
do
{
cout<<"\nNow the List is :\n";
Display(start);
cout<<"\n Do you want to delete first node(y/n):";
cin>>ch;
if (ch=='y'||ch=='Y')
r=Delnode();
}while((ch=='y'||ch=='Y')&&r!=1);
getch();
delete start;
delete newptr;
delete save;
delete rear;
delete ptr;
}
OUTPUT
Ans.
#include<iostream.h>
#include<conio.h>
void main()
{
int elem;
clrscr();
cout<<"Enter size of array(max 40):";
cin>>n;
cout<<"Enter Array Elements:\n";
for(int i=0;i<n;i++)
cin>>array[i];
OUTPUT
Ans.
#include<iostream.h>
#include<conio.h>
const int size=40;
int array[size],n;
Ans.
#include <iostream.h>
#include <conio.h>
#include<ctype.h>
int pop();
void Display();
void main()
{
int choice;
int val;
char opt='y';
top = -1;
clrscr();
int pop()
{
int value;
if (top < 0)
{
cout<< "\nUnderflow!!!!";
value = -1;
}
else
{
value = stack[top];
top = top - 1;
}
if(value!=-1)
cout<<"Element deleted from Stack is "<<value<<endl;
return value;
}
void Display()
{
int i;
i = top;
while(i>=0)
{
cout <<stack[i]<<"<-";
i = i - 1;
}
}
OUTPUT
Ans.
#include <iostream.h>
#include <conio.h>
#include <ctype.h>
int push(int);
void Display();
void main()
{
int val,ret;
char opt = 'Y';
top = -1;
clrscr();
cout << "\n\tPush in Stack";
do
{
cout << "\nEnter the value to be added in the stack ";
cin >> val;
ret=push(val);
if(ret==-1)
break;
cout<<"\nNow the stack is: \n";
Display();
cout << "\nDo you want to add more element <Y/N>? ";
cin >> opt;
} while (toupper(opt) == 'Y');
void Display()
{
int i;
i = top;
while(i>=0)
{
cout <<stack[i]<<"<-";
i = i - 1;
}while(i >= 0);
}
OUTPUT
Push in Stack
Enter the value to be added in the stack 25
Ans.
#include <iostream.h>
#include <conio.h>
#include <ctype.h>
int Insertion(int);
void Display();
void main()
{
int ch, val;
char opt = 'Y'; // To continue the do loop in case
rear = -1; // Initialization of Queue
front = -1;
clrscr();
cout << "\n\tInsertion in Queue\n";
do
{
cout << "Enter the value to be added in the queue: ";
cin >> val;
ch=Insertion(val);
cout<<"Now the Queue is:\n";
Display();
if(!ch)
break;
cout << "\nDo you want to add more elements <Y/N>:";
cin >> opt;
} while (toupper(opt) == 'Y');
void Display()
{
if (front==rear&& rear<0)
{
cout << "\tQueue Empty!!!";
return;
}
int i=front;
while(i<=rear)
{
Insertion in Queue
Enter the value to be added in the queue: 25
Now the Queue is:
25<-
Do you want to add more elements <Y/N>:y
Enter the value to be added in the queue: 36
Now the Queue is:
25<-36<-
Do you want to add more elements <Y/N>:n
Q-20.Deletion in Array Queue
Ans.
#include <iostream.h>
#include <conio.h>
#include <ctype.h>
int Deletion();
void Display();
void main()
{
int val,ch;
char opt = 'Y';
rear = -1;
front = -1;
clrscr();
if(val!=-1)
{
cout<<"Now the Queue is:";
Display();
}
else
break;
cout << "\nDo you want to delete more elements <Y/N> ? " ;
cin >> opt;
} while (toupper(opt) == 'Y');
getch();
}
int Deletion()
{
int value;
if (front==rear&&rear<0)
{
cout << "\nUNDERFLOW!!! ";
value = -1;
}
else
{
front = front + 1;
value = queue[front];
}
return (value);
}
// Function body for show queue with array
void Display()
{
int i=front;
while(i<=rear)
{
cout<<queue[i]<<"<-";
i++;
}
OUTPUT
Ans.
#include<iostream.h>
#include<fstream.h>
#include<process.h>
int main()
{
Char filename[13];
Cout<<”Enter the text file name:”;
Cin.getline(filename,13);
Cout<<”\n”;
Ifstream fin;
Fin.open(filename,ios::in);
If(!fin)
{cerr<<”\nfile cannot be opened\n”;
Exit(-1);
}
Ofstream fout;
Fout.open(“PRN”,ios::out);
Char ch;
While (fin.get(ch)!=0)
Fout.put(ch);
Return0;
}
OUTPUT
Ans.
#include<iostream.h>
#include<string.h>
#include<stdio.h>
#include<conio.h>
class Student
{
int rollno,marks;
char name[31],stream[31];
void streamalloc()
{
if(marks>=96)
strcpy(stream,"Computer Science");
else if(marks>=91)
strcpy(stream,"Electronics");
else if(marks>=86)
strcpy(stream,"Mechanical");
else if(marks>=81)
strcpy(stream,"Electrical");
else if(marks>=75)
strcpy(stream,"Chemical");
else
strcpy(stream,"Civil");
}
public:
void getinfo()
{
cout<<"Enter Roll No.:";
cin>>rollno;
cout<<"Enter Name:";
gets(name);
cout<<"Enter Marks:";
cin>>marks;
streamalloc();
}
void putinfo()
{
cout<<"\nRoll No.:"<<rollno;
cout<<"\nName:";
puts(name);
cout<<"\nMarks:"<<marks;
cout<<"\nStream:";
puts(stream);
}
};
void main()
{
clrscr();
Student J[20];
char ch;
int final;
for(int i=0;i<20;i++)
{
cout<<"Enter Details of Student "<<i+1<<endl;
J[i].getinfo();
cout<<"\nDo you want Enter more Records(y/n):";
cin>>ch;
if(ch!='y'||ch!='Y')
{
final=i;
break;
}
}
clrscr();
for(i=0;i<=final;i++ )
{
cout<<"Student "<<i+1<<endl;
J[i].putinfo();
cout<<endl;
}
getch();
}
OUTPUT
Student 1
Roll No.:12125
Name:Ojasvi
Marks:93
Stream:Electronics