Lab 13 - 1781
Lab 13 - 1781
1=================================================
#include <iostream>
using namespace std;
int main()
{
int** a;
a = new int* [4];
for (int i = 0; i < 4; i++) {
a[i] = new int[4];
}
int count = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
a[i][j] = count;
count++;
}
}
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
cout << a[i][j] << " ";
}
cout << endl;
}
===============================TASK
2==========================================================
#include <iostream>
using namespace std;
int main()
{
char* a;
a = new char[10];
char* b;
b = new char[10];
cout << "Enter FIRST Array: \t";
cin.getline(a, 10);
cout << "Enter SECOND Array:\t";
cin.getline(b, 10);
cout << "After Changing to upper case :\t";
string str;
str = maximum(a, b);
for (int i = 0; i < str.length(); i++) {
cout << (char)(str[i] - 32);
}
return 0;
}
==============================TASK
3=========================================================
#include <iostream>
using namespace std;
T getmember(int x) {
return memblock[x];
}
};
int main()
{
Sequence <int, 5> myints;
Sequence <double, 5> myfloats;
myints.setmember(0, 100);
myfloats.setmember(3, 3.1416);
cout << myints.getmember(0) << '\n';
cout << myfloats.getmember(3) << '\n';
return 0;
}
=====================TASK
4============================================================
#include <iostream>
using namespace std;
template <typename T>
class tornadoException {
public:
tornadoException() {
cout << "TORNADO = Take cover immediately!" << endl;
}
tornadoException(T m);
};
int main() {
string str = "";
tornadoException <string>();
tornadoException<int>(5);
}
===================================TASK 5=================================
#include <iostream>
using namespace std;
class Animal
{
public:
virtual void speak() {
cout << "SPAEK Constructor called" << endl;
}
virtual ~Animal() {
cout << "ANIMAL Destructor called" << endl;
}
};
int main()
{
Animal objAnimal;
Dog objDog;
Animal* ptrAnimal = &objAnimal;
Dog* ptrDog = &objDog;
objAnimal.speak();
objDog.speak();
ptrAnimal->speak();
ptrDog->speak();
ptrDog->Animal::speak();
}
====================TASK 6================================================
#include <iostream>
using namespace std;
class Animal
{
public:
virtual void speak() {
cout << "Speak Constructor called" << endl;
}
virtual ~Animal() {
cout << "~Animal Destructor called" << endl;
}
};
int main()
{
Animal objAnimal;
Dog objDog;
Dog* ptrDog = &objDog;
Animal* ptrAnimal = &ptrDog;
objAnimal.speak();
objDog.speak();
ptrAnimal->speak();
ptrDog->speak();
ptrDog->Animal::speak();
}