CS 11 C++ track: lecture 1 Administrivia Need a CS cluster account sysadmin/account_request.cgi Need to know UNIX (Linux)

Slides:



Advertisements
Similar presentations
Chapter 18 Vectors and Arrays
Advertisements

A C++ Crash Course Part II UW Association for Computing Machinery Questions & Feedback.
C++ Language Fundamentals. 2 Contents 1. Introduction to C++ 2. Basic syntax rules 3. Declaring and using variables.
Chapter 18 Vectors and Arrays John Keyser’s Modification of Slides by Bjarne Stroustrup
Lecture 3 Feb 4 summary of last week’s topics and review questions (handout) Today’s goals: Chapter 1 overview (sections 1.4 to 1.6) c++ classes constructors,
CSE 374 Programming Concepts & Tools Hal Perkins Winter 2012 Lecture 19 – Introduction to C++
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Object Oriented Programming.  OOP Basic Principles  C++ Classes  September 2004  John Edgar 22.
OOP Etgar 2008 – Recitation 11 Object Oriented Programming Etgar 2008 Recitation 1.
1 CSE 303 Lecture 21 Classes and Objects in C++ slides created by Marty Stepp
Chapter Objectives You should be able to describe: Object-Based Programming Classes Constructors Examples Common Programming Errors.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles C/C++ Emery Berger and Mark Corner University of Massachusetts.
Guide To UNIX Using Linux Third Edition
CS-2303 System Programming Concepts
C++ fundamentals.
CSE 332: C++ Classes From Procedural to Object-oriented Programming Procedural programming –Functions have been the main focus so far Function parameters.
CS 11 C track: lecture 1 Preliminaries Need a CS cluster account cgi-bin/sysadmin/account_request.cgi Need to know UNIX ITS.
Introduction to C++. Overview C++? What are references Object orientation Classes Access specifiers Constructor/destructor Interface-implementation separation.
Lecture 22 Miscellaneous Topics 4 + Memory Allocation.
C++ C++ Overview (I) What is Object Orientated Programming? Approach: Break problem into subgroups of related parts that take into account code and data;
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Object Oriented Programming Concepts OOP – reasoning about a program as a set of objects rather than as a set of actions Object – a programming entity.
By – Tanvir Alam.  This tutorial offers several things.  You’ll see some neat features of the language.  You’ll learn the right things to google. 
 200 Total Points ◦ 74 Points Writing Programs ◦ 60 Points Tracing Algorithms and determining results ◦ 36 Points Short Answer ◦ 30 Points Multiple Choice.
By Noorez Kassam Welcome to JNI. Why use JNI ? 1. You already have significantly large and tricky code written in another language and you would rather.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Copyright 2008 by Pearson Education Building Java Programs Chapter 8 Lecture 8-3: Encapsulation, this reading: self-checks: #13-17 exercises:
CS 11 C++ track: lecture 4 Today: More on memory management the stack and the heap inline functions structs vs. classes.
Chapter 13. Procedural programming vs OOP  Procedural programming focuses on accomplishing tasks (“verbs” are important).  Object-oriented programming.
Copyright  Hannu Laine C++-programming Part 1 Hannu Laine.
1 Data Structures - CSCI 102 CS102 C++ Pointers & Dynamic Objects Prof Tejada.
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
1 Object-Oriented Programming Using C++ CLASS 1. 2 Review of Syllabus Catalog Description –An introduction to object oriented programming techniques using.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 4 – August 30, 2001.
Hank Childs, University of Oregon May 13th, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / / / __.
Object-Oriented Programming in C++
Current Assignments Start Reading Chapter 6 Project 3 – Due Thursday, July 24 Contact List Program Homework 6 – Due Sunday, July 20 First part easy true/false.
Monday, Mar 31, 2003Kate Gregory with material from Deitel and Deitel Week 12 Labs 4 and 5 are back File IO Looking ahead to the final.
Object-Oriented Programming in C++ More examples of Association.
CS Class 08 Today  Exercises  Nested loops  for statement  Built-in functions Announcements  Homework #3, group solution to in-class.
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
CS 11 java track: lecture 2 This week: more on object-oriented programming (OOP) objects vs. primitive types creating new objects with new calling methods.
 140 Total Points ◦ 100 Points Writing Programs ◦ 24 Points Tracing Algorithms and determining results ◦ 16 Points Short Answer  Similar to quizzes.
CS 11 C++ track: lecture 3 Today const and const -correctness operator overloading.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 16: Introduction to C++
Module 4: I/O and Strings #1 2000/01Scientific Computing in OOCourse code 3C59 Module 4: I/O In this module we will cover Keyboard/screen input and output.
1 Today’s Objectives  Announcements Homework #3 is due on Monday, 10-Jul, however you can earn 10 bonus points for this HW if you turn it in on Wednesday,
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.
Computing and Statistical Data Analysis Lecture 6 Glen Cowan RHUL Physics Computing and Statistical Data Analysis Introduction to classes and objects:
C++ REVIEW INPUT/OUTPUT (I/O). BRIEF NOTE “CLASSES” AND “STRUCTS” AND “TYPES” They are ADTs… They define data and operations on that data The ADTs in.
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
CSC1201: Programming Language 2 1 Functions. 2 Function declaration: return_type FuncName( Type arg1, Type arg2,….. Type argN) { function body } A program.
1 Introduction to Object Oriented Programming Chapter 10.
Polymorphism and Virtual Functions One name many shapes behaviour Unit - 07.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 19 – Introduction to C++
C++ Namespaces, Exceptions CSci 588: Data Structures, Algorithms and Software Design All material not from online sources copyright © Travis Desell, 2011.
Object-Oriented Programming (OOP) and C++
Console Programs Console programs are programs that use text to communicate with the use and environment – printing text to screen, reading input from.
Week 13 - Friday.  What did we talk about last time?  Server communications on a socket  Function pointers.
CSE 374 Programming Concepts & Tools
Hank Childs, University of Oregon
Eugene Hsu.
Finally! Discussing a language!
The dirty secrets of objects
group work #hifiTeam
Brought to you by C++ Tutorial Brought to you by
Classes, Constructors, etc., in C++
Today’s Objectives 28-Jun-2006 Announcements
Input / output (i/o) Acknowledgement: THE Slides are Prepared FROM SLIDES PROVIDED By NANCY M. AMATO AND Jory Denny.
Presentation transcript:

