BCSL-032 ASSIGNMENT SOLUTION (2018-19)

If you have any queries please leave a message here
Your Message
×


In this ASSIGNMENT all the below PROGRAMMINGS are written and run in Turbo C++ 3.0

We have removed clrscr( ) and getch( ) functions from each programming because of different version of C++ compiler.




Question 1 (a) :

Write a C++ program for followings :

Answer : -

// Find sum of 1+3+5+…. up to n terms
#include<iostream.h>
class series
{
public:
void calculation(int n)
{
int i, a=1, sum=0;
for(i=1;i<=n;i++)
{
sum=sum+a;
a=a+2;
}
cout << "\n Answer = " << sum;
}
};

void main()
{
int num;
cout << "\n Enter the value of n : ";
cin >> num;
series ob1;
ob1.calculation(num);
}

Output

Enter the value of n : 5

Answer = 25




// Generate Fibonacci series
#include<iostream.h>
class Fibonacci
{
private:
int a, b, c, n;

public:
void Input()
{
cout << "\n Enter the first number of the series : ";
cin >> a;
cout << "\n Enter the second number of the series : ";
cin >> b;
cout << "\n Enter the number of terms you want to generate : ";
cin >> n;
}
void SeriesGenerate()
{
int i;
for(i=1;i<=n;i++)
{
c=a+b;
cout << "\t" << c;
a=b;
b=c;
}
}
};

void main()
{
Fibonacci ob1;
ob1.Input();
ob1.SeriesGenerate();
}

Output

Enter the first number of the series : 2

Enter the second number of the series : 5

Enter the number of terms you want to generate : 5

712193150




Question 1 (b) :

Write a C++ program to create class named Account. Derive Current_Account and Saving_Account classes from it. Define method display-balance() in both the classes. Make necessary assumptions wherever required.

Answer : -

#include<iostream.h>
#include<conio.h>
class Account
{
protected:
long account_no;
double balance;
Account()
{
balance=0.0;
}
};

class Current_Account : private Account
{
public:
Current_Account(long accno, double b)
{
account_no=accno;
balance=b;
}
void display_balance()
{
cout << "\n Account Type \t Account No. \t Balance";
cout << "\n ------------ \t ----------- \t -------";
cout << "\n Current \t " << account_no << " \t " << balance;
}
};

class Saving_Account : private Account
{
public:
Saving_Account(long accno, double b)
{
account_no=accno;
balance=b;
}
void display_balance()
{
cout << "\n Account Type \t Account No. \t Balance";
cout << "\n ------------ \t ----------- \t -------";
cout << "\n Saving \t " << account_no << " \t " << balance;
}
};

void main()
{
clrscr();
Current_Account ob1(1055080, 1540372.25);
Saving_Account ob2(2468105, 50815.75);
ob1.display_balance();
cout << "\n\n\n";
ob2.display_balance();
getch();
}

Output

Account TypeAccount No.Balance
----------------------------------------------
Current10550801540372.25
Account TypeAccount No.Balance
----------------------------------------------
Saving246810550815.75



Question 2 (a) :

Write a C++ program to demonstrate exception handling by using example of multiplication of two matrices.

Answer : -

#include<iostream.h>
void main()
{
int i, j, k, a[3][3], b[3][3], c[3][3];
// Input Matrix A
cout << "\n Enter the element of matrix A";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout << "\n Enter the value of A[" << i << "][" << j <<"] : ";
cin >> a[i][j];
}
}
// Input Matrix B
cout << "\n Enter the element of matrix B";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout << "\n Enter the value of B[" << i << "][" << j <<"] : ";
cin >> b[i][j];
// Matrix C initialization
c[i][j] = 0;
}
}
// try block
try
{
// Multiply matrix A and B
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
for(k=0;k<3;k++)
{
c[i][j] = c[i][j] + (a[i][k] * b[k][j]);
}
}
}
}
// catch block
catch(char* message)
{
cerr << message;
}
// Print the matrix C
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout <<"\t" << c[i][j];
}
cout << endl;
}
}

Output

Enter the Element of First Matrix
Enter the value of A[0][0] : 1

Enter the value of A[0][1] : 4

Enter the value of A[0][2] : 2

Enter the value of A[1][0] : 3

Enter the value of A[1][1] : 2

Enter the value of A[1][2] : 5

Enter the value of A[2][0] : 4

Enter the value of A[2][1] : 6

Enter the value of A[2][2] : 3

Enter the Element of Second Matrix
Enter the value of B[0][0] : 2

Enter the value of B[0][1] : 6

Enter the value of B[0][2] : 3

Enter the value of B[1][0] : 8

Enter the value of B[1][1] : 1

Enter the value of B[1][2] : 5

Enter the value of B[2][0] : 6

Enter the value of B[2][1] : 2

Enter the value of B[2][2] : 4

461431
523039
743654




Question 2 (b) :

Write C++ program for adding two matrices by overloading ‘+’ operator. Make necessary assumptions wherever required.

Answer : -

#include<iostream.h>
class MatrixAddition
{
private:
int matrix[5][5], value, i, j;

public:
MatrixAddition(int m[5][5], int n)
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
matrix[i][j] = m[i][j];
}
}
value = n;
}
/* Adding two matrices by overloading ‘+’ operator */
void operator +(MatrixAddition obj)
{
for(i=0;i<value;i++)
{
for(j=0;j<value;j++)
{
cout << "\t" << (matrix[i][j] + obj.matrix[i][j]);
}
cout << endl;
}
}
};
void main()
{
int a[5][5], b[5][5], x, y, z;
cout << "\n Enter the number of row/column present in the matrix : ";
cin >> z;
// Input Matrix A
cout << "\n Enter the element of matrix A";
for(x=0;x<z;x++)
{
for(y=0;y<z;y++)
{
cout << "\n Enter the value of A[" << x << "][" << y << "] : ";
cin >> a[x][y];
}
}
// Input Matrix B
cout << "\n Enter the element of matrix B";
for(x=0;x<z;x++)
{
for(y=0;y<z;y++)
{
cout << "\n Enter the value of B[" << x << "][" << y << "] : ";
cin >> b[x][y];
}
}
MatrixAddition ob1(a,z), ob2(b,z);
ob1 + ob2;
}

Output

Enter the number of Row / Column present in the Matrix : 2

Enter the Element of First Matrix
Enter the value of A[0][0] : 5

Enter the value of A[0][1] : 8

Enter the value of A[1][0] : 3

Enter the value of A[1][1] : 4

Enter the Element of Second Matrix
Enter the value of B[0][0] : 7

Enter the value of B[0][1] : 6

Enter the value of B[1][0] : 7

Enter the value of B[1][1] : 9

1214
1013



ABOUT US

QuestionSolves.com is an educational website that helps worldwide students in solving computer education related queries.

Also, different software like Visual Studio, SQL Server, Oracle etc. are available to download in different versions.

Moreover, QuestionSolves.com provides solutions to your questions and assignments also.


MORE TOPIC


Windows Command

UNIX Command

IGNOU Assignment Solution

IGNOU Question Paper Solution

Solutions of Different Questions


WHAT WE DO


Website Devlopment

Training

Home Learning

Provide BCA, MCA Projects

Provide Assignment & Question Paper Solution


CONTACT US


Follow Us