You are on page 1of 3

RAHMA ZAMIR BSCS 1-A 02-134222-096

Computer Programming Lab 12


Task 01
#include<iostream>
#include<string>
using namespace std;
void main()
{
string name1, name2;
string* ptr1 = &name1;
string* ptr2 = &name2;
string temp;
repeat:
cout << "\n Enter first string: ";
cin >> name1;
int len = name1.length();
if (len < 6)
{
cout << " String should have atleast 6 letters.";
goto repeat;
}
repeat2:
cout << "\n Enter second string: ";
cin >> name2;
int len2 = name2.length();
if (len2 < 6)
{
cout << "\n String should have atleast 6 letters.";
goto repeat2;
}
cout << "\n Enter new first string: ";
cin >> *ptr1;
cout << "\n Enter new second string: ";
cin >> *ptr2;
cout << "\n First string: " << *ptr1;
cout << "\n Second string: " << *ptr2 << endl<<endl;
system("pause");
}
RAHMA ZAMIR BSCS 1-A 02-134222-096

Task 02
#include<iostream>
#include<string>
using namespace std;
void main()
{
string blue;
string* ptr = &blue;
cout << " Enter your string: ";
cin >> blue;
int len = blue.length();
cout <<" Length of string : "<< len <<endl<< endl;
system("pause");
}
RAHMA ZAMIR BSCS 1-A 02-134222-096
Task 03

#include<iostream>
using namespace std;
int main()
{
int arr[5];
int* ptr = arr;
int temp;
for (int x = 0; x < 5; x++)
{
cout << " Enter element " << x + 1 << " of the array: ";
cin >> ptr[x];
}
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
if (arr[i] > arr[j])
{
temp = ptr[i];
ptr[i] = ptr[j];
ptr[j] = temp;
}
}
}
for (int k = 0; k < 5; k++)
{
cout << ptr[k];
}
}

You might also like