1 / 9

Ch6 & 12 Note

Ch6 & 12 Note. Dr. Wang. Strings for C, C++, Java. C++ string – string str = “VWC”; C- string – char cstr [21] = {‘V’, ‘W’, ‘C’, ‘’}; char cstr2[21] = “VWC”; Assignment is valid for C++ string, not C-string: str = “ODU”; // valid cstr2 = “ODU”; // invalid

gisela
Download Presentation

Ch6 & 12 Note

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Ch6 & 12 Note Dr. Wang

  2. Strings for C, C++, Java C++ string – string str = “VWC”; C- string – char cstr[21] = {‘V’, ‘W’, ‘C’, ‘\0’}; char cstr2[21] = “VWC”; Assignment is valid for C++ string, not C-string: str = “ODU”; // valid cstr2 = “ODU”; // invalid strcpy (cstr2, “ODU”); // valid • I/O similar: cin >> str; // “CS202” cin >> cstr; // “CS380”

  3. Strings for C, C++, Java (ctd) Java string – String st1, st2; …. st1 = “VWC”; str2 = str1; • I/O total different from C/C++ System.out.println(str1); Input uses the Scanner class – Scanner in = new Scanner(System.in); str = in.next(); // a single string

  4. Enumeration types, p.259 • C/C++ enum Gender {MALE, FEMALE}; Gender t1 = MALE; Gender t2 = FEMALE; • Java interface for enumeration

  5. Arrays, p.264 • C/C++: arrays have a limitation for storage (static) const int MAX = 100; int num[MAX] = {1, 2, 3}; … • Java array is dynamic int x; … intarr[] = new int[x];

  6. Record Types, p.282 • C/C++ struct • Java class

  7. Pointers & References, p.291 • C/C++ int* ptr = new int; *ptr = 7; int x = 12; int* qtr = &x; *qtr = *ptr; cout << *ptr << “\t” << *qtr << “\t” << x;

  8. Ch 12 OOP • Procedure-oriented P. L. – C, Fortran, .. • Object-O. P.L. – C++, Java, Clips, Alice • Inheritance, composition, & polymorphism • C++: data members, function members • Java: instance variables, methods

  9. Ch 12 OOP Inheritance • Super class  sub class • A subclass may inherit all methods and instance variables (in C++: functions, data)

More Related