{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lec02 - CSE 100 Lecture 2 C Scott B Baden Announcements...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Scott B. Baden CSE 100 Lecture 2 : C++
Background image of page 1

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

View Full Document Right Arrow Icon
Announcements Programming lab #1 has been posted Be sure to attend Friday’s section if you didn’t go on Wednesday Incentive for working as a team of 2: 3% extra credit Office hours – choose permanent time Piazza Shared with Section B00, but only for announcements pertaining to the labs If you want to post something for our section only, use the A00 group that’s been set up for the purpose Press "New Post” Select "Class group" in the second row Select an appropriate group from the drop-down menu If you have not received a Piazza invitation follow this link and request to join https://piazza.com/#spring2013/cse100 Scott B. Baden / CSE 100, Lec 2 / Spring 2013 2
Background image of page 2
Today’s Lecture An introduction to C++ Comparing Java and C++ Basic C++ programming Pointers and pointer arithmetic C++ primitive types and operators Pragmatics Reading: Weiss Ch 1, section 1.4 to 1.7 Scott B. Baden / CSE 100, Lec 2 / Spring 2013 3
Background image of page 3

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

View Full Document Right Arrow Icon
An introduction to C++ C++ is an object-oriented language based on the non-object-oriented C language C++ was initially developed by Bjarne Stroustrup at Bell Labs in the 1980’s Now it is an ISO standard and is one of the 3 most widely used programming languages in the world (along with Java and C) We are using C++11, the most recent standard In CSE 100, we don’t assume that you have programmed in C++ or C before We do assume that you have programmed in Java before! C++ is superficially similar to Java, but with many differences that can make it a challenge to use Let’s start by showing some comparisons between Java and C++, and then look at specific C++ details Scott B. Baden / CSE 100, Lec 2 / Spring 2013 5
Background image of page 4
Simple classes and objects in Java Suppose you have a Java class defined this way: Now you could write a Java program like this: public static void main(String[] args) { C x; // declare x to be a pointer to a C object x = new C(); // create a C and make x point to it object x.setA(5); // dereference x, and access a member System.out.println( x.getA() ); } Scott B. Baden / CSE 100, Lec 2 / Spring 2013 6 public class C { private int a; public void setA(int a) { this.a = a; } public int getA() { return a; } }
Background image of page 5

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

View Full Document Right Arrow Icon
Simple classes and objects in C++ Defining ‘the same’ class in C++: class C { private: int a; public: void setA(int a) { this->a= a;} int getA() { return a; } }; And writing ‘the same’ program: #include <iostream> int main() { C* x; // declare x to be a pointer to a C object x = new C(); // create a C object, and make x point to it x->setA(5); // dereference x, and access a member // note: (*x).setA(5) is equivalent x->getA() << std::endl; std::cout << } Scott B. Baden / CSE 100, Lec 2 / Spring 2013 7 public class C { // Java private int a; public void setA(int a) { this.a = a; } public int getA() { return a; } }
Background image of page 6
Pictures of memory It is useful to abstract the essentials about the contents of memory by drawing simple pictures...
Background image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}