Sie sind auf Seite 1von 9

Course Code : BCSL-032

Course Title : C++ Programming Lab

Assignment Number : BCA(III)/L-032/Assignment/2015

Maximum Marks : 50 Weightage : 25%

Last Dates for Submission : 15th October, 2015 (For July 2015
Session)

15th April, 2016 (For January 2016 Session)

This assignment has two questions. Answer both the questions. These
questions carry 40 marks. Rest 10 marks are for viva-voce. Write C++
program and take its output as part of solution. Please go through
the guidelines regarding the assignments given in the programme
guide for the format of presentation.
1.

(a) Write a C++ program to demonstrate us of all the arithmetic and


logical operators in C++.

Solution:

#include<iostream.h>
#include<conio.h>
class abc
{
int a[10],i,sum,av,max,min;
public:
void input()
{
sum=0;
cout<<"\n Enter array elements:";
for(i=0;i<10;i++)
{
cin>>a[i];
sum=sum+a[i];
}
}
void calAverage()
{
av=sum/10;
}
void min_max()
{
max=a[0];
min=a[0];
for(i=0;i<10;i++)
{
if(a[i]<min)
min=a[i];
else if(a[i]>max)
max=a[i];
}
}
void display()
{
cout<<"\n Average of number in Array :"<<av;
cout<<"\n largest of number in Array"<<max;
cout<<"\n Smallest of number in Array"<<min;
}
};
void main()
{
clrscr();
abc obj;
obj.input();
obj.calAverage();
obj.min_max();
obj.display();
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.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>

class Account
{
protected:
int account_no;
char name[20];
float amt;
public:
void input()
{
cout<<"\n Enter account number:\t";
cin>>account_no;
cout<<"\n Enter Your Name:\t";
gets(name);
cout<<"\n Enter Amount:\t";
cin>>amt;
}
void deposit(float a)
{
}
void withdrawl(float a)
{
}
void Show()
{
cout<<"\nCustomer Details:\n";
cout<<"\nAccount Number:\t"<<account_no;
cout<<"\nName:"<<name;
cout<<"\nTotal Amount:\t"<<amt;
}
};

class Saving_Account::public Account


{
char type_of_account;
public:
void get_details()
{
input();
cout<<"\n Enter typre of Account:\t";
cin>>type_of_account;
}
void deposit(float a)
{
amt=amt+a;
}
void withdrawl(float a)
{
amt=amt-a;
}
};
class Current_Account::public Account
{
char type_of_account;
public:
void get_details()
{
input();
cout<<"\nEnter type of Account:\t";
cin>>type_of_account;
}
void deposit(float a)
{
amt=amt+a;
}
void withdrawl(float a)
{
amt=amt-a;
}
};
void main()
{
float amount;
clrscr();
Saving_Account sa;
sa.get_details();
cout<<"\n Enter amount to be deposited in Saving Account:\t";
cin>>amount;
sa.deposit(amount);
sa.show();
cout<<"\n Enter the amount to be Withdrawl from Saving Account:\t";
cin>>amount;
sa.withdrawl(amount);
sa.show();

Current_Account ca;
ca.get_details();
cout<<"\n Enter amount to be deposited in Current Account:\t";
cin>>amount;
ca.deposit(amount);
ca.show();
cout<<"\n Enter the amount to be Withdrawl from Current Account:\t";
cin>>amount;
ca.withdrawl(amount);
ca.show();
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.

Solution:

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>

class String
{
char str[80];
public:
String(char s[])
{
strcpy(str,s);
}
int operator -(String ss)
{
int len;
if(strlen(str)>strlen(ss.str))
len=strlen(str)-strlen(ss.str);
else
len=strlen(ss.str)-strlen(str);
return len;
}
};

void main()
{
char str1[50],str2[20];
clrscr();
cou<<"\n Enter the First String:\t";
gets(str1);
cou<<"\n Enter the Second String:\t";
gets(str2);
String s1(str1);
String s2(str2);
int diff=s1-s2;
cout<<"\n Difference in length ="<<diff;
getch();
}

(b) Write C++ program for addison of two complex numbers by


overloading „+‟ operator. Make necessary assumptions wherever
required.

Solution:

#include <iostream.h>
template<class T>
class Node
{
friend LinkedQueue<T>
private:
T data;
Node<T> *link;
};
templatelink;
delete front;
front = next;
}
}
template<class T>
T LinkedQueue<T>::First() const
{
if (IsEmpty()) { cout<<"OutOfBounds()"; return -1; };
return front->data;
}
template<class T>
T LinkedQueue<T>::Last() const
{
if (IsEmpty()) { cout<<"OutOfBounds()"; return -1; };
return rear->data;
}
template<class T>
LinkedQueue<T>& LinkedQueue<T>::Add(const T& x)
{
Node<T> *p = new Node<T>;
p->data = x;
p->link = 0;
if (front) rear->link = p; // queue not empty
else front = p; // queue empty
rear = p;
return *this;
}
template<class T>
LinkedQueue<T>& LinkedQueue<T>::Delete(T& x)
{
if (IsEmpty()) { cout<<"OutOfBounds()"; return *this; };
x = front->data;
Node<T> *p = front;
front = front->link;
delete p;
return *this;
}
void main(void)
{
LinkedQueue<int> Q;
int x;
Q.Add(1).Add(2).Add(3).Add(4);
cout << "No queue add failed" << endl;
cout << "Queue is now 1234" << endl;
Q.Delete(x);
cout << "Deleted " << x << endl;
cout << Q.First() << " is at front" << endl;
cout << Q.Last() << " is at end" << endl;
Q.Delete(x);
cout << "Deleted " << x << endl;
Q.Delete(x);
cout << "Deleted " << x << endl;
Q.Delete(x);
cout << "Deleted " << x << endl;
cout << "No queue delete failed " << endl;
}

Das könnte Ihnen auch gefallen