Question 1. Write a function which takes a C string as an input and converts it
ID: 3555435 • Letter: Q
Question
Question 1. Write a function which takes a C string as an input and converts it to all uppercase characters. For each lowercase character in the C string, simply subtract 32 from it to form the uppercase character. Any non-alphabetic character in the C string should not be changed. You are not allowed to use any other functions to do this. Do not write a main function. Your function does not do any cin
or cout. Hint: lowercase characters are between 'a' and 'z' where the value of 'z' equals the value of 'a' + 25. Remember, C strings are terminated with the '' character. Make sure to properly format all your code.
Question 2. Write a function which takes two string variables (not C strings) as inputs and compares them. If they are equal, the function should return 0. If the first string is less than the second string, return a negative number. If the first string is greater than the second string, return a positive number. You are not allowed to use the compare method of the string data type. You must use the comparison operators. Do not write a main function. Your function does not do any cin or cout. Make sure to properly format all your code.
Question 2. Write a function which takes two string variables (not C strings) as inputs and compares them. If they are equal, the function should return 0. If the first string is less than the second string, return a negative number. If the first string is greater than the second string, return a positive number. You are not allowed to use the compare method of the string data type. You must use the comparison operators. Do not write a main function. Your function does not do any cin or cout. Make sure to properly format all your code.
Explanation / Answer
1) void convert(char str[])
{
int i=0;
while(*(str+i)!='')
{
if(*(str+i)<='Z' && *(str+i)>='A')
*(str+i)=*(str+i)+32;
i++;
}
2) int compare(string str1,string str2)
{
if(str1==str2)
return 0;
if(str1<str2)
return -1;
else
return 1;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.