isalpha() and isdigit()

Pages: 12

Define a set of overloaded versions for isalpha(), isdigit(), so that these functions work correctly for char ,unsigned char ,and signed char

1
2
3
4
5
6
7
8
9
10
bool isdigit(int ch)
{
	return ch >= '0' && ch <= '9';
}


bool isalpha(int ch)
{
	return islower_(ch) || isupper(ch);
}
And the problem is.... ?
I want to define isdigit(), isalpha() function for char ,unsigned char ,and signed char
A char is alpha if it's greater than or equal to A and less than or equal to z.

http://www.asciitable.com/
Last edited on
you said, I did not understand

1
2
3
4
5
6
7
8
9
10
char a;
cin >> a;
if ( (char >= 'A')  && (char <= 'z'))
{
  cout << "It's alpha";
} 
else
{
  cout << "It's not alpha";
}
thank
What to do with my question?
1
2
3
4
bool isalpha(char a)
{
  return ((char >= 'A')  && (char <= 'z'));
}


Last edited on
incorrect code.Do you think ?
firix, you should know by now that there's no way we're going to give you a full solution. Moschops did give you a solid quarter of it, though, if I understood the problem correctly. :/

EDIT: Well... closer to 1/5 because of a teeny-tiny gigantic deliberate flaw.

-Albatross
Last edited on
incorrect code.Do you think ?


An enormous clue, though.
Last edited on
I did not understand the solution :)


firix, honestly I have gone through your posts and most of them ask for a solution with no attempts at a solution yourself. I am surprised Mochops was kind enough to even give you something.
Last edited on
Moschops:

An enormous clue, though.


you do not understand what it means.
Last edited on
There's an error in the code, but it's easily fixed. Sod it, I'll just give you the function.

1
2
3
4
bool isalpha(char a)
{
  return ((a >= 'A')  && (a <= 'z'));
}


The function accepts a char, and returns true is the char is an alphabetical letter, and false if it is not.

That's your lot, though. You can use this as a template to do all the rest. Your original functions were passing in integers. Why integers? The instructions make it clear you should be judging characters.

GodPyro,

firix, honestly I have gone through your posts and most of them ask for a solution with no attempts at a solution yourself. I am surprised Mochops was kind enough to even give you something.


please.
Do not get me wrong.
I could not understand the subject.
I have read here, but there is nothing to understand.

http://www.cplusplus.com/reference/c...ctype/isalpha/
Oh right.

Well, not understanding the question is no crime.

Define a set of overloaded versions for isalpha(), isdigit(), so that these functions work correctly for char ,unsigned char ,and signed char


This means make six functions. Three of them are called isalpha, three of them are called isdigit.

The isalpha functions are to take in a char or an unsigned char or a signed char, and should return true if the input is a letter, and return false if the input is not a letter.

e.g.
1
2
3
bool isalpha(char);
bool isalpha(unsigned char);
bool isalpha(signed char);


The isdigit functions are to take in a char, or an unsigned char, or a signed char, and should return true is the input is a number.

Last edited on
why three,
what char, signed char, unsigned char is the difference between
Would not it be even if I write only to char
I don't know. You're the one who came up with the question. Why do you need one for char, one for unsigned char and one for signed char?
this example in Bjarne Sttorutrup`s C++ programming Language book


Define a set of overloaded versions for i s a l p h a (), i s d i g i t (), etc., so that these functions
work correctly for c h a r , u n s i g n e d c h a r , and s i g n e d c h a r
Pages: 12