ASSIGNMENT No3
ASSIGNMENT No3
POLYMORPHISM IN C++
PREPARED BY
HURR ABBAS
SUBMITTED TO
Ms. AYESHA
ROLL No. 5111323030
FIELD: BS-AI-II
SUBJECT: OOP
int main() {
int numericArr[] = {5, 2, 9, 1, 7};
string stringArr[] = {"apple", "banana", "cherry", "date", "fig"};
int n = sizeof(numericArr) / sizeof(numericArr[0]);
sortNumericArray(numericArr, n);
sortStringArray(stringArr, n);
cout << "Sorted numeric array: ";
for (int i = 0; i < n; ++i) {
cout << numericArr[i] << " ";
}
cout << endl;
return 0;
}
2. Write program to remove 2nd letter. Let the input string is pwsxtpbcderxrtxgt then
the output is pwxtpbcderxrtxgt.
#include <iostream>
#include <string>
using namespace std;
int main() {
string inputString = "pwsxtpbcderxrtxgt";
string result = removeSecondLetter(inputString);
cout << "Output after removing 2nd letter: " << result << endl;
return 0;
}
3. Read a string and replace first x by y. Input is artxuxtxxp and resulted output
artyuxtxxp.
#include <iostream>
#include <string>
using namespace std;
int main() {
string inputString = "artxuxtxxp";
string result = replaceFirstXWithY(inputString);
cout << "Output after replacing first 'x' with 'y': " << result << endl;
return 0;
}