1. Write a function which takes a C string as an input and converts it to all up
ID: 3639116 • Letter: 1
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. (Points : 20)
2. Write a function which takes one string variable (not C string) as input and modifies the existing string. Try to find "Ohio" or "OHIO" in the input string. If the input string contains either of these, replace those 4 characters with "OH". As an example,
Original string = "Blacklick, Ohio 43004"
Modified string = "Blacklick, OH 43004"
Use an appropriate parameter passing mechanism. Your function will not do any cin or cout. Do not write a main function. Make sure to properly format all your code.
Explanation / Answer
please rate - thanks
void toUpper(char s[])
{int i=0;
while(s[i]!='')
{if(s[i]>='a'&&s[i]<='z')
s[i]=s[i]-32;
i++;
}
}
void replaceString(string &in )
{string change[]={"Ohio","OHIO"};
string to="OH";
int i,pos;
for(i=0;i<2;i++)
{pos=in.find(change[i],0);
if(pos !=in.npos)
{in.erase(pos,change[i].length());
in.insert(pos,to);
return;
}
}
return;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.