CCS0007 - Laboratory Exercise 3
CCS0007 - Laboratory Exercise 3
CCS007L
(COMPUTER PROGRAMMING 2)
EXERCISE
3
CHARACTER AND STRING MANIPULATION
Section:
Professor:
I. PROGRAM OUTCOME/S (PO) ADDRESSED BY THE LABORATORY EXERCISE
Apply knowledge through the use of current techniques and tools necessary for the IT
profession. [PO: I]
INSTRUCTIONS:
Copy your source codes to be pasted in this document as well as a screen shot of your running
output.
if(chk==0)
cout<<"\nEqual";
else if (chk<1)
cout<<"\nNegative";
else
cout<<"\nPositive";
cout<<endl;
return 0;
}
int main()
{
char s1[100], s2[100];
cout<<"**********************************"<<endl;
cout<<"S T R I N G C O P Y "<<endl;
cout<<"**********************************"<<endl;
cout << "Enter The First Word (str1): ";
cin.getline(s1, 100);
cout << "Enter the Second Word (str2): ";
cin.getline(s2, 100);
strcpy(s1, s2);
cout << "new string value for str1: "<< s2 << endl;
return 0;
}
int main()
{
cout<<"**********************************"<<endl;
cout<<"S T R I N G C O N C A T E N A T E "<<endl;
cout<<"**********************************"<<endl;
string s1, s2, result;
result = s1 + s2;
return 0;
}
NOTE: Palindromes are words that are read the same way either left to right or right to left.
while(inputString[length] != '\0')
length++;
l = 0;
r = length -1;
return 0;
}
int main()
{
string str;
cout<<"Enter Some string: \n";
getline(cin,str);
for(int i=0;str[i]!='\0';i++)
{
if (str[i]>=65 && str[i]<=90 )
str[i] = str[i] + 32;
else if (str[i]>=97 && str[i]<=122 )
str[i] = str[i] - 32;
}
cout<< str;
return 0;
string reverse_words(string s)
{
int left = 0, i = 0, n = s.size();
left = i;
while (i < n)
{
if (i + 1 == n || s[i] == ' ')
{
int j = i - 1;
if (i + 1 == n)
j++;
left = i + 1;
}
if (s[left] == ' ' && i > left)
left = i;
i++;
}
reverse(s.begin(), s.end());
return s;
}
int main()
{
string str;
cout<<"Enter Some string: \n";
getline(cin,str);
str = reverse_words(str);
return 0;
}
Briefly answer the questions below. Avoid erasures. For group activity, specify the name of
GROUP MEMBER/s who answered the question. Do not forget to include the source for all
NON-ORIGINAL IDEAS.
What is a String?
Strings are like sentences. They're made up of a list of characters, which is actually an
"array of characters." Strings are extremely beneficial for transmitting information from
the program to the program's user. They are less useful when it comes to storing data
for the computer to use.
What is cctype?
This header specifies a suite of functions for character classification and transformation.
What is cstring?
CStrings are identical to regular strings, except they have an extra null character at the
end that distinguishes them as Cstrings. This null character represents the string's end.