Professional Documents
Culture Documents
Lab#10 PF Cpe-27 M.usama Saghar
Lab#10 PF Cpe-27 M.usama Saghar
Lab Manual # 10
CLO: CLO-1
Lab Submission[10] 0 1 2 3 4 5
Completeness & Correctness
Required Conclusion & Results
No of Checks
SUB TOTAL
TOTAL SCORE
______________________
Course Instructor / Lab Engineer
return0;
}
When the above code is compiled and executed, it produces result something as follows:
Greeting message:Hello
1 strcpy(s1, s2);
2 strcat(s1, s2);
Concatenates string s2 onto the end of string s1.
3 strlen(s1);
Returns the length of string s1.
4 strcmp(s1, s2);
Returns 0 if s1 and s2 are the same; less than 0 if s1<s2; greater than 0
if s1>s2.
5 strchr(s1, ch);
Returns a pointer to the first occurrence of character ch in string s1.
6 strstr(s1, s2);
Returns a pointer to the first occurrence of string s2 in string s1.
The standard C++ library provides a string class type that supports all the operations mentioned
above, additionally much more functionality
Example
#include<iostream>
#include<string>
usingnamespace std;
int main ()
{
string str1 ="Hello";
string str2 ="World";
string str3;
intlen;
str3 = str1;
cout<<"str3 : "<< str3 <<endl;
str3 = str1 + str2;
cout<<"str1 + str2 : "<< str3 <<endl;
len= str3.size();
cout<<"str3.size() : "<<len<<endl;
return0;
}
When the above code is compiled and executed, it produces result something as follows:
str3 :Hello
str1 +str2 :HelloWorld
str3.size():10
P-1: Write a C++ program that will find the frequency of a character in the string that is entered
by user.
Your Code:
#include <stdio.h>
#include <string.h>
int main()
{
char string[100];
int c = 0, count[26] = {0}, x;
printf("Enter a string\n");
gets(string);
c++;
}
return 0;
}
Your Code:
#include <iostream>
using namespace std;
int main()
{
string s1, s2;
s2 = s1;
return 0;
}
P-3: Write a C++ program to find the number of vowels , consonant , digit and white space in a
string.
Your Code:
#include<iostream>
#include<string.h>
using namespace std;
int main ()
{
char str[50];
int v = 0, c = 0, n = 0, s = 0;
cout << "Enter a string : ";
gets(str);
for (int i = 0; str[i]!='\0'; ++i)
{
if (str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u' || str[i] == 'A' || str[i]
== 'E' || str[i] == 'I' || str[i] == 'O' || str[i] == 'U')
++v;
else if ((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z'))
P-4: Write a program that compare two user entered string either they are equal or not.
Your Code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
if (strcmp(string1, string2) == 0)
{
cout << "Yes";
return 0;
}
Comments: