6. For Quiz 9 about Character I/O and Strings Q 5, the ans is that
if(symbol !=' ') should be if(!isspace(symbol)) ,
is there any difference between if(symbol!= ' ') and
if(!isspace(symbol)) ??? why need to change to use isspace()?
Good question, here is the ans. which I grep from man isspace in Unix.
isspace() tests for any space, tab, carriage-return,
newline, vertical-tab or form-feed (standard
white-space characters) or for one of the
current locale-defined set of characters for
which isalnum() is false. In the C locale,
isspace() returns true only for the standard
white-space characters.
7. For Q 6 , if (s3 > s2) is to compare the size of the string or
anythings else??
why the ans is HiHiHeh rather than HiHehHiHeh ??
s3 > s2 is string comparison, which do character by character comparison
until one of the string ends.
so if s3="Heh", s2="Hi",
we have H==H
then e < i then if s3>s2 will become false.
if s3="Hih", then s3>s2 will become true.
You could further explore it by doing more test on your own.
here are some e.g.
s2="Hi", s3="He"
s2="Hi", s3="Hi"
and the above mentioned ones...
One more thing, if your string is stored in char* or char[]
you would need strcmp() to do the similar comparison operation.
e.g.
char a[100];
char b[100];
cin >> a;
cin >> b;
if (strcmp(a,b)<0)
cout << "a0)
cout << "a>b" << endl;
else
cout << "a=b" << endl;
8. I am writing to ask some question about 'Character'.I have
encountered 2
problem when studying the slide.
1)there are some functions that can't be found the detail in the
book,such as
int(c), int('0'), char(i)....
can u explain that to me in detail or suggest some reference that where
i can
find it?
actually those int(), char() are type conversion stuff.
if you still remember what Dr. Tang or I had said about the representation
of characters in computer you would know that a character say, 'a' is
represented as an integer no. 97 in the computer.
Therefore, if you want to explicitly convert a character to
it's integer representation you would use something like this.
int aInt=int('a');
Please also note that, if we are talking about characters we use '' to
quote it, otherwise it is some other type. That is '1' is a character and
1 is an integer. But be awared that '1' 's integer representation is not
integer 1, '1' is a character and it's integer representation is 49, this
is because the integer representation of characters is encoded according
to an ascii table which is mentioned in the notes.
I have a written a program
which is you could understand more about characters and their
corresponding integer representation.
For reference, I don't have much of them in hand, as it is relatively
simple once you test it with a computer.
9. Where could I find you if I have questions?
Call me at 97204111 if it is urgent, email me otherwise.
10. Could you give me some tips on the final exam?
Yes and No. I haven't read the exam paper but according to my
experience. Here are some tips that might be helpful
The last few lecture is the most important.
Pay attention to those extra stuff.
Learn and understand those algorithm like link list, recursion,
sorting, character arithmatic, pointer arithmatic not just remembering
them.
Things could be twisted around.
There are a lot of program to write as mentioned by the lecturers.
Do the extra lab and lab again and read the book if you have time.
Sleep well, you need to think a lot.
11. Do we need to memorize the ASCII code?
No. But of course if you like you could memorize it.
12. Is Quiz 12, question 1, wrong?
Yes. I suspect it should be wrong, but I am not sure as the question is
not set by me. I have put up another version which is written by me and I
guess that should be the ans. we would agree on.