ch6 12 note n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Ch6 & 12 Note PowerPoint Presentation
Download Presentation
Ch6 & 12 Note

Loading in 2 Seconds...

play fullscreen
1 / 9

Ch6 & 12 Note - PowerPoint PPT Presentation


  • 80 Views
  • Uploaded on

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] = “VWC”; Assignment is valid for C++ string, not C-string: str = “ODU”; // valid cstr2 = “ODU”; // invalid

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Ch6 & 12 Note' - gisela


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
strings for c c java
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”

strings for c c java ctd
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

enumeration types p 259
Enumeration types, p.259
  • C/C++

enum Gender {MALE, FEMALE};

Gender t1 = MALE;

Gender t2 = FEMALE;

  • Java interface for enumeration
arrays p 264
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];

record types p 282
Record Types, p.282
  • C/C++ struct
  • Java class
pointers references p 291
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;

ch 12 oop
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
ch 12 oop inheritance
Ch 12 OOP Inheritance
  • Super class  sub class
  • A subclass may inherit all methods and instance variables (in C++: functions, data)