Deep Discription of Classes and Inheritance
Deep Discription of Classes and Inheritance
22F-8801
TASK NO 1
#include<iostream>
using namespace std;
void swapp(int *x, int *y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
}
int main()
{
int a=10, b=30;
int *ap, *bp;
ap = &a;
bp = &b;
swapp(&a, &b);
cout << a << endl;
cout << b << endl;
system ("pause");
}
TASK NO 2
#include<iostream>
#include<string>
using namespace std;
int main()
{
string s;
string *sp;
sp = new string;
cout << "enter string" << endl;
getline (cin,s);
cout << s;
system("pause");
}
TASK 3
#include<iostream>
using namespace std;
void printfunction(int a[5])
{
for (int i = 0; i < 5; i++)
{
cout << a[i]<<endl;
}
}
int main()
{
int a[5];
int *ap;
ap = new int[5];
cout << " enter elements of array" << endl;
for (int i = 0; i<5; i++)
{
cin >> a[i];
}
cout << "______ELEMENTS OF ARRAY__________" << endl;
printfunction(a);//function call
system("pause");
}
TASK NO 4
#include<iostream>
using namespace std;
int main()
{
int row, col, sum = 0;
cout << "enter column" << endl;
cin >> col;
cout << "enter row" << endl;
cin >> row;
int **p;
p = new int*[row];
for (int i = 0; i < row; i++)
{
p[i] = new int[col];
}
cout << "enter elements of array" << endl;
for(int i = 0; i < row; i++)
{
for(int j = 0; j < col; j++)
{
cin >> **p;
sum = sum + **p;
}
}
cout << "__________sum of all elements of array" << endl;
cout << sum;
system("pause");
}
TASKNO 5
#include<iostream>
using namespace std;
int main()
{
int row, sum = 0;
cout << "enter row" << endl;
cin >> row;
int **p;
p = new int*[row];
for (int i = 0; i < row; i++)
{
p[i] = new int[i+1];
}
cout << "enter elements of array" << endl;
for (int i = 0; i < row; i++)
{
for (int j = 0; j < i+1; j++)
{
cin >> p[i][j];
}
}
for (int i = 0; i < row; i++)
{
for (int j = 0; j < i + 1; j++)
{
cout << p[i][j];
}
cout << endl;
}
system("pause");
}
TASK NO 6
#include<iostream>
using namespace std;
int *copyfunction(int arr[], int size)
{
int *ptr;
ptr = new int[size];
for (int i = 0; i < size; i++)
{
ptr[i] = arr[i];
}
return ptr;
}
int main()
{
int size;
cout << "_enter size of the array________" << endl;
cin >> size;
int *p;
p = new int[size];
cout << "+++++++++++++++++populate the array+++++++++++++++" << endl;
for (int i = 0; i < size; i++)
{
cin >> p[i];
}
cout << "+++++++++++++++++ array before copy+++++++++++++++" << endl;
for (int i = 0; i < size; i++)
{
cout << p[i]<<endl;
}
int *cp;
cp = copyfunction(p, size);
cout << "+++++++++++++++++ array after copy+++++++++++++++" << endl;
for (int i = 0; i < size; i++)
{
cout << endl << cp[i];
}
system("pause");
}