BCSL 032 Solved Assignments 2016
BCSL 032 Solved Assignments 2016
www.pixelesindia.com
PIXELES CLASSES BCA & MCA (IGNOU)
}
(b) Write a C++ program to create class named Account to perform basic operations on a saving bank
account. Make necessary assumptions wherever required.
(10 Marks)
Ans:
#include<iostream.h>
#include<conio.h>
#include<string.h>
class account
{
public:
int ac;
char type;
char cname[20];
float bal,d,w;
www.pixelesindia.com
PIXELES CLASSES BCA & MCA (IGNOU)
account(int a,char b[],float c)
{
ac=a;
strcpy(cname,b);
bal=c;
} PIXELES Classes
void deposit(); Page | 3
void widthdraw();
void disp();
};
class saving:public account
{
int rate;
char type;
public:
saving(int x, char y[],float z, char t,int r):account(x,y,z)
{
rate=r;
type=t;
}
void deposit();
void withdraw();
void disp();
};
void saving::deposit()
{
cout<<"Enter deposit amount";
cin>>d;
bal=bal+d;
}
void saving::withdraw()
{
cout<<"Enter withdraw amount";
cin>>w;
bal=bal-w;
}
void saving::disp()
{
cout<<"\n*****Your details*****\n";
cout<<"\nAccount NUmber="<<ac;
cout<<"\nCustomer Name="<<cname;
cout<<"\nNew Balance="<<bal;
cout<<"\n Account type="<<type;
cout<<"\n Rate of interest="<<rate;
}
class current:public account
www.pixelesindia.com
PIXELES CLASSES BCA & MCA (IGNOU)
{
int rate;
char type;
int overdraft;
public:
current(int x, char y[],float z, char t,int r,int p):account(x,y,z) PIXELES Classes
{ Page | 4
rate=r;
type=t;
overdraft=p;
}
void deposit();
void withdraw();
void disp();
};
void current::deposit()
{
cout<<"Enter deposit amount";
cin>>d;
bal=bal+d;
}
void current::withdraw()
{
cout<<"Enter withdraw amount";
cin>>w;
bal=bal-w;
}
void current::disp()
{
cout<<"\n*****Your details*****\n";
cout<<"\nAccount NUmber="<<ac;
cout<<"\nCustomer Name="<<cname;
cout<<"\nNew Balance="<<bal;
cout<<"\n Account type="<<type;
cout<<"\n Rate of interest="<<rate;
cout<<"\n Overdraft Limit="<<overdraft;
}
void main()
{
int ch,c;
clrscr();
cout<<"Input your account type(0-saving,1-current)";
cin>>ch;
if(ch==0)
{
www.pixelesindia.com
PIXELES CLASSES BCA & MCA (IGNOU)
saving *ob=new saving(10,"Ashu",1000.00,'s',4);
ob->disp();
cout<<"\n(select 0-for deposit, 1-for withdraw)\n";
cin>>c;
if(c==0)
ob->deposit(); PIXELES Classes
else if(c==1) Page | 5
ob->withdraw();
ob->disp();
}
else if(ch==1)
{
current *ob=new current(10,"Ashu",1000.00,'s',4,25000);
ob->disp();
cout<<"\ninput 0-for deposit, 1-for withdraw\n";
cin>>c;
if(c==0)
ob->deposit();
else if(c==1)
ob->withdraw();
ob->disp();
}
getch();
}
2.
(a) Write a C++ program to demonstrate exception handling by using matrix multiplication operation.
Matrix multiplication function should notify if the order of the matrix is invalid, using exception.
(10 Marks)
ANs:
#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<exception.h>
void matsum()
{
int m, n, i, j, first[10][10], second[10][10], sum[10][10];
try
{
www.pixelesindia.com
PIXELES CLASSES BCA & MCA (IGNOU)
cout << "Enter the number of rows and columns of matrix ";
cin >> m >> n;
cout << "Enter the elements of first matrix\n";
if (m>10 || n>10)
//exit(0);
PIXELES Classes
throw 1;
Page | 6
}
catch(int)
{
Disclaimer: This Assignment is prepared by Our Students.
cout<<"subscript invalid";
Institution and publisher are neither responsible for the result of the
} any action taken on the basis of this work or any omissions or errors.
}
void main()
{
matsum();
getch();
www.pixelesindia.com
PIXELES CLASSES BCA & MCA (IGNOU)
}
(b) Write C++ program for Addition of two complex numbers by overloading „+‟ operator. Make
necessary assumptions wherever
required.
#include<iostream.h>
PIXELES Classes
#include<conio.h>
class complex Branches & Contacts Details Page | 7
{
int real,imaginary; Uttam Nagar:-WZ-B7, Old Pankha Nangloi:-Plot. No-19, Ext- 2A,
oppBanke-Bihari, Talabwali Road,
public: Road (Opp. Primary School), Near
Nangloi, Delhi-41
complex() East Metro Station, Uttam Nagar,
{ New Delhi-59
}
complex(int a,int b)
{
Ph: 9213327975, 9716339580
real=a; 8750321695
imaginary=b; [email protected], web: www.pixelesindia.com
}
void operator+(complex);
};
void complex::operator+(complex c)
{
complex temp;
temp.real=real+c.real;
temp.imaginary=imaginary+c.imaginary;
cout<<"real sum is:"<<temp.real<<endl;
}
void main()
{
clrscr();
complex c1(10,20);
complex c2(20,30);
c1+c2;
getch();
}
www.pixelesindia.com