Fa20-Bee-040 Oop Lab 13
Fa20-Bee-040 Oop Lab 13
Programming
Lab 13
Names
FA20-BEE-040
Registration
Numbers
Class 3B (BEE)
Lab Assessment
Task 5.1
#include<iostream>
#include<conio.h>
class Test
{
public:
T1 temp = var1;
var1 = var2;
var2 = temp;
}
};
int main()
{
Test <int> t1;
Test <float> t2;
Test <char> t3;
t1.swap(9, 15);
t2.swap(18.2,25.3);
t3.swap('c','a');
return 0;
}
Output
Task 5.2
#include<iostream>
cout<<array[i]<<" ";
cout<<endl;
int main()
{
const int size = 2;
int a[size] = { 1, 2 };
double b[size] = { 1.11, 2.23 };
char c[size] = { 'A','B'};
Output
Task 6.1
#include<iostream>
using namespace std;
template<class T>
class stack{
private:
T st[17];
int top;
public:
stack()
{
top = -1;
}
bool isempty()
{
return (top < 0);
}
void push(T var)
{
st[++top] = var;
}
T pop()
{
return st[top--];
}
};
int main()
{
stack<float> s1;
s1.push(111.1);
cout<<"1: "<<s1.pop()<<endl;
s1.isempty();
stack<int> s2;
s2.push(-1);
cout<<"2: "<<s2.pop()<<endl;
s2.isempty();
return 0;
}
Output
Critical Analysis
This lab taught us about templates and their use in programming, templates can
be used in two different ways with functions and with classes. Using a template
we can create a single function that can process any type of data. The portability
provided by a template mechanism can be extended to classes.