BCA202 - LAB Manual PDF
BCA202 - LAB Manual PDF
LAB MANUAL
Start programs Microsoft Visual Studio 6.0 Microsoft Visual C++ 6.0
OR
1. Bulid Compile.cpp
2. select compile icon from the menu bar or
3. press CTRL + F7
3-press CTRL + F5
() small brackets
, comma
; semicolon
Objectives:
#include<iostream.h> //PREPROCESSOR
{ // is comment
cout<<"WELCOME TO C++"<<endl;
#include<iostream.h>
void main( )
int a;
float b;
char c;
cout<<"ENTER AN INTEGER"<<endl;
cin>>a;
cout<<"ENTER A FLOAT"<<endl;
cin>>b;
cout<<"ENTER A CHARECTER"<<endl;
cin>>c;
#include<iostream.h>
void main( )
float a,b;
float sum,avg;
cin>>a>>b;
sum = a + b;
avg = sum/2;
#include<iostream.h>
void main( )
folat a,b,c;
float sum,avg;
cin>>a>>b>>C;
sum = a + b + c;
Exercises:
Objectives:
#include<iostream.h>
void main( )
folat r,area;
cin>>r;
area = pi*r*r;
#include<iostream.h>
void main( )
cin>>len;
cin>>wid;
area = len*wid;
#include<iostream.h>
void main( )
cin>>len;
area = side*side;
#include<iostream.h>
void main ()
double GSal,NSal,ded,basic,da;
cin>>basic;
cin>>ded;
GSal=basic+da+Housing+TA;
NSal=GSal-ded;
cout<<"\t\t\t\tBasic :\t"<<basic<<endl;
cout<<"\t\t\t\tDA :\t"<<da<<endl;
cout<<"\t\t\t\tHousing :\t"<<Housing<<endl;
cout<<"\t\t\t\tTravelling :\t"<<TA<<endl;
cout<<"\t\t\t\tDeduction :\t"<<ded<<endl;
Exercises:
1. Write a C++ program to find the volume of Cylinder.
Objectives:
#include<iostream.h>
void main()
int a,b;
cin>>a>>b;
if(a>b)
else
#include<iostream.h>
void main()
int num;
cout<<"Enter a number\n";
cin>>num;
if(num%2==0)
else
#include<iostream.h>
void main()
{
int mark;
char grade;
cout<<"Enter mark";
cin >> mark;
if(mark >= 90 && mark <= 100 )
grade='A';
if(mark >= 80 && mark <= 89 )
grade='B';
if(mark >= 70 && mark <= 79 )
grade='C';
if(mark >= 60 && mark <= 69 )
grade='D';
if(mark < 60 )
grade='F';
cout<<"Mark"<<"\t"<<"Grade"<<endl;
cout<<mark<<"\t"<<grade<<endl;
Exercises:
1. Write a C++ program to find the largest among three numbers.
2. Write a C++ program to find whether the given number is Armstrong number or not.
3. Write a C++ program to find whether the given number is palindrome or not.
Objectives:
#include<iostream.h>
void main()
int x;
cout<<"Enter number"<<endl;
cin>>x;
switch(x)
case 1:
cout<<"Saturday"<<endl;
break;
case 2:
cout<<"Sunday"<<endl;
break;
case 3:
cout<<"Monday"<<endl;
break;
case 4:
cout<<"Tuesday"<<endl;
break;
case 5:
cout<<"Wednesday"<<endl;
break;
cout<<"Thursday"<<endl;
break;
case 7:
cout<<"Friday"<<endl;
break;
default:
cout<<"Error"<<endl;
#include<iostream.h>
void main()
int m;
cin>>m;
switch(m)
case 1:cout<<"JAN";break;
case 2:cout<<"FEB";break;
case 3:cout<<"MAR";break;
case 4:cout<<"APR";break;
case 5:cout<<"MAY";break;
case 6:cout<<"JUN";break;
case 7:cout<<"JUL";break;
case 9:cout<<"SEP";break;
case 10:cout<<"OCT";break;
case 11:cout<<"NOV";break;
case 12:cout<<"DEC";break;
default:cout<<"ERROR";
#include<iostream.h>
void main()
{
int n1, n2;
char op;
cout<<"Enter first number"; cin >> n1;
cout<<"Enter second number"; cin >> n2;
cout<<"Enter operator(*, /, + -)"; cin >> op;
switch (op)
{
case '*':
cout<<n1<<op<<n2<<"="<<(n1*n2)<<endl;
break;
case '/':
cout<<n1<<op<<n2<<"="<<(n1/n2)<<endl;
break;
case '+':
cout<<n1<<op<<n2<<"="<<(n1+n2)<<endl;
break;
case '-':
cout<<n1<<op<<n2<<"="<<(n1-n2)<<endl;
break;
default:
cout<<"Invalid oprator"<<endl;
break;
} }
Exercises: Write a menu driven program to calculate different currency conversions.
Objectives:
#include <iostream.h>
void main()
int i;
for (i=0;i<=30;i++)
cout<<" "<<"i=";
cout<<i<<endl;
#include<iostream.h>
void main()
int a=1;
while(a<=30)
cout<<a<<endl;
#include<iostream.h>
void main()
int a=1;
do
cout<<a<<endl;
a++;
while(a<=30);
#include<iostream.h>
void main()
int n,i=1,fact=1;
cin>>n;
if(n>=0)
do
fact=fact*i;
i++;
while(i<=n);
cout<<"fact="<<fact<<"\n";
}}
Exercises:
1. Write a C++ program to generate Fibonacci numbers up to 100 using for loop.
2. Write a C++ program to generate multiplication table of any number using while loop.
3. Write a C++ program to print all prime numbers between two limits by using do while
loop.
Objectives:
#include <iostream.h>
void main()
int i,j,k,n,m;
cout<<"Enter a number";
cin>>n;
m=n;
for(i=0;i<n;i++) // * * *
{ // * *
for(j=0;j<i;j++) // *
cout<<" ";
for(k=0;k<m;k++)
cout<<" *";
cout<<endl;
m--;
Exercises:
1. Write a C++ program to display Pascal’s triangle
Objectives:
#include<iostream.h>
void main()
int a[5],i;
for(i=0;i<5;i++)
cin>>a[i];
for(i=0;i<5;i++)
cout<<a[i]<<endl;
// Program 23 Program to store 5 numbers in an array then print them in reverse order
#include<iostream.h>
void main()
int a[5],i;
cin>>a[i];
cout<<a[i]<<endl;
// Program 24 program using arrays for checking Maximum Number and Minimum number among
elements
#include <iostream.h>
void main()
int a[8],i,max,min;
cout<<"Enter 8 number:"<<endl;
for(i=0;i<8;i++)
cin>>a[i];
max=min=a[0];
for(i=0;i<8;i++)
{ if (a[i]>max)
max=a[i];
min=a[i];
cout<<"Maximum number="<<max<<endl;
cout<<"Minimum number="<<min<<endl;
// Program 25 to input data into two different arrays and then add two arrays and store result in
third Array
#include<iostream.h>
main()
float a[5],b[5],s[5];
int i;
for (i=0;i<=4;i++)
cin>>a[i];
for (i=0;i<=4;i++)
cin>>b[i];
for(i=0;i<=4;i++)
s[i]=a[i]+b[i];
// Program 26 Write a program to read some values into array and sort them using bubble sort.
#include<iostream.h>
void main()
int x[10],i,n,j;
cout<<"enter count";
cin>>n;
for(i=0;i<n;i++)
cin>>x[i];
for(i=0;i<(n-1);i++)
for(j=i+1;j<n;j++)
if (x[i]>x[j])
int temp=x[i];
x[j]=temp;
for(i=0;i<n;i++)
cout<<x[i]<<"\n";
Exercises:
1. Write a C++ program to search an element by using binary search.
Objectives:
#include <iostream.h>
void main()
int a, b;
cin>>a;
cin>>b;
add(a,b);
int res;
res = x+y;
return res;
#include<iostream.h>
int sq(int);
void main()
int x;
cin>>x;
int sq(int x)
return x*x;
#include<iostream.h>
int fact(int);
void main()
int x,f;
cin>>x;
f=fact(x);
int fact(int a)
int i,f=1;
for(i=1;i<=a;i++)
f=f*i;
return f;
Exercises:
1. Write a C++ program to interchange two numbers by using function.
Objectives:
#include<iostream.h>
#include<fstream.h>
#include<iomanip.h>
#include<stdlib.h>
void main()
ifstream student("marks.dat",ios::in);
if (!student)
exit(1);
int account;
char name[40];
double balance;
cout<<"account"<<setw(10)<<"name"<<setw(10)<<"balance"<<endl;
while(student>>account>>name>>balance)
cout<<account<<setw(15)<<name<<setw(10)<<balance<<endl;
}//end of main
Exercise:
1. Write a C++ program to create a file and store the details of a student.
LAB: 10
Objectives:
// Program 31 Create class student read and show the details by using scope resolution operator
#include<iostream.h>
class student
int id,m1,m2,m3,tot;
char sname[10];
float avg;
public:
void read();
void show();
};
void student::read()
cin>>id>>sname>>m1>>m2>>m3;
void student::show()
tot=m1+m2+m3;
avg=tot/3;
void main()
student st;
st.read();
st.show();
// Program 32 Create class student read and show the details without scope resolution operator
#include<iostream.h>
class student
int id,m1,m2,m3,tot;
char sname[10];
float avg;
public:
void read()
cin>>id>>sname>>m1>>m2>>m3;
void show()
tot=m1+m2+m3;
avg=tot/3;
};
void main()
student st;
st.read();
st.show();
// Program 33 Create class result read, total and show the details by using scope resolution
operator
#include<iostream.h>
class result
int id,m1,m2,m3,tot;
char sname[10];
public:
void read();
void total();
void show();
};
void result::read()
cin>>id>>sname>>m1>>m2>>m3;
void result::total()
tot=m1+m2+m3;
void result::show()
result st;
st.read();
st.total();
st.show();
// Program 34 Create class result read, total and show the details without scope resolution operator
#include<iostream.h>
class result
int id,m1,m2,m3,tot;
char sname[10];
public:
void read()
cin>>id>>sname>>m1>>m2>>m3;
void total()
tot=m1+m2+m3;
void show()
};
void main()
result st;
st.read();
st.total();
st.show();
// Program 35 Create class employee read and show the details by using scope resolution operator
#include<iostream.h>
class employee
int eno,sal;
char ename[10];
public:
void accept();
void disp();
void employee::accept()
cin>>eno>>ename>>sal;
void employee::disp()
cout<<eno<<"\n"<<ename<<"\n"<<sal;
void main()
employee e;
e.accept();
e.disp();
// Program 36 Create class employee read and show the details without scope resolution operator
#include<iostream.h>
class employee
int eno,sal;
public:
void accept()
cin>>eno>>ename>>sal;
void disp()
cout<<eno<<"\n"<<ename<<"\n"<<sal;
};
void main()
employee e;
e.accept();
e.disp();
Exercises:
1. Create class item read and display the details of an item by using class.
LAB: 11
Revision
--------------------**************************----------------------------**************-------------------------