Professional Documents
Culture Documents
Hassan Rasif CP Lab 13
Hassan Rasif CP Lab 13
02-235222-014
EXERCISE 01)
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main() {
int count = 0;
string text;
string letter;
cout << "Enter any text: ";
getline(cin, text);
int size = text.size();
cout << "Enter letter you want to search in the given text: ";
cin >> letter;
int index = text.find(letter);
cout << "Searched letter is found at ";
for (int i = 0; i < size; i++) {
if (text[index] == text[i]) {
count++;
cout << i << " ";
}
}
cout << "index" << endl;
cout << "Occured " << count << " times." << endl;
}
HASSAN RASIF CP LAB 13
02-235222-014
EXERCISE 02)
#include <iostream>
#include <string>
#include <cstring>
int main () {
string str1="Kaif";
string str2="Zonish";
int str_one_size=str1.size();
int str_two_size=str2.size();
else {
}
HASSAN RASIF CP LAB 13
02-235222-014
EXERCISE 03)
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main() {
string str1 = " MY NAME IS HASSAN RASIF";
string str2;
str2 = str1;
cout << str2 << endl;
}
HASSAN RASIF CP LAB 13
02-235222-014
EXERCISE 04
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main() {
string str1 = "MY NAME IS HASSAN ";
cout << "First character is " << str1.front() << endl;
cout << "Last character is " << str1.back() << endl;
}