Project
Project
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main()
{
clrscr();
char str[10];
int i,j,n,flag=0;
cout<<endl<<"Enter any string:"<<endl;
gets(str);
n=strlen(str);
for(i=0,j=n-1;i<=n/2;i++,j--)
{
if(str[i]!=str[j])
{ flag=1;
break;
}
}
if(flag==1)
{
cout<<"String is not Palindrome"<<endl;
}
else
{
cout<<"String is Palindrome"<<endl;
}
getch();
}
OUTPUT
2. Write a program in C++ to calculate area of Circle, Triangle and
Rectangle using Function.
include<iostream.h>
#include<conio.h>
#include<math.h>
#include<process.h>
#define pi 3.14
//circle area
void area(float r)
{
cout<<endl<<" Area Of The Circle : "<<pi*r*r;
}
//rectangle area
void area(float l,float b)
{
cout<<endl<<" Area Of The Rectangle : "<<l*b;
}
//triangle area
void area(float a,float b,float c)
{
float s=(a+b+c)/2;
float ar=sqrt(s*(s-a)*(s-b)*(s-c));
cout<<endl<<" Area Of The Triangle : "<<ar;
}
void main()
{
clrscr();
float r,ln,br,a,b,c;
int ch;
do
{
cout<<endl<<"-*- AREA OF DIFFERENT SHAPES USING FUNCTION OVERLOADING -
*-";
cout<<endl<<" Area Of Calculation Menu ";
cout<<endl<<" 1.CIRCLE AREA ";
cout<<endl<<" 2.RECTANGLE AREA ";
cout<<endl<<" 3.TRIANGLE AREA ";
cout<<endl<<" 4.EXIT ";
cout<<endl<<" Enter Your Choice : ";
cin>>ch;
switch(ch)
{
case 1:cout<<endl<<" Enter The Radius Of A Circle : ";
cin>>r;
area(r);
break;
case 2:cout<<endl<<" Enter The Length Of The Rectangle : ";
cin>>ln;
cout<<endl<<" Enter The Breadth Of The Rectangle : ";
cin>>br;
area(ln,br);
break;
case 3:cout<<" Enter First Side Of The Triangle : ";
cin>>a;
cout<<" Enter Second Side Of The Triangle : ";
cin>>b;
cout<<" Enter Third Side Of The Triangle : ";
cin>>c;
area(a,b,c);
break;
case 4:exit(0);
}
}while(1);
getch();
}
OUTPUT
FOR CIRCLE
FOR RECTANGLE
FOR TRIANGLE
3. Write a program in C++ to implement Function Overloading.
#include <iostream.h>
#include <conio.h>
long add(long, long);
float add(float, float);
void main()
{ clrscr();
long a, b, x;
float c, d, y;
x = add(a, b);
y = add(c, d);
cout << "Sum of floats: " << y << endl;
getch();
}
long add(long x, long y)
{
long sum;
sum = x + y;
return sum;
}
float add(float x, float y)
{
float sum;
sum = x + y;
return sum;
}
OUTPUT
4. Write a program in C++ to calculate simple interest amount using
function overloading.
#include<iostream>
#include <conio.h>
void amt(float prin,float rate,int time)
{
cout<<"Principal amount : "<<prin<<" ";
cout<<"Rate : "<<rate<<" ";
cout<<"Time : "<<time<<" ";
cout<<"Total interest : "<<prin*rate*time<<endl;
}
void amt(float prin,int time)
{
amt(prin,.05F,time);
}
void amt(float prin,float rate)
{
amt(prin,rate,5);
}
void amt(int time,float rate)
{
amt(5000.0F,rate,time);
}
void amt(float rate)
{
amt(5000.0F,rate,5);
}
void amt(int time)
{
amt(5000.0F,.05,time);
}
void main()
{
amt(.09F);
amt(2);
amt(9000.0F,8);
amt(7,.02);
amt(2000.0F,.03F,6);
getch();
}
OUTPUT
5. Write a program in C++ to do linear search using array.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10], i, num, n,c=0,pos;
cout<<"Enter Size of Array:"<<"\t";
cin>>n;
cout<<"Enter Array Elements:";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"Enter the no. to be searched:"<<"\t";
cin>>num;
for(i=0;i<n;i++)
{
if(a[i]==num)
{
c=1;
pos=i+1;
break;
}
}
if(c==0)
{
cout<<"Number not found....!!!!!";
}
else
{
cout<<num<<"found at position"<<pos;
}
getch();
}
OUTPUT
6. Write a program in C++ to do binary search using array.
#include <iostream>
using namespace std;
int main()
{
int count, i, arr[30], num, first, last, middle;
cout<<"how many elements would you like to enter?:";
cin>>count;
}
else if(arr[middle] == num)
{
cout<<num<<" found in the array at the location "<<middle+1<<"\n";
break;
}
else {
last = middle - 1;
}
middle = (first + last)/2;
}
if(first > last)
{
cout<<num<<" not found in the array";
}
return 0;
}
OUTPUT
7. Write a program in C++ to implement bubble sort.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n, i, arr[50], j, temp;
cout<<"Enter total number of elements :";
cin>>n;
cout<<"Enter "<<n<<" numbers :";
for(i=0; i<n; i++)
{
cin>>arr[i];
}
cout<<"Sorting array using bubble sort technique...\n";
OUTPUT
11. Write a program in C++ to implement concept of Constructor and
Destructor.
#include <iostream.h>
#include <conio.h>
class Line
{
public:
void setLength( int len );
double getLength( void );
Line();
~Line();
private:
double length;
};
Line::Line(void)
{
cout << "Object is being created" << endl;
}
Line::~Line(void)
{
cout << "Object is being deleted" << endl; OUTPUT
}
void Line::setLength( int len )
{
length = len;
}
double Line::getLength( void )
{
return length;
}
void main()
{
Line line;
line.setLength(6.0);
cout << "Length of line : " <<
line.getLength() <<endl;
getch();
}
#include<iostream.h>
#include<conio.h>
class baseclass1
{
protected:
int acc;
char name[20];
public:
void enter1()
{
cout<<" Enter The Accession Number : ";
cin>>acc;
cout<<" Enter The Name Of The Author : ";
cin>>name;
}
};
class baseclass2
{
protected:
char title[30],pname[20];
int year;
public:
void enter2()
{
cout<<" Enter The Title Of Book : ";
cin>>title;
cout<<" Enter The Year Of Publication : ";
cin>>year;
cout<<" Enter The Publisher Name : ";
cin>>pname;
}
};
class derivedclass : public baseclass1,public baseclass2
{
protected:
float cost;
public:
void enter3()
{
cout<<" Enter The Cost Of Book : ";
cin>>cost;
}
void show();
};
void derivedclass :: show()
{
cout<<endl<<"---------- Details Of The Book ----------";
cout<<endl<<" Accession Number : "<<acc;
cout<<endl<<" Author Name : "<<name;
cout<<endl<<" Title Of The Book : "<<title;
cout<<endl<<" Year Of Publication : "<<year;
cout<<endl<<" Publisher Name : "<<pname;
cout<<endl<<" Cost Of Book : "<<cost;
}
void main()
{
clrscr();
derivedclass d;
d.enter1();
d.enter2();
d.enter3();
d.show();
getch();
}
OUTPUT
#include<iostream.h>
#include<conio.h>
class baseclass
{
protected:
char name[20],gender[10];
int age;
public:
void enter1()
{
cout<<" Enter The Name Of The Patient : ";
cin>>name;
cout<<" Enter The Gender Of The Patient : ";
cin>>gender;
cout<<" Enter The Age Of The Patient : ";
cin>>age;
}
};
class derivedclass1 : public baseclass
{
protected:
int bedno;
char nature[50];
public:
void enter2()
{
cout<<" Enter The Bed Number Of The Patient : ";
cin>>bedno;
cout<<" Enter The Nature Of Illnes Of The Patient : ";
cin>>nature;
}
};
class derivedclass2 : public derivedclass1
{
protected:
int date;
public:
void enter3()
{
cout<<" Enter The Date Of Admission Of The Patient : ";
cin>>date;
}
void show();
};
void derivedclass2::show()
{
cout<<endl<<"---------- DETAIL OF THE PATIENT ----------";
cout<<endl<<" Name : "<<name;
cout<<endl<<" Gender : "<<gender;
cout<<endl<<" Age : "<<age;
cout<<endl<<" Bed Number : "<<bedno;
cout<<endl<<" Nature Of Illness : "<<nature;
cout<<endl<<" Date Of Admission : "<<date;
}
void main()
{
clrscr();
derivedclass2 d2;
d2.enter1();
d2.enter2();
d2.enter3();
d2.show();
getch();
}
OUTPUT
OUTPUT
#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int r, c, a[100][100], b[100][100], sum[100][100], i, j;
cout << endl << "Enter elements of 1st matrix: " << endl;
OUTPUT
17. Write a program in C++ to implement stack using array.
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define MAX_SIZE 5
class Stack {
private:
int item, i;
int arr_stack[MAX_SIZE];
int top;
public:
Stack() {
top = 0;
void push() {
if (top == MAX_SIZE)
cout << "\n## Stack is Full!";
else {
cout << "\nEnter The Value to be pushed : ";
cin>>item;
cout << "\n## Position : " << top << ", Pushed Value :" << item;
arr_stack[top++] = item;
}
}
void pop() {
if (top == 0)
cout << "\n## Stack is Empty!";
else {
--top;
cout << "\n## Position : " << top << ", Popped Value :" << arr_stack[top];
}
}
void display()
{
cout << "\n## Stack Size : " << top;
for (i = (top - 1); i >= 0; i--)
cout << "\n## Position : " << i << ", Value :" << arr_stack[i];
}
};
int main()
{
clrscr();
int choice, exit_p = 1;
Stack obj;
do {
cout << "\n\nStack Main Menu";
return 0;
}
{
clrscr();
int item, choice, i;
int arr_queue[MAX_SIZE];
int rear = 0;
int front = 0;
int exit = 1;
do {
cout << "\nQueue Main Menu";
return 0;
}
OUTPUT
OUTPUT