Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ch6 & 12 Note Dr. Wang. Strings for C, C++, Java C++ string – string str = “VWC”; C- string – char cstr[21] = {‘V’, ‘W’, ‘C’, ‘\0’}; char cstr2[21] =

Similar presentations


Presentation on theme: "Ch6 & 12 Note Dr. Wang. Strings for C, C++, Java C++ string – string str = “VWC”; C- string – char cstr[21] = {‘V’, ‘W’, ‘C’, ‘\0’}; char cstr2[21] ="— 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; … int arr[] = 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)


Download ppt "Ch6 & 12 Note Dr. Wang. Strings for C, C++, Java C++ string – string str = “VWC”; C- string – char cstr[21] = {‘V’, ‘W’, ‘C’, ‘\0’}; char cstr2[21] ="

Similar presentations


Ads by Google