0% found this document useful (0 votes)
66 views

Crush CPP

The document lists 25 C++ programming practical problems involving classes and objects including calculating positive/negative numbers, area of shapes, swapping values, pattern printing, bank account operations, constructors, destructors, inheritance, and operator overloading.

Uploaded by

aadityarakhade
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views

Crush CPP

The document lists 25 C++ programming practical problems involving classes and objects including calculating positive/negative numbers, area of shapes, swapping values, pattern printing, bank account operations, constructors, destructors, inheritance, and operator overloading.

Uploaded by

aadityarakhade
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

BCA 1styear(2nd Sem) 2023-24

C++ Practical List


1. Write an algorithm, draw a flowchart and Write a
program in c++to find weather given number is
positive or negative using Class and Object.
2. Write an algorithm, draw a flowchart and Write a
program in c++ to find area of
traiangle,rectangle,circle and square using class and
object.
3. Write an algorithm, draw a flowchart and Write a
program in c++to find weather entered character is
vowel or not using Class and Object.
4. Write an algorithm, draw a flowchart and Write a
program in c++ to perform swapping between two
numbers without using temporary variable using
Class and Object.
5. Write an algorithm, draw a flowchart and Write a
program in c++ to perform swapping between two
numbers with using temporary variable using Class
and Object
6. Write an algorithm, draw a flowchart and write a
program to print the following pattern.
**
****
******
********
7. Write an algorithm, draw a flowchart and Write
program in C++ to implement Bank account Class
8. Write an algorithm,draw a flowchart and In a bank
,N depositors deposit the amount,write a program to
find total amount deposited in the bank declare a
class deposit with private data member rupee and
paisa containing member function getdata,putdata.
9. Write an algorithm, draw a flowchart and Write
program in C++ to demonstrate uses of a Constructor
and Destructor.
10. Write an algorithm, draw a flowchart and Write
program in C++ to demonstrate uses of constructors
11. Write an algorithm,draw a flowchart and write
program to accept the distance between city 1st &
2nd ,city 2nd & 3rd
12. Write an algorithm, draw a flowchart and write a
program in c++to Demonstrate the use of operator
overloading .
13. Write an algorithm, draw a flowchart and write a
program in c++ to Declare class event, accept time of
first event and second event and find the difference
between 1st and 2nd event. Use operator ‘-
‘overloading.
14. Write an algorithm,draw a flowchart and write a
program in c++ to search an element from an array
using class.
15. Write an algorithm, draw a flowchart and write a
program in c++ to Demonstrate the use of
overloading unary operators: increment (++) and
decrement (--).
16. Write an algorithm, draw a flowchart and write a
program in c++ to insert an element in given position.
17. Write an algorithm, draw a flowchart and write a
program in c++ to delete an element from given
position

18. Write an algorithm, draw a flowchart and write a


program in c++arrange elements in ascending order.
19. Write an algorithm, draw a flowchart and write
a program in c++to arrange element in descending
order
20. Write an algorithm, draw a flowchart and write a
program in c++ to demonstrate Single Inheritance.
21. Write an algorithm, draw a flowchart and write a
program in c++ to demonstrate Multiple Inheritance.
22. Write an algorithm, draw a flowchart and write a
program in c++ to demonstrate Multilevel
Inheritance.
23. Write an algorithm, draw a flowchart and write a
program in c++ to demonstrate hierarchical
inheritance.
24. Write an algorithm, draw a flowchart and write a
program in c++ to demonstrate usage of normal
virtual function and pure virtual Function with
abstract class.
25. Write an algorithm, draw a flowchart and write
a program in c++ to illustrate use of inline function
PROGRAMS
PRACTICAL – 1
#include<iostream.h>
#include<conio.h>
class check
{
public:
int posnev()
{
int num;
cout<<"Enter the number:";
cin>>num;
if(num==0)
cout<<"Entered number is zero";
else if(num>0)
cout<<"Entered number is positive";
else
cout<<"Entered number is negative";
return 0;
}
};
void main()
{
clrscr();
check c;
c.posnev();
getch();
}

PRACTICAL – 2
#include<iostream.h>
#include<conio.h>
class area
{
public:
int area1,area2,area3,area4,l,b,r,s,h;
void rectangle()
{
cout<<"Enter the leangth and breath:";
cin>>l>>b;
area1=l*b;
cout<<"area of rectangle:"<<area1<<endl;
cout<<"Enter the radius and radius:";
cin>>r>>r;
area2=r*r*3.14;
cout<<"area of circle:"<<area2<<endl;
cout<<"Enter the height and base:";
cin>>h>>b;
area3=h*b;
cout<<"area of triangle:"<<area3<<endl;
cout<<"Enter the side:";
cin>>s;
area4=s*s;
cout<<"area of square:"<<area4<<endl;
}
};
void main()
{
clrscr();
area a;
a.rectangle();
getch();
}

PRACTICAL – 3
#include<iostream.h>
#include<conio.h>
class swap
{
int a,b;
int swapfun()
{
cout<<"Enter the value of a and b:";
cin>>a>>b;
cout<<"Before swapping,a="<<a;
cout<<"Before swapping,b="<<b;
a=a+b;
b=a-b;
a=a-b;
cout<<"After swapping,a="<<a;
cout<<"After swapping,b="<<b;
return 0;
}
};
void main()
{
clrscr();
swap obj;
obj.swapfun();
getch();
}
PRACTICAL – 4
#include<iostream.h>
#include<conio.h>
class swap
{
public:
int a,b;
int swapfun()
{
cout<<"Enter the value of a and b:";
cin>>a>>b;
cout<<"Before swapping,a="<<a<<endl;
cout<<"Before swapping,b="<<b<<endl;
a=a+b;
b=a-b;
a=a-b;
cout<<"\n After swapping,a="<<a<<endl;
cout<<"\n After swapping,b="<<b<<endl;
return 0;
}
};
void main()
{
clrscr();
swap obj;
obj.swapfun();
getch();
}
PRACTICAL – 5
#include<iostream.h>
#include<conio.h>
class swap
{
public:
int a,b,temp;
int swapfun()
{
cout<<"Enter the value of a and b:";
cin>>a>>b;
cout<<"\n Before swapping,a="<<a;
cout<<"\n Before swapping,b="<<b;
temp=a;
a=b;
b=temp;
cout<<"\n After swapping,a="<<a;
cout<<"\n After swapping,b="<<b;
return 0;
}
};
void main()
{
clrscr();
swap s;
s.swapfun();
getch();
}
PRACTICAL – 6
#include<iostream.h>
#include<conio.h>
class pattern
{
public:
int row;
int print()
{
cout<<"Enter the value of row:";
cin>>row;
for(int i=1; i<row; i++)
{
for(int j=1; j<=i; j++)
{
cout<<"*";
}
cout<<"\n";
}
return 0;
}
};
void main()
{
clrscr();
pattern p;
p.print();
getch();
}
PRACTICAL – 7
#include<iostream.h>
#include<conio.h>
class BankAccount
{
int acno;
float balance;
char actype[4];
public:
void store();
void deposit();
void withdraw();
void display();
};
void BankAccount::store()
{
cout<<"Enter account number:"<<endl;
cin>>acno;
cout<<"Enter the account type:CURR/SAVG/FD:"<<endl;
cin>>actype;
cout<<"Enter the current amount available:"<<endl;
cin>>balance;
}
void BankAccount::deposit()
{
float more;
cout<<"Enter the amount to deposit:";
cin>>more;
balance=balance+more;
}
void BankAccount::withdraw()
{
float amt;
cout<<"Enter the amount to withdraw:"<<endl;
cin>>amt;
balance=balance-amt;
}
void BankAccount::display()
{
cout<<"Account Details:"<<endl;
cout<<"Account Number:"<<acno<<endl;
cout<<"Account Type:"<<actype<<endl;
cout<<"Balance:RS"<<balance;
}
int main()
{
BankAccount b;
clrscr();
b.store();
b.deposit();
b.withdraw();
b.display();
getch();
return 0;
}
PRACTICAL – 8
#include<iostream.h>
#include<conio.h>
class deposit
{
private:
float rupee,paisa,bal,total;
public:
};
void deposit::getdata()
{
cout<<"Enter the value of rupee:";
cin>>rupee;
cout<<"Enter the value of paisa:";
cin>>paisa;
}
int deposit::putdata()
{
bal=0;
total=bal+rupee+(paisa/100);
cout<<"Total deposit="<<total<<endl;
return 0;
}
void main()
{
clrscr();
int i,n;
cout<<"\n input how many deposit:";
cin>>n;
deposit d[10];
for(i=0;i<n;i++)
{
d[i].getdata();
d[i].putdata();
}
getch();
}

PRACTICAL – 9
#include<iostream.h>
#include<conio.h>
int count=0;
class alpha
{
public:
alpha()
{
count ++;
cout<<"\n Number of object created:"<<count;
}
~alpha()
{
cout<<"\n Number of object destroyed:"<<count;
count --;
}
};
void main()
{
clrscr();
cout<<"\n \n Enter main \n";
alpha A1,A2,A3,A4;
{
cout<<"\n \n Enter block 1 \n";
alpha A5;
}
{
cout<<"\n \n Enter block 2 \n";
alpha A6;
}
cout<<"\n \n Re-Enter main \n";
getch();
}
PRACTICAL – 10
#include<iostream.h>
#include<conio.h>
class check
{
public:
int posnev()
{
int num;
cout<<"Enter the number:";
cin>>num;
if(num==0)
cout<<"Entered number is zero";
else if(num>0)
cout<<"Entered number is positive";
else
cout<<"Entered number is negative";
return 0;
}
};
void main()
{
clrscr();
check c;
c.posnev();
getch();
}
PRACTICAL – 11
#include<iostream.h>
#include<conio.h>
class road
{
private:
long d1,d2,d3;
float km,m;
public:
void getdata();
void calculate();
void display();
};
void road::getdata()
{
cout<<"Enter distance between 1st & 2nd city:";
cin>>d1;
cout<<"Enter distance between 2nd & 3rd city:";
cin>>d2;
}
void road::calculate()
{
d3=d1+d2;
km=(d3*1.0)/1000;
m=d3%1000;
}
void road::display()
{
cout<<"The distance between 1st & 3rd city:"<<d3<<"\n";
cout<<"Distance between 1st & 3rd city in kilometer:"<<km<<"\n";
cout<<"Distance between 1st & 3rd city in meter:"<<m<<"\n";
}
void main()
{
clrscr();
road r;
r.getdata();
r.calculate();
r.display();
getch();
}
PRACTICAL – 12
#include<iostream.h>
#include<conio.h>
#include<string.h>
struct string
{
char str[20];
};
string operator+(string,string);
int main()
{
clrscr();
string str1,str2,str3;
cout<<"Input any string=>";
cin>>str1.str;
cout<<"Input any string=>";
cin>>str2.str;
str3=str1+str2;
cout<<"\n After concatenating string is:"<<str3.str;
getch();
}
string operator+(string s1,string s2)
{
string s3;
strcpy(s3.str,s1.str);
strcat(s3.str,s2.str);
return s3;
}
PRACTICAL – 13
#include<iostream.h>
#include<conio.h>
class event
{
private:
int sec,min,hr,total;
public:
event()
{
sec=0;
min=0;
hr=0;
}
void getdata();
void display();
event operator-(event e);
};
void event::getdata()
{
cout<<"\n Enter the time of event in hours,minute and second:";
cin>>hr>>min>>sec;
total=(3600*hr)+(60*min)+sec;
}
void event::display()
{
cout<<"\n hours="<<hr;
cout<<"\n minute="<<min;
cout<<"\n second="<<sec;
}
event event::operator-(event e)
{
event t;
t.total=e.total-total;
t.hr=t.total/(3600);
t.min=(t.total%3600)/60;
t.sec=(t.total%3600)%60;
return (t);
}
void main()
{
clrscr();
event e.e1,e2,e3;
e1.getdata();
e2.getdata();
cout<<"\n First event";
e1.display();
cout<<"\n Second event";
e2.display();
e3=e2-e1;
cout<<"\n Difference between 1st & 2nd event";
e3.display();
getch();
}
PRACTICAL – 14
#include<iostream.h>
#include<conio.h>
class search
{
public:
int a[10],i,n,ele;
void get_data();
void search_data();
void put_data();
};
void search::get_data()
{
clrscr();
cout<<"Enter the element in an array:";
cin>>n;
cout<<"Enter the element in an array:";
for(i=0;i<n;i++)
{
cin>>a[i];
}
}
void search::put_data()
{
cout<<"\n The element of the array are:";
for(i=0;i<n;i++)
{
cout<<"\t"<<a[i];
}
}
void search::search_data()
{
cout<<"\n Enter the element to be searched:";
cin>>ele;
for(i=0;i<n;i++)
{
if(a[i]==ele)
cout<<"The element is found at"<<(i+1)<<"location";
break;
}
}
if(i==n)
{
cout<<"\n The element is not found";
}
}
void main()
{
search s;
s.get_data();
s.put_data();
s.search_data();
getch();
}
PRACTICAL – 15
#include<iostream.h>
#include<conio.h>
class IncreDecre
{
int a,b;
public:
void accept()
{
cout<<"\n Enter two numbers:";
cout<<" ";
cin>>a;
cout<<" ";
cin>>b;
}
void operator--()
{
a--;
b--;
}
void operator++()
{
a++;
b++;
}
void display()
{
cout<<"|n A:"<<a;
cout<<"\n B:"<<b;
}
};
int main()
{
IncreDecre id;
id.accept();
--id;
cout<<"\n After Decrementing:";
id.display();
++id;
++id;
cout<<"\n\n After Incrementing:";
id.display();
return 0;}
PRACTICAL – 16
#include<iostream.h>
#include<process.h>
#include<iomanip.h>
#include<conio.h>
void main()
{
int a[10],i,n,num,pos;
clrscr();
cout<<"Enter the size of an array:"<<endl;
cin>>n;
cout<<"Enter"<<n<<"Elements"<<endl;
for(i=1;i<n;i++)
cin>>a[i];
cout<<"Array before insention"<<endl;
for(i=1;i<n;i++)
cout<<a[i]<<"\t";
cout<<endl<<"Enter element to insert element:"<<endl;
cin>>pos;
for(i=n+1,i>pos;i--)
a[i]=a[i-1];
a[pos]=num;
cout<<"Array after insertion"<<endl;
for(i=1;i<n;i++)
cout<<a[i]<<"\t";
getch();
}
PRACTICAL – 17
#include<iostream.h>
#include<process.h>
#include<conio.h>
void main()
{
int a[10],i,n,pos;
clrscr();
cout<<"Enter size of an array:"<<endl;
cin>>n;
cout<<"Enter"<<n<<"Element"<<endl;
for(i=1;i<n;i++)
cin>>a[i];
cout<<"Array before deletion:"<<endl;
for(i=1;i<=n;i++)
cout<<a[i]<<"\t";
cout<<"Enter position of element to delete from array";
cin>>pos;
if(pos>n)
{
cout<<"cannot delete from array";
exit(0);
}
for(i=pos;i<n;i++)
a[i]=a[i+1];
cout<<"Array after deletion"<<endl;
for(i=1;i<n;i++)
cout<<a[i]<<"\t";
getch();
}
PRACTICAL – 18
#include<iostream.h>
#include<process.h>
#include<conio.h>
#include<iomanip.h>
void main()
{
int n,i,j;
int a[50];
clrscr();
cout<<"\n Enter the range of array:";
cin>>n;
cout<<"\n Enter the element of array:";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"\n original array is:";
for(i=0;i<n;i++)
{
cout<<"setw(s)"<<a[i];
}
for(i=0;i<n;i++)
{
for(j=0;j<n-1;j++)
{
if(a[j]>=a[j+1])
{
int t;
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
cout<<"\n \n Array in ascending order is:";
for(i=0;i<n;i++)
{
cout<<"setw(s)"<<a[i];
}
cout<<"\n\n";
getch();
}
PRACTICAL – 19
#include<iostream.h>
#include<process.h>
#include<iomanip.h>
#include<conio.h>
void main()
{
int n,i,j;
int a[50];
clrscr();
cout<<"\n Enter the range of array:";
cin>>n;
cout<<"\n Enter the element of an array:";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"\n Original array is:";
for(i=0;i<n;i++)
{
cout<<"setw(s)"<<a[i];
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(a[j]<=a[j+1])
{
int t;
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
cout<<"\n\nArray in decreasing order is:";
{
cout<<"setw(s)"<<a[i];
}
cout<<"\n\n";
getch();
}
PRACTICAL – 20
#include<iostream.h>
#include<conio.h>
class B
{
private:
int a;
public:
int b;
void get_ab()
{
a=5;
b=22;
}
int get_a()
{
return (a);
}
void show_a()
{
cout<<"\n a="<<a;
}
};
class D:public B
{
int c;
public:
void mul()
{
c=get_a()*b;
}
void display()
{
cout<<"\n\n a="<<get_a();
cout<<"\n\n b="<<b;
cout<<"\n\n multiplication is="<<c;
}
};
void main()
{
clrscr();
D m;
m.get_ab()
m.mul();
m.show_a();
m.display();
m.b=20;
m.mul();
m.display();
getch();
}
PRACTICAL – 21
#include<iostream.h>
#include<conio.h>
class M
{
protected:
int m;
public:
void get_m()
{
cout<<"\n Enter value of m:";
cin>>m;
}
};
class N
{
protected:
int n;
public:
void get_n()
{
cout<<"\n Enter value of n:";
cin>>n;
}
};
class P:public M,public N
{
public:
int c;
void display()
{
c=m+n;
cout<<"\n\n m="<<m;
cout<<"\n\n n="<<n;
cout<<"\n Addition is="<<c;
}
};
void main()
{
P z;
clrscr();
z.get_m();
z.get_n();
z.display();
getch();
}
PRACTICAL – 22
#include<iostream.h>
#include<conio.h>
class student
{
protected:
long roll_number;
public:
get_number()
{
cout<<"\n Enter the roll no of student:";
cin>>roll_number;
}
put_number()
{
cout<<"\n roll="<<roll_number;
}
};
class test:public student
{
protected:
long sub1,sub2;
public:
void get_marks()
{
cout<<"\n Enter marks of sub1 & sub2:";
cin>>sub1>>sub2;
}
put_marks()
{
cout<<"\n sub1="<<sub1<<"\n sub2="<<sub2;
}
};
class result:public test
{
long total;
public:
display()
{
put_number();
put_marks();
total=sub1+sub2;
cout<<"\n total marks="<<total;
}
};
void main()
{
clrscr();
result r;
r.get_number();
r.get_marks();
r.display();
getch();
}
PRACTICAL – 23
#include<iostream.h>
#include<conio.h>
class side
{
protected:
int c;
public:
int a;
void set_values()
{
cout<<"\n ENtre the value of a=";
cin>>a;
}
};
class square:public side
{
public:
void sq()
{
int sq=a*a;
cout<<"\n Square="<<sq;
}
};
class cube:public side
{
public:
void cub()
{
int cub=a*a*a;
cout<<"\n Cube="<<cub;
}
};
void main()
{
square s;
clrscr();
s.set_values();
s.sq();
cube c;
c.set_values();
c.cub();
getch();}
PRACTICAL – 24
#include<iostream.h>
#include<conio.h>
class test
{
public:
virtual void display()=0;
virtual void show(){};
};
class derived:public test
{
public:
void show()
{
cout<<"\n I am in test class"<<endl;
}
void display()
{
cout<<"\n This is pure virtual function"<<endl;
}
};
void main()
{
clrscr();
test*t;
derived d;
t=&d;
t->show();
t->display();
getch();
}
PRACTICAL – 25
#include<iostream.h>
#include<conio.h>
class line
{
public:
inline float mul(float x,float y)
{
return(x*y);
}
inline float cube(float x)
{
return(x*x*x);
}
};
void main()
{
line l1;
float val1,val2;
clrscr();
cout<<"Enter two value=";
cin>>val1>>val2;
cout<<"Multiplication:"<<l1.mul(val1,val2);
cout<<"\n Cube:"<<l1.cube(val1)<<"\t<<l1.cube(val2)";
getch();
}

END

You might also like