Beruflich Dokumente
Kultur Dokumente
Last Dates for Submission : 15th October, 2015 (For July 2015
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.
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();
}
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;
}
};
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.
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();
}
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;
}