Any help would be greatly apreciated, I need the following code to be in C++ ple
ID: 3920013 • Letter: A
Question
Any help would be greatly apreciated, I need the following code to be in C++ please.
Code two functions, both which accept a C-string parameter and return information about the C-string.
bool AllLetters(char *text) //this function accepts one C-string parameter and returns true if all characters in the a text are letters.
void AllUpper(char* text) //this function accepts one C-string parameter containing all letters and setting all characters to upper case
Your main program will verify that these function work properly by:
* asking the user to enter some text without blanks
*print out the text
* while the text that the user entered does not contain only letters (use your function to check this)
Ask the user to enter some text without blanks
* print out the text
* update the text so that the first letter only is in upper case (use your function to update the text)
* print out the text
Place the above functions in a file separate from the main, this part is very important.
Explanation / Answer
#include<iostream>
using namespace std;
bool AllLetters(char *text)
{
//returns true if all characters are text letters..
int i=0;
while(text[i]!='')//runs upto the end of the string..
{
int c= (int)text[i];
//matching with ascii values..of boundaries of letters
if(c<65)//means not a letter
return false;
else if(c>91 && c<97)//not a letter
return false;
else if(c>123)
return false;
i++;
}
return true;//means all are letters..
}
void AllUpper(char* text){
//converts all letters to upper case
//accepts only string that contains only letters
if(AllLetters(text))//checking whether it contains all letters or not..
{
int i=0;
while(text[i]!='')
{
int c= (int)text[i];
if(c>=97 && c<=123)
{
c=c-32;//converting to upper
text[i]=(char)c;
}
i++;
}
}
else cout<<" Does not contain all letters ";
}
int main()
{
//testing
char c[100];
cout<<"Enter a string(without blanks):";
cin>>c;
if(AllLetters(c))cout<<" Contains all letters ";
else cout<<" Does not contain all letters ";
cout<<c<<endl;
AllUpper(c);
cout<<" Converting to uppercase:"<<c<<endl;
return 0;
}
output:
Enter a string(without blanks):hero
Contains all letters
hero
Converting to uppercase:HERO
Process exited normally.
Press any key to continue . . .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.