0% found this document useful (0 votes)
58 views7 pages

BCSL 032 Solved Assignments 2016

This document contains two C++ programming assignments for a BCA/MCA lab course. The first assignment asks students to write programs demonstrating arithmetic and logical operators, and creating a bank account class to perform basic saving account operations. The second assignment asks students to write programs demonstrating exception handling using matrix multiplication, and overloading the addition operator for complex numbers.

Uploaded by

ash thomas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views7 pages

BCSL 032 Solved Assignments 2016

This document contains two C++ programming assignments for a BCA/MCA lab course. The first assignment asks students to write programs demonstrating arithmetic and logical operators, and creating a bank account class to perform basic saving account operations. The second assignment asks students to write programs demonstrating exception handling using matrix multiplication, and overloading the addition operator for complex numbers.

Uploaded by

ash thomas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

PIXELES CLASSES BCA & MCA (IGNOU)

Course Code : BCSL-032


Course Title : C++ Programming Lab
Assignment Number : BCA (III)/L-032/Assignment/2015
October, 2015 (For July 2015 Session) April, 2016 (For January 2016 Session)
1. PIXELES Classes
(a) Write a C++ program to demonstrate us of all the arithmetic and logical operators in C++. Page | 1
(10 Marks)
ANs:
#include<iostream.h>
#include<conio.h> We are teaching IGNOU’s BCA & MCA
#include<stdio.h>
class oper Students
{
int s,s1,s2,s3,s4,s5;
//cout<<"USE OF AIRHTEMATIC OPERATOR"; Why join us?
public:
 Regular Classes
void sum(int a,int b)
{  BCA & MCA IGNOU Special Institute
cout<<"USE OF AIRHTEMATIC OPERATOR"<<endl;
s=a+b;  Free Trial Classes
cout<<"sum="<<s<<endl;
}  Subjective Knowledge
void subtract(int c,int d)
{  Free PIXELES Guide Books (Prepared by
s1=c-d;
our teachers)
cout<<"subtract="<<s1<<endl;
}  Free Solved Assignments
void mult(int e,int f)
{  Experienced Faculties
s2=e*f;
cout<<"multiply="<<s2<<endl;  100% Results
}
 Home Test Series
void div(int g,int h)
{
 Class Test Series
s3=g/h;
cout<<"divide="<<s3<<endl;  We teach you until you pass
}
void mod(int i,int j)  Final Year Synopsis & Project
{
s4=i%j;  Proper Guidance
cout<<"modulas="<<s4<<endl;

www.pixelesindia.com
PIXELES CLASSES BCA & MCA (IGNOU)
}

void log(int x,int y)


{
cout<<"USE OF LOGICAL OPERATOR"<<endl;
PIXELES Classes
if(x>0 && y>0)
Page | 2
{
s5=x-y;
}
if(x<0 || y<0)
{
s5=x+y;
}
cout<<"result="<<s5;
}
};
void main()
{
oper ob;
clrscr();
ob.sum(6,7);
ob.subtract(8,3);
ob.mult(4,5);
ob.div(4,2);
ob.mod(5,12);
ob.log(8,9);
getch();
}

(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.

for ( i = 0 ; i < m ; i++ )


for ( j = 0 ; j < n ; j++ )
cin >> first[i][j];

cout << "Enter the elements of second matrix\n";

for ( i = 0 ; i < m ;i++ )


for ( j = 0 ; j < n ; j++ )
cin >> second[i][j];

for ( i = 0 ; i < m ; i++ )


for ( j = 0 ; j < n ; j++ )
sum[i][j] = first[i][j] + second[i][j];

cout << "Sum of entered matrices:-\n";

for ( i = 0 ; i < m ; i++ )


{
for ( j = 0 ; j < n ; j++ )
cout << sum[i][j] << "\t";

cout << endl;


}

}
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

You might also like