Fortgeschrittene Programmierung in C++ Vorbesprechung & 1. Vorlesung
|
|
|
- Andra Franklin
- 9 years ago
- Views:
Transcription
1 Fortgeschrittene Programmierung in C++ Vorbesprechung & 1. Vorlesung Thomas Gschwind <thg at zurich ibm com> 2013 IBM Corporation
2 Overview Administrative Issues Prerequisites & Goals Schedule Exams & Grading C++ Introduction ( Hello World ) Functions and Operators Object-Based Programming (Classes and Structures) Namespaces 2
3 Prerequisites Programming Languages Java, maybe better C Basic knowledge of object-oriented programming For students in the third semester or later 3
4 Goals Learn to use different programming paradigms Procedural programming Object-based programming (templates, static polymorphism) Object-oriented programming (inheritance, dynamic polymorphism) Hot Topics Typing Strong vs. weak typing Static vs. dynamic typing Templates Exception Handling Standard Library Arduino UNO SDK uses C++ Provides 32k Flash 4
5 Grading Exercises will be handed out after each lecture Exercises SHOULD be solved in groups of two Exercises will be evaluated during two oral evaluation sessions Oral Lab Submission 1: Exercises from lectures 1 to 5 Oral Lab Submission 2: Exercises from lectures 6 to 10 Written exam at the end of the course No material is allowed during the exam Exam supervisor can be used as API reference during the exam Yes, you will be asked to write code on paper Approx % theory, 30-50% practical questions Exam MAY be oral if less than 10 students attending Grading Exercises determine 1/3 of the final grade Exam determines 2/3 of the final grade 5
6 Organization & Schedule Announcements via the course web page Urgent announcements by (mailing list seal-cpp) Approx. 12 lectures, 1.5 hours each Thu. 8:10-9:45 BIN 2.A.10. Tentatively, no lectures will be taught on Oct 23 and Dec 11 (however may change depending on my IBM activities) For a complete schedule, please check the web Exercise submissions and Exam Exercises due: Thu. Oct 30, 8:00 BIN 2.A.10, TBD: Thu. Dec. 18, 8:00 BIN 2.A.10 OR Thu. Jan. 8, 10:00. Exam on: Thu. Jan. 8, 8:10 BIN 2.A.10. 6
7 Q & A? Course material? Slides Books? Bjarne Stroustrup. The C++ Programming Language (4th. ed.). Addison-Wesley. Stanley B. Lippman, Josée Lajoie, Barbara E. Moo. C++ Primer. Addison-Wesley. Check out your local book store Which operating system/c++ compiler? Unix/Windows/OSX GNU C++ (strongly recommended) 7
8 A Request from Your Lecturer If anything is unclear Please ask questions This makes the lecture more lively and interesting If you find mistakes in the slides Please point them out, if you are unsure, privately after the lecture Improves the quality of the lecture When I compare C++ with other programming languages Of course, I will stress the advantages of C++ Yes, C++ has its downsides, we will address them as well After all, a programming languages are tools You SHOULD be able to use any of them to develop readable programs 8
9 Overview Administration Issues Prerequisites & Goals Schedule Exams & Grading C++ Introduction ( Hello World ) Functions and Operators Object-Based Programming (Classes and Structures) Namespaces 9
10 Introduction Historically speaking, C++ is an Algol like programming language (like Pascal, or Java without OO features) C++ builds on the C language of which it is a superset (except for comments, struct, enum, ) C++ adds several features to C such as Inheritance Templates Exceptions C++ supports different programming paradigms Procedural programming Object-based programming Object-oriented programming 10
11 Hello World This is the C++ way of saying import. No class statement necessary. C++ s fancy way of saying System.out. #include <iostream> hello.cc using namespace std; int main(int argc, char *argv[]) { cout << "Hello World!" << endl; return 0; } This stands for print. Move to the next line. 11
12 Hello World : Compilation C++ is typically compiled to native code Every file is compiled to an object file Finally, files are linked tom@navelli:~/ak3-01$ g++ -c hello.cc tom@navelli:~/ak3-01$ g++ -o hello hello.o tom@navelli:~/ak3-01$./hello Hello World! tom@navelli:~/ak3-01$ This executes our program. *shell* This compiles our source file and generates an object file. This links the object file. 12
13 Functions May occur outside of classes This is useful for routines that do not naturally belong to a specific class Support a variety of parameter passing options Supports overloading Different functions may have the same name The argument types are used to resolve the function to be executed The return type is not considered for overloading resolution (This would overly complicate the function resolution algorithm) Functions can be used to define new operators Functions may be inlined This may be requested using the inline keyword Instead of invoking the function, the functions code will be replicated whenever the function should be invoked 13
14 Functions: Parameter Passing Call by Value Argument to be passed copied from the caller s scope into the callee s scope Callee operates on its own copy Call by Reference/Pointer Callee receives a references to the argument passed by the caller Callee operates on caller s copy C++/C All parameters can be passed by value, by pointer, or in C++ also by reference Java Primitive types are passed by value Class instances are passed by reference C# Value types (primitives and structs) by value or reference Class instances by reference 14
15 Functions: References Point to the address of the argument in the caller s scope Argument in caller s scope must be an lvalue Similar to VAR parameter in Pascal ref parameter in C# Using pointers in C c++-swap.cc void swap(int &a, int &b) { int c=a; a=b; b=c; } 15
16 Functions: Pointers Pointer s are similar to references Caller has to pass a pointer to an object in his scope using the & operator => more explicit Pointers are traditionally used in C c-swap.c void c_swap(int *a, int *b) { int c=*a; *a=*b; *b=c; } // printf("&a=%p, a=%p, *a=%d\n", &a, a, *a); // printf("&b=%p, b=%p, *b=%d\n", &b, b, *b); 16
17 Functions: inline Replaces the function call with the function s body Code needs to be known during compile time When to use it? Useful for small functions Sometimes also for larger ones Faster and more compact code For C Developers Combines advantages of macros and functions Own area for parameters and variables No side effects As efficient as macros (if possible) 17
18 Functions: A Comprehensive Example #include <cstdlib> #include <iostream> using namespace std; functions.cc inline void swap(int &a, int &b) { int c=a; a=b; b=c; } int gcf(int a, int b) { if (a<b) swap(a, b); while (b!=0) { a=a-b; if (a<b) swap(a, b); } return a; } inline int lcm(int a, int b) { return (a/gcf(a,b))*b; } void main(int argc, char *argv[]) { cout << gcf(atoi(argv[1]), atoi(argv[2])) << endl; cout << lcm(atoi(argv[1]), atoi(argv[2])) << endl; } 18
19 Operators C++ supports user-defined operators Operators are mapped onto a binary function with the name operator prepended to the operator struct fraction { // type def int cntr; int denom; }; fraction operator*(fraction a, fraction b) { fraction c; c.cntr=a.cntr*b.cntr; c.denom=a.denom*b.denom; return c; } fraction foo(fraction a, fraction b, fraction c) { return a+b*c; } 19
20 Operators: Input & Output Two operators are used for input and output Input operator>> Output operator<< cout << Hello World! << endl; (cout << Hello World! ) << endl; operator<<(cout, Hello World! ); operator<<(cout, endl); operator<<( operator<<(cout, Hello World! ), endl); 20
21 Operators: Guidelines Some people consider operator overloading Because one could overload them in meaningless ways In this respect adhere to their established mathematical properties foo==foo Reflexivity foo==bar bar==foo Symetry foo==bar bar==foobar foo==foobar Transitivity foo!=bar!(foo==bar) Consider mathematical laws foo+=bar foo=foo+bar Associativity, Commutivity, 21
22 Operators User-definable operators +, -, *, /, %, ^, &,, ~,!, =, <, >, +=, -=, *=, /=, %=, ^=, &=, =, <<, >>, >>=, <<=, ==,!=, <=, >=, &&,, ++, --, ->*,,, ->, [], (), new, new[], delete, delete[] Not user-definable ::,.,.* 22
23 Object-Based Programming (Classes and Structures) Encapsulation Add structure to the program Explicit interface (Access to class checked by compiler) User only needs to know this interface Hide implementation details Useful for abstract data types such as stack, vector, map, User-defined types Allows developers to develop types that behave like primitive types One of the key differences between C++ and C (or Java) 23
24 Classes: Declaration and Definition (C++ and Java) // same as class fraction { // type def { cntr=c; denom=d; } private: int cntr; int denom; public: fraction(int c=0, int d=1) : cntr(c), denom(d) {} }; int get_counter() { return cntr; } void set_counter(int cntr) { this->cntr=cntr; } fraction operator*(fraction b) { return result; } class Fraction { // type def private int cntr; private int denom; }; public Fraction(int c, int d) { cntr=c; denom=d; } public int getcounter() { return cntr; } public void setcounter(int cntr) { this.cntr=cntr; } public Fraction mul(fraction b) { return denom; } 24
25 Classes: Using them In Java void main(string[] args) { Fraction f=new Fraction(Integer.parseInt(args[1]), Integer.parseInt(args[2])); } System.out.println(f.getCounter()+":"+ f.getdenominator()); In C++ void main(int argc, char *argv[]) { fraction f(atoi(argv[1]), atoi(argv[2])); } cout << f.get_counter() << ":" << f.get_denominator() << endl; 25
26 Classes: Access Control (Encapsulation) public: Members declared in this section maybe used everywhere (default for structures) private: Things declared here may only be used by this class Useful for helper methods and attributes (default for classes) protected: Things declared here may only be used by this class and its subclasses friend Something different but somewhat similar to package in Java 26
27 Classes: Construction & Destruction Constructor (T) Executed after memory allocated for an object Destructor (~T) Executed before memory will be deallocated for an object Similar but better than Java s finalize() method (well defined when it will be executed) Allows you to free additional resources class Fraction { public: Fraction(...) { // } ~Fraction() { // } }; // Constructor // Destructor 27
28 Classes: Constructors Default Constructor (T()) Created by the compiler, if not defined by yourself Initializes attributes with default constructor Copy Constructor (T(const T&)) Created by the compiler, if not defined by yourself Copies each attribute from the source to the target object ( shallow copy ) This constructor is executed frequently Whenever a parameter is passed by value Whenever an value is returned from a function (not if a pointer or reference to the value is returned) 28
29 Classes: Default Artifacts Each class gets the following artifacts for free (that is, if they are not declared, C++ will provide them) Default constructor Copy constructor Destructor Assignment operator 29
30 Classes: Constructors class fraction { // type declaration+definition int c; int d; public: fraction(int cntr=0, int denom=1) : c(cntr), d(denom) {} // possibly redundant fraction(const fraction &f) : c(f.c), d(f.d) {} ~fraction() {} fraction &operator=(fraction b) { c=b.c; d=b.d; } fraction operator+(fraction b); fraction operator-(fraction b); }; Yes, that s the same as the compiler-generated one, but many people consider it as good practice to define it yourself anyways What s this? This initializes the members of this class in a more efficient way (for built-in types it s actually the same) 30
31 Classes: Disable Default Artifacts If we do not want the default artifacts, we can block their creation Why would I not want it? E.g., an object should not ever be duplicated by accident Hide the default constructor Declare in the private part of the class What if not even the class itself may use it? Declare it in the class => Compiler won t create one for you But never implement it => Linker will complain if you ever use it 31
32 Classes: Rule of Three The Rule of Three states that if you define either of them, you most likely need to define all three of them Copy Constructor Assignment Operator Destructor In any case, follow this rule and even if you do not need the others, just provide the same as the compiler-generated code to show that you did not forget about the others 32
33 Classes: Friends Allow other functions and classes access to protected and private members Useful for Functions, operators, etc. that logically belong to a class but cannot be defined as member thereof Classes having a close relationship to each other 33
34 Classes: Friend Example fraction.h class fraction { friend ostream &operator<<(ostream &os, fraction f); friend istream &operator>>(istream &is, fraction &f); }; fraction.cc ostream &operator<<(ostream &os, fraction f) { os << '(' << f.c << /' << f.d << ')'; return os; } inline void check_char(istream &is, char ch) { char c; is >> c; if(c!=ch) { is.putback(c); is.setstate(ios::badbit); } } istream &operator>>(istream &is, fraction &f) { fraction g; check_char('('); is >> g.c; check_char('/'); is >> g.d; check_char(')'); if(is) f=g; return is; } 34
35 Classes: User-Defined Conversions class fraction { public: User-defined conversion // conversion fraction to double operator double() { return (double)c/d; } fraction operator+(fraction b); fraction operator-(fraction b); }; double solve(double p, double q) { return... } Will invoke our userdefined conversion 35 void foo(fraction &a, fraction &b) { cout << "The result is " << solve(a,b) << endl; // implicit cout << "a+b=" << (double)(a+b) << endl; // explicit } Style-wise, in C++, one should use static_cast<double>(a+b)
36 Classes: Change Through References class fraction { public: References as return // conversion fraction to double type, BUT be careful operator double() { return (double)c/d; } // references as return value int &counter() { return c; } int &denominator() { return d; } fraction operator+(fraction b); fraction operator-(fraction b); }; That s how they are used void foo(fraction &a, fraction &b) { cout << "a+b=" << (a+b) << "=" << (double)(a+b) << endl; a.counter()=b.denominator(); } Style-wise, in this example, a.set_counter(b.denominator()) would have been more beautiful. 36
37 Namespaces Modular programming Avoid name collisions User defined data-types fraction.h namespace fractions { // } int gcf(int a, int b); int lcm(int a, int b); int swap(int &a, int &b); // Namespace declarations need to be repeated again in the corresponding.cc file 37
38 Namespaces (cont d) Multiple namespace statements are allowed within a single source file Namespaces may be nested Namespaces may anonymous fraction.h namespace util { int gcf(int a, int b); int lcm(int a, int b); int swap(int &a, int &b); } namespace fraction { class fraction { }; } 38
39 Using Namespaces Scoping :: Operator Example: util::gcf(foo,bar); Import a single name of a given namespace using declaration Example: using NAMESPACE::VAR; Import all names defined in a given namespace using directive Example: using namespace NAMESPACE; 39
40 Namespaces: Operators Operators can be defined in multiple ways and scopes As member function: fraction fraction::operator+(complex b); Stand-alone: fraction operator+(fraction a, complex b); As stand-alone operator, in the current namespace, or that of fraction, or that of complex Wow! So which one will be used? 40
41 Namespaces: Operators Example: fraction a; complex b; cout << a+b << endl; A a; B b; cout << a+b << endl; 1. Does A have a member operator+(b) => yes => use it, if it has multiple, use standard overloading rules 2. Is there an operator+(a,b) defined in the namespace where A or B is defined in? => yes => use it, if it has multiple, use standard overloading rules 41
42 Summary Administrative Issues Prerequisites & Goals Schedule Exams & Grading C++ Introduction ( Hello World ) Functions and Operators Object-Based Programming (Classes and Structures) Namespaces 42
43 Exercise 0 Visit your local book store Check out the books recommended in this lecture and some others Optional, if you really like one, go for it Install a C++ Compiler Unix: apt-get/yum g++ make (if not, check with your distribution) Windows: install the cygwin tools at least base/bash, devel/gcc-c++ and devel/make (dependencies will be selected automatically) Apple Users: use Xcode, may be downloaded from Apple Developer Web Site or App Store Possibly in combination with Eclipse (may simplify debugging) 43
44 Exercise 0 Some Pointers First install the C++ Compiler Install the following packages from shells/bash, devel/gcc-g++, devel/make Eclipse Users Go to and download Eclipse IDE for C/C++ Developers In the past, eclipse/eclipsec should have been run from your cygwin shell (to ensure that paths are set up correctly) 44
45 Exercise 1 Implement and run the Hello World program from this lecture 45
46 Exercise 2 Have a look at the two swap routines swap(int&,int&) and c_swap(int*,int*) Let the compiler compile the code but ask the compiler to stop at the assembly stage $ gcc S o source.s source.cc Compare the assembly code, what do you observe? How do you interpret the difference? 46
47 Exercise 3 Implement the comprehensive function example twice Once with the swap and lcm functions declared inline Once with those functions declared as normal functions Compile the two programs and generate assembly code How many instructions do the different functions have for the two different versions of the example? How do you interpret the differences? 47
48 Exercise 4 Implement a data type for complex numbers Implement the +, -, *, / operators Implement the << and >> operators Provide two test drivers One that checks based on a few samples that your code is correct One that interactively lets a user invoke some operations with complex numbers 48
49 Next Lecture Separate Compilation in C++ Introduction to C++ s Standard Library 49
50 Questions? Happy Coding and see you next Thursday 50
CpSc212 Goddard Notes Chapter 6. Yet More on Classes. We discuss the problems of comparing, copying, passing, outputting, and destructing
CpSc212 Goddard Notes Chapter 6 Yet More on Classes We discuss the problems of comparing, copying, passing, outputting, and destructing objects. 6.1 Object Storage, Allocation and Destructors Some objects
Comp151. Definitions & Declarations
Comp151 Definitions & Declarations Example: Definition /* reverse_printcpp */ #include #include using namespace std; int global_var = 23; // global variable definition void reverse_print(const
C++ INTERVIEW QUESTIONS
C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get
Operator Overloading. Lecture 8. Operator Overloading. Running Example: Complex Numbers. Syntax. What can be overloaded. Syntax -- First Example
Operator Overloading Lecture 8 Operator Overloading C++ feature that allows implementer-defined classes to specify class-specific function for operators Benefits allows classes to provide natural semantics
An Incomplete C++ Primer. University of Wyoming MA 5310
An Incomplete C++ Primer University of Wyoming MA 5310 Professor Craig C. Douglas http://www.mgnet.org/~douglas/classes/na-sc/notes/c++primer.pdf C++ is a legacy programming language, as is other languages
C++ Crash Kurs. C++ Object-Oriented Programming
C++ Crash Kurs C++ Object-Oriented Programming Dr. Dennis Pfisterer Institut für Telematik, Universität zu Lübeck http://www.itm.uni-luebeck.de/people/pfisterer C++ classes A class is user-defined type
Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas
CS 110B - Rule Storage Classes Page 18-1 Attributes are distinctive features of a variable. Data type, int or double for example, is an attribute. Storage class is another attribute. There are four storage
C++FA 5.1 PRACTICE MID-TERM EXAM
C++FA 5.1 PRACTICE MID-TERM EXAM This practicemid-term exam covers sections C++FA 1.1 through C++FA 1.4 of C++ with Financial Applications by Ben Van Vliet, available at www.benvanvliet.net. 1.) A pointer
El Dorado Union High School District Educational Services
El Dorado Union High School District Course of Study Information Page Course Title: ACE Computer Programming II (#495) Rationale: A continuum of courses, including advanced classes in technology is needed.
PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?
1. Distinguish & and && operators. PART-A Questions 2. How does an enumerated statement differ from a typedef statement? 3. What are the various members of a class? 4. Who can access the protected members
CEC225 COURSE COMPACT
CEC225 COURSE COMPACT Course GEC 225 Applied Computer Programming II(2 Units) Compulsory Course Duration Two hours per week for 15 weeks (30 hours) Lecturer Data Name of the lecturer: Dr. Oyelami Olufemi
Ch 7-1. Object-Oriented Programming and Classes
2014-1 Ch 7-1. Object-Oriented Programming and Classes May 10, 2014 Advanced Networking Technology Lab. (YU-ANTL) Dept. of Information & Comm. Eng, Graduate School, Yeungnam University, KOREA (Tel : +82-53-810-2497;
CSC230 Getting Starting in C. Tyler Bletsch
CSC230 Getting Starting in C Tyler Bletsch What is C? The language of UNIX Procedural language (no classes) Low-level access to memory Easy to map to machine language Not much run-time stuff needed Surprisingly
CORBA Programming with TAOX11. The C++11 CORBA Implementation
CORBA Programming with TAOX11 The C++11 CORBA Implementation TAOX11: the CORBA Implementation by Remedy IT TAOX11 simplifies development of CORBA based applications IDL to C++11 language mapping is easy
Object Oriented Software Design II
Object Oriented Software Design II Introduction to C++ Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 20, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February
IS0020 Program Design and Software Tools Midterm, Feb 24, 2004. Instruction
IS0020 Program Design and Software Tools Midterm, Feb 24, 2004 Name: Instruction There are two parts in this test. The first part contains 50 questions worth 80 points. The second part constitutes 20 points
C++ Overloading, Constructors, Assignment operator
C++ Overloading, Constructors, Assignment operator 1 Overloading Before looking at the initialization of objects in C++ with constructors, we need to understand what function overloading is In C, two functions
CISC 181 Project 3 Designing Classes for Bank Accounts
CISC 181 Project 3 Designing Classes for Bank Accounts Code Due: On or before 12 Midnight, Monday, Dec 8; hardcopy due at beginning of lecture, Tues, Dec 9 What You Need to Know This project is based on
Introduction to C++ Introduction to C++ Week 7 Dr Alex Martin 2013 Slide 1
Introduction to C++ Introduction to C++ Week 7 Dr Alex Martin 2013 Slide 1 Introduction to Classes Classes as user-defined types We have seen that C++ provides a fairly large set of built-in types. e.g
KITES TECHNOLOGY COURSE MODULE (C, C++, DS)
KITES TECHNOLOGY 360 Degree Solution www.kitestechnology.com/academy.php [email protected] [email protected] Contact: - 8961334776 9433759247 9830639522.NET JAVA WEB DESIGN PHP SQL, PL/SQL
Konzepte objektorientierter Programmierung
Konzepte objektorientierter Programmierung Prof. Dr. Peter Müller Werner Dietl Software Component Technology Exercises 3: Some More OO Languages Wintersemester 04/05 Agenda for Today 2 Homework Finish
How To Teach C++ Data Structure Programming
UTSA EE 3223 - C++ Data Structures Syllabus Fall 2015 Part A - Course Outline Catalog Description: 3 hours credit. Review of C/C++ non-object oriented programming concepts. Object-oriented programming
Parameter Passing. Parameter Passing. Parameter Passing Modes in Fortran. Parameter Passing Modes in C
Parameter Passing In this set of notes you will learn about: Parameter passing modes Call by Call by reference Call by sharing Call by result Call by /result Call by name Subroutine closures as parameters
AP Computer Science Java Subset
APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall
6.S096 Lecture 1 Introduction to C
6.S096 Lecture 1 Introduction to C Welcome to the Memory Jungle Andre Kessler Andre Kessler 6.S096 Lecture 1 Introduction to C 1 / 30 Outline 1 Motivation 2 Class Logistics 3 Memory Model 4 Compiling 5
C++ Outline. cout << "Enter two integers: "; int x, y; cin >> x >> y; cout << "The sum is: " << x + y << \n ;
C++ Outline Notes taken from: - Drake, Caleb. EECS 370 Course Notes, University of Illinois Chicago, Spring 97. Chapters 9, 10, 11, 13.1 & 13.2 - Horstman, Cay S. Mastering Object-Oriented Design in C++.
Chapter 5 Functions. Introducing Functions
Chapter 5 Functions 1 Introducing Functions A function is a collection of statements that are grouped together to perform an operation Define a function Invoke a funciton return value type method name
Object Oriented Software Design II
Object Oriented Software Design II C++ intro Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 26, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 26,
Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is
Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is preceded by an equal sign d. its name has undereline 2. Associations
COS 217: Introduction to Programming Systems
COS 217: Introduction to Programming Systems 1 Goals for Todayʼs Class Course overview Introductions Course goals Resources Grading Policies Getting started with C C programming language overview 2 1 Introductions
Basics of I/O Streams and File I/O
Basics of This is like a cheat sheet for file I/O in C++. It summarizes the steps you must take to do basic I/O to and from files, with only a tiny bit of explanation. It is not a replacement for reading
Schedule. Structures and Classes in C++ Outline. Goals for This Topic. Another Example of a Structure. What is a Structure? Classes May 12-17, 2005
Classes May -7, 005 Schedule Structures and Classes in C++ Larry Caretto Computer Science 06 Computing in Engineering and Science May and 7, 005 Today and Tuesday: Lecture on classes Thursday (May 9) Project
Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.
Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to
Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program
Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2015 The third
Visual Studio 2008 Express Editions
Visual Studio 2008 Express Editions Visual Studio 2008 Installation Instructions Burning a Visual Studio 2008 Express Editions DVD Download (http://www.microsoft.com/express/download/) the Visual Studio
Computer Programming C++ Classes and Objects 15 th Lecture
Computer Programming C++ Classes and Objects 15 th Lecture 엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University Copyrights 2013 Eom, Hyeonsang All Rights Reserved Outline
More C++ Concepts. Operator overloading Friend Function This Operator Inline Function
More C++ Concepts Operator overloading Friend Function This Operator Inline Function 1 Review There are different types of member functions in the definition of a class Accessor int Str :: get_length();
A deeper look at Inline functions
A deeper look at Inline functions I think it s safe to say that all Overload readers know what C++ inline functions are. When we declare a function or member function as inline we are trying to avoid the
The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1
The Java Series Java Essentials I What is Java? Basic Language Constructs Slide 1 What is Java? A general purpose Object Oriented programming language. Created by Sun Microsystems. It s a general purpose
Class 16: Function Parameters and Polymorphism
Class 16: Function Parameters and Polymorphism SI 413 - Programming Languages and Implementation Dr. Daniel S. Roche United States Naval Academy Fall 2011 Roche (USNA) SI413 - Class 16 Fall 2011 1 / 15
C++ Programming Language
C++ Programming Language Lecturer: Yuri Nefedov 7th and 8th semesters Lectures: 34 hours (7th semester); 32 hours (8th semester). Seminars: 34 hours (7th semester); 32 hours (8th semester). Course abstract
Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program
Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2014 Jill Seaman
Java Interview Questions and Answers
1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java
OpenCL Static C++ Kernel Language Extension
OpenCL Static C++ Kernel Language Extension Document Revision: 04 Advanced Micro Devices Authors: Ofer Rosenberg, Benedict R. Gaster, Bixia Zheng, Irina Lipov December 15, 2011 Contents 1 Overview... 3
Brent A. Perdue. July 15, 2009
Title Page Object-Oriented Programming, Writing Classes, and Creating Libraries and Applications Brent A. Perdue ROOT @ TUNL July 15, 2009 B. A. Perdue (TUNL) OOP, Classes, Libraries, Applications July
13 Classes & Objects with Constructors/Destructors
13 Classes & Objects with Constructors/Destructors 13.1 Introduction In object oriented programming, the emphasis is on data rather than function. Class is a way that binds the data & function together.
CSI33 Data Structures
Outline Department of Mathematics and Computer Science Bronx Community College November 25, 2015 Outline Outline 1 Chapter 12: C++ Templates Outline Chapter 12: C++ Templates 1 Chapter 12: C++ Templates
Object Oriented Software Design
Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 14, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction
INTRODUCTION TO OBJECTIVE-C CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 12 09/29/2011
INTRODUCTION TO OBJECTIVE-C CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 12 09/29/2011 1 Goals of the Lecture Present an introduction to Objective-C 2.0 Coverage of the language will be INCOMPLETE
Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.
Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java
Object-Oriented Programming
Object-Oriented Programming Programming with Data Types to enhance reliability and productivity (through reuse and by facilitating evolution) Object (instance) State (fields) Behavior (methods) Identity
Object Oriented Programming With C++(10CS36) Question Bank. UNIT 1: Introduction to C++
Question Bank UNIT 1: Introduction to C++ 1. What is Procedure-oriented Programming System? Dec 2005 2. What is Object-oriented Programming System? June 2006 3. Explain the console I/O functions supported
Introduction to Programming System Design. CSCI 455x (4 Units)
Introduction to Programming System Design CSCI 455x (4 Units) Description This course covers programming in Java and C++. Topics include review of basic programming concepts such as control structures,
CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship.
CSCI 253 Object Oriented Design: Java Review OOP George Blankenship George Blankenship 1 Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation Abstract Data Type (ADT) Implementation
The programming language C. sws1 1
The programming language C sws1 1 The programming language C invented by Dennis Ritchie in early 1970s who used it to write the first Hello World program C was used to write UNIX Standardised as K&C (Kernighan
Software Engineering Concepts: Testing. Pointers & Dynamic Allocation. CS 311 Data Structures and Algorithms Lecture Slides Monday, September 14, 2009
Software Engineering Concepts: Testing Simple Class Example continued Pointers & Dynamic Allocation CS 311 Data Structures and Algorithms Lecture Slides Monday, September 14, 2009 Glenn G. Chappell Department
Binary storage of graphs and related data
EÖTVÖS LORÁND UNIVERSITY Faculty of Informatics Department of Algorithms and their Applications Binary storage of graphs and related data BSc thesis Author: Frantisek Csajka full-time student Informatics
Copyright 2001, Bill Trudell. Permission is granted to copy for the PLoP 2001 conference. All other rights reserved.
The Secret Partner Pattern Revision 3a by Bill Trudell, July 23, 2001 Submitted to the Pattern Languages of Programs Shepherd: Neil Harrison PC Member: Kyle Brown Thumbnail This paper describes the Secret
Function Overloading I
Function Overloading I we can overload functions on their arguments like so: void foo (int iarg) { cout
Sequential Program Execution
Sequential Program Execution Quick Start Compile step once always g++ -o Realtor1 Realtor1.cpp mkdir labs cd labs Execute step mkdir 1 Realtor1 cd 1 cp../0/realtor.cpp Realtor1.cpp Submit step cp /samples/csc/155/labs/1/*.
BCS2B02: OOP Concepts and Data Structures Using C++
SECOND SEMESTER BCS2B02: OOP Concepts and Data Structures Using C++ Course Number: 10 Contact Hours per Week: 4 (2T + 2P) Number of Credits: 2 Number of Contact Hours: 30 Hrs. Course Evaluation: Internal
1 bool operator==(complex a, Complex b) { 2 return a.real()==b.real() 3 && a.imag()==b.imag(); 4 } 1 bool Complex::operator==(Complex b) {
Operators C and C++ 6. Operators Inheritance Virtual Alastair R. Beresford University of Cambridge Lent Term 2008 C++ allows the programmer to overload the built-in operators For example, a new test for
Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)
Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the
More on Objects and Classes
Software and Programming I More on Objects and Classes Roman Kontchakov Birkbeck, University of London Outline Object References Class Variables and Methods Packages Testing a Class Discovering Classes
Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation
Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science updated 03/08/2012 Unit 1: JKarel 8 weeks http://www.fcps.edu/is/pos/documents/hs/compsci.htm
Constructor, Destructor, Accessibility and Virtual Functions
Constructor, Destructor, Accessibility and Virtual Functions 182.132 VL Objektorientierte Programmierung Raimund Kirner Mitwirkung an Folienerstellung: Astrit Ademaj Agenda Constructor Destructors this
Compiler Construction
Compiler Construction Lecture 1 - An Overview 2003 Robert M. Siegfried All rights reserved A few basic definitions Translate - v, a.to turn into one s own language or another. b. to transform or turn from
Chapter 5 Names, Bindings, Type Checking, and Scopes
Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Type Checking Strong Typing Scope Scope and Lifetime Referencing Environments Named
Integrating the C++ Standard Template Library Into the Undergraduate Computer Science Curriculum
Integrating the C++ Standard Template Library Into the Undergraduate Computer Science Curriculum James P. Kelsh [email protected] Roger Y. Lee [email protected] Department of Computer Science Central
Syllabus OBJECT ORIENTED PROGRAMMING C++
1 Syllabus OBJECT ORIENTED PROGRAMMING C++ 1. Introduction : What is object oriented programming? Why do we need objectoriented. Programming characteristics of object-oriented languages. C and C++. 2.
The C Programming Language course syllabus associate level
TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming
Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C
Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C 1 An essential part of any embedded system design Programming 2 Programming in Assembly or HLL Processor and memory-sensitive
Syllabus Introduction to C++ Programming and Numerical Analysis Spring 2016
Syllabus Introduction to C++ Programming and Numerical Analysis Spring 2016 lead instructor: office: web: class time: Professor Johan Walden F655 [email protected] http://www.haas.berkeley.edu/faculty/walden.html
CS 103 Lab Linux and Virtual Machines
1 Introduction In this lab you will login to your Linux VM and write your first C/C++ program, compile it, and then execute it. 2 What you will learn In this lab you will learn the basic commands and navigation
Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies)
Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies) Duration of Course: 6 Months Fees: Rs. 25,000/- (including Service Tax) Eligibility: B.E./B.Tech., M.Sc.(IT/ computer
Sources: On the Web: Slides will be available on:
C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,
Part I. Multiple Choice Questions (2 points each):
Part I. Multiple Choice Questions (2 points each): 1. Which of the following is NOT a key component of object oriented programming? (a) Inheritance (b) Encapsulation (c) Polymorphism (d) Parallelism ******
First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science
First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca
Objectif. Participant. Prérequis. Remarque. Programme. C# 3.0 Programming in the.net Framework. 1. Introduction to the.
Objectif This six-day instructor-led course provides students with the knowledge and skills to develop applications in the.net 3.5 using the C# 3.0 programming language. C# is one of the most popular programming
PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON
PROBLEM SOLVING WITH SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON Addison Wesley Boston San Francisco New York London
Parameter Passing. Standard mechanisms. Call by value-result Call by name, result
Parameter Passing Standard mechanisms Call by value Call by reference Other methods Call by value-result Call by name, result Terms Function definition where the details of the function are presented (type,
An Introduction to Assembly Programming with the ARM 32-bit Processor Family
An Introduction to Assembly Programming with the ARM 32-bit Processor Family G. Agosta Politecnico di Milano December 3, 2011 Contents 1 Introduction 1 1.1 Prerequisites............................. 2
Fundamentals of Java Programming
Fundamentals of Java Programming This document is exclusive property of Cisco Systems, Inc. Permission is granted to print and copy this document for non-commercial distribution and exclusive use by instructors
Course MS10975A Introduction to Programming. Length: 5 Days
3 Riverchase Office Plaza Hoover, Alabama 35244 Phone: 205.989.4944 Fax: 855.317.2187 E-Mail: [email protected] Web: www.discoveritt.com Course MS10975A Introduction to Programming Length: 5 Days
Glossary of Object Oriented Terms
Appendix E Glossary of Object Oriented Terms abstract class: A class primarily intended to define an instance, but can not be instantiated without additional methods. abstract data type: An abstraction
Semantic Analysis: Types and Type Checking
Semantic Analysis Semantic Analysis: Types and Type Checking CS 471 October 10, 2007 Source code Lexical Analysis tokens Syntactic Analysis AST Semantic Analysis AST Intermediate Code Gen lexical errors
Conditions & Boolean Expressions
Conditions & Boolean Expressions 1 In C++, in order to ask a question, a program makes an assertion which is evaluated to either true (nonzero) or false (zero) by the computer at run time. Example: In
Sample Syllabus (C++) CSCI 1301 Introduction to Programming Principles
Sample Syllabus (C++) CSCI 1301 Introduction to Programming Principles Knowledge Areas that contain topics and learning outcomes covered in the course Knowledge Areas Total Hours of Coverage Software Development
CS 106 Introduction to Computer Science I
CS 106 Introduction to Computer Science I 01 / 21 / 2014 Instructor: Michael Eckmann Today s Topics Introduction Homework assignment Review the syllabus Review the policies on academic dishonesty and improper
C Programming Review & Productivity Tools
Review & Productivity Tools Giovanni Agosta Piattaforme Software per la Rete Modulo 2 Outline Preliminaries 1 Preliminaries 2 Function Pointers Variadic Functions 3 Build Automation Code Versioning 4 Preliminaries
Informatica e Sistemi in Tempo Reale
Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)
Member Functions of the istream Class
Member Functions of the istream Class The extraction operator is of limited use because it always uses whitespace to delimit its reads of the input stream. It cannot be used to read those whitespace characters,
Moving from CS 61A Scheme to CS 61B Java
Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you
WORKSPACE WEB DEVELOPMENT & OUTSOURCING TRAINING CENTER
WORKSPACE WEB DEVELOPMENT & OUTSOURCING TRAINING CENTER Course Outline (2015) Basic Programming With Procedural & Object Oriented Concepts (C, C++) Training Office# Road: 11, House: 1 A, Nikunja 2, Khilkhet,
Introduction to Programming Block Tutorial C/C++
Michael Bader Master s Program Computational Science and Engineering C/C++ Tutorial Overview From Maple to C Variables, Operators, Statements Functions: declaration, definition, parameters Arrays and Pointers
Introduction to Scientific Computing Part II: C and C++ C. David Sherrill School of Chemistry and Biochemistry Georgia Institute of Technology
Introduction to Scientific Computing Part II: C and C++ C. David Sherrill School of Chemistry and Biochemistry Georgia Institute of Technology The C Programming Language: Low-level operators Created by
Stack Allocation. Run-Time Data Structures. Static Structures
Run-Time Data Structures Stack Allocation Static Structures For static structures, a fixed address is used throughout execution. This is the oldest and simplest memory organization. In current compilers,
www.sahajsolns.com Chapter 4 OOPS WITH C++ Sahaj Computer Solutions
Chapter 4 OOPS WITH C++ Sahaj Computer Solutions 1 Session Objectives Classes and Objects Class Declaration Class Members Data Constructors Destructors Member Functions Class Member Visibility Private,
C++ Support for Abstract Data Types
Topics C++ Support for Abstract Data Types Professor Department of EECS [email protected] Vanderbilt University www.cs.wustl.edu/schmidt/ (615) 343-8197 Describing Objects Using ADTs Built-in vs.
