{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture17

lecture17 - Monday,December6 th Icecream(mmmmmm,IceCream...

This preview shows pages 1–10. Sign up to view the full content.

Monday, December 6 th      Fill out class evaluation forms  Ice cream (mmmmmm, Ice Cream)  Finish Operator Overloading  Start Review:  ASCII  Pointers  Classes  Constructors and Destructors The final exam is  this   FILL IN THE BLANK. Review session on  FILL IN THE BLANK!

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Characters and ASCII Every symbol on the keyboard:  letter digit period space , etc. is  represented by a  numeric value in memory ! ‘A’ = 65, ‘B’ = 66, ..., ‘Z’ = 90 ‘a’ = 97, ‘b’ = 98, ..., ‘z’ = 122 ‘ ‘ = 32 (space), ‘!’ = 33, ‘,’ = 44, etc... ‘0’ = 48, ‘1’ = 49, ‘2’ = 50,... ‘9’ = 57
main() { char c1 = ‘C’ ; // note: c NOT C char c2 = 67 ; cout << c1 << endl; cout << c2 << endl; }   Characters and ASCII c1 67 When using char variables in C++, you may use symbolic  characters or ASCII (numeric) values. c2 67 C C ‘A’ = 65 ‘B’ = 66 ‘C’ = 67 ... ‘Z’ = 90 When you use  cout  to print a  char  variable cout  converts the  number  back  to a  symbol  for display on the screen.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Characters and ASCII void main(void) { char ch; cout >> “Enter a char: “; cin >> ch; cout << ch << endl; cout<< static_cast<int>( ch ) << endl; ++ch; // treat it just like a number! cout << ch << endl; cout<< static_cast<int>( ch ) << endl; } Enter a char: d ch 100 d 100 You can print out the  ASCII value of a char  variable  instead of  printing its symbol  using  static_cast . 101 e 101
What’s the Difference? void main(void) { int i cout >> “Enter an int: “; cin >> i; cout << i << endl; char c; cout >> “Enter a char: “; cin >> c; cout << static_cast<int>(c) << endl; cout << c; } If you use cin with an  int  variable , C++ converts the  symbol you type into its  integer equivalent.  i  c Enter an int: 9   9 9 Enter a char: 9  57 If you use cin with a  char variable , it converts the  symbol you type into its ASCII value, not its integer  value. 57 9

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
num2   Characters and ASCII void main(void) { char c; cout<<"Enter uppercase letter: "; cin >> c; int num = c - 65; cout << c << " is letter # " << num; cout << endl; int num2 = c - 'A'; cout << c << " is letter # " << num2; cout << endl; if ('A' == 65) cout << "A is 65!\n"; if ('0' == 48) cout << "0 is 48!\n"; }   c num Enter uppercase letter: F 70 5 F is letter 5 num2 = c - 65; F is letter 5 5 A is 65 0 is 48
main() { int a=1, b=2; int *p1, *p2; // how to define 2 ptrs p1 = &a; p2 = &b; // whats the diff between if (*p1 == *p2) { do something; }// and if (p1 == p2) { do something; } } 00000000 00000001 00006420 00006421 00006422 00006423 00006424 00006425 00006426 00006427 00006428 00006429 00006430 00006431 00006432 00006433 00006434 00006435 a             1 b             2 p1         p2                6420 6424 *p1 == *p2  and  p1 == p2

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
*p1 == *p2  and  p1 == p2 main() { int a=1, b=2; int *p1, *p2; // how to define 2 ptrs p1 = &a; p2 = &b; // whats the difference between if (*p1 == *p2) { do something; } // and if (p1 == p2) { do something; } } 00000000 00000001 00006420 00006421 00006422 00006423 00006424 00006425 00006426 00006427 00006428 00006429 00006430 00006431 00006432 00006433 00006434 00006435 a             1 b             2 p1         p2                6420 6424 “Compare the value pointed to by p1 to the value  pointed to by p2.” if ( ==  2 )
main() { int a=1, b=2; int *p1, *p2; // how to define 2 ptrs p1 = &a; p2 = &b;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}