CS 11 C++ track: lecture 1 Administrivia Need a CS cluster account sysadmin/account_request.cgi Need to know UNIX (Linux) unix/unixtutorial.shtml Need to know C at level of CS 11 C track Track home page: material/cpp/mike/index.html

Assignments 1st assignment is posted now due one week after class, midnight late penalty: 1 mark/day redos

Textbook suggested: Essential C++ by Stanley Lippman covers more material than this track Stroustrup NOT recommended! except as reference

Why use C++? speed and low-level control of C higher level of abstraction than C object-oriented programming generic programming can define own data types that work like built-in data types

What's not to like about C++? incredibly complex! tons of features that don’t always interact well takes a long time to master suffers from many of C’s problems memory leaks, crashes much less safe/portable than java "language for experts"

Some features of C++ everything that’s in C object-oriented programming very powerful (and complex!) generic programming (templates) list, multiset exception handling better way to deal with errors

Getting started The “hello, world!” program: #include // Access values in namespace “std”: using namespace std; int main() { cout << “hello, world!” << endl; return 0; }

Compiling Save as “hello.cc” and do: % g++ -Wall hello.cc -o hello % hello hello, world! woo hoo!

Alternatively... The “hello, world!” program: #include int main() { std::cout << “hello, world!” << std::endl; return 0; } std:: says use name in “std” namespace

cin and cout (1) Don’t use printf() or scanf() for i/o Use cout for output, cin for input int i = 10; double d = ; string s = "I am a string!"; cout << "i = " << i << " d = " << d << " s = " << s << endl;

cin and cout (2) int i; double d; string s; cout << "enter i: "; cin >> i; cout << "enter d: "; cin >> d; cout << "enter s: "; cin >> s; cout << "i = " << i << " d = " << d << " s = " << s << endl;

Objects An object consists of: data functions (methods) that act on data Idea: rest of program only interacts with an object by calling its methods data in object stays private to that object C++ supports objects directly

Classes A class is a template for building an object most C++ code consists of class descriptions Classes include: constructors (functions that create instances of the class i.e. new objects of that class) data members or fields (data associated with each instance) member functions or methods (functions that can act directly on the data members) destructors (functions that destroy instances)

Example: 2d point class Point { private: int x_coord, y_coord; public: Point(); // constructor Point(int x, int y); // constructor void setX(int val); // mutator int getX(); // accessor ~Point(); // destructor };

Example: 2d point class Point { private: int x_coord, y_coord; public: Point(); // constructor Point(int x, int y); // constructor void setX(int val); // mutator int getX(); // accessor ~Point(); // destructor }; class

Example: 2d point class Point { private: int x_coord, y_coord; public: Point(); // constructor Point(int x, int y); // constructor void setX(int val); // mutator int getX(); // accessor ~Point(); // destructor }; data members (fields)

Example: 2d point class Point { private: int x_coord, y_coord; public: Point(); // constructor Point(int x, int y); // constructor void setX(int val); // mutator int getX(); // accessor ~Point(); // destructor }; constructors

Example: 2d point class Point { private: int x_coord, y_coord; public: Point(); // constructor Point(int x, int y); // constructor void setX(int val); // mutator int getX(); // accessor ~Point(); // destructor }; member functions (methods)

Example: 2d point class Point { private: int x_coord, y_coord; public: Point(); // constructor Point(int x, int y); // constructor void setX(int val); // mutator int getX(); // accessor ~Point(); // destructor }; destructor

Example: 2d point Put previous code in “Point.hh” file Implementation goes in “Point.cc” file: #include “Point.hh” Point::Point(int x, int y) { x_coord = x; y_coord = y; } void Point::setX(int val) { x_coord = val; } // etc.

Using 2d points Using 2d points in other code: //... Point p(); // calls no-arg ctor Point p2(10, 10); // calls 2-arg ctor cout << p2.getX() << endl; // call method p.setX(20); // etc.

Destructors What about destructors? destructor is automatically called at end of block where Point objects created useful when allocating memory dynamically not mandatory (not really needed here)

References (1) contrast: void setXto10(Point p) { // copies p p.setX(10); } with: void setXto10(Point *p) { // doesn't copy p->setX(10); // (*p).setX(10); }

References (2) C++ shortcut: void setXto10(Point &p) { // note the & p.setX(10); } no copy is made like pointers, but with nicer syntax use this instead of pointers when possible

Odds and ends C header files are included differently #include // not meaning is the same don’t mix and in the same code! results are “unpredictable”

That's all for now! First lab will walk you through these steps. Should be pretty easy. Future labs will be much more complicated matrix classes (regular, sparse) operator overloading templates inheritance So stay tuned!