This document provides an introduction to object-oriented programming and C++. It defines key object-oriented programming concepts like objects, classes, encapsulation, inheritance, polymorphism, and aggregation. It also introduces basic C++ concepts such as variables, data types, operators, functions, and input/output. The document uses a sample C++ program to demonstrate typical program structure and elements like main functions, function definitions, comments, and preprocessor directives.
Object-Oriented Programming in Modern C++. Borislav Stanimirov. CoreHard Spri...corehard_by
Object-oriented programming has been criticized a lot. Every now and then some article or talk appears denouncing it and proclaiming that it's dead. This talk will do the opposite. It defends OOP and presents many modern libraries and concepts to show that it's very much alive and kicking.
Learn and master the Conditional statements, conditional expressions and logical expressions in Python. These slides are part of the Python Masterclass by Python Whiz
This document is a summary of Part 1 of a Python Masterclass on functions taught by PythonWhiz. It discusses what functions are and how they are useful for reusability and avoiding code duplication. It explains how to define functions using the def keyword and return values from functions using the return keyword. It also covers adding parameters to functions, scoping rules, default parameters, keyword arguments, and documenting functions. The goal is to explain the basics of functions in Python.
This document provides an overview of Objective-C and discusses several key concepts:
1. It begins with instructions for setting up the Objective-C development environment on Linux, Mac OS X, and Windows systems.
2. A "Hello World" example program is presented to demonstrate the basic structure of an Objective-C application and how to print output.
3. Object-oriented concepts like classes, inheritance, and polymorphism are explained through examples showing how to define classes with interfaces and implementations, create class instances, and call methods.
4. Additional Objective-C features are demonstrated like method parameters, constructors, access privileges, class methods, and exceptions handling.
This document provides an introduction to object-oriented programming concepts in C++ including objects, classes, encapsulation, inheritance, polymorphism, and more. It explains the basic structure of a C++ program and demonstrates how to write a simple "Hello World" program. It also covers basic C++ elements like variables, data types, comments, strings, arithmetic operators, and input/output.
C# 4.0 introduced several new features to the C# language including dynamic programming, optional and named parameters, and improved support for covariance and contravariance. It also added the ability to invoke members of dynamic objects at runtime instead of compile-time. The .NET Framework 4.0 implemented these language changes and added support for variance in interfaces like IEnumerable and delegates.
This is Work-In-Progress. Developing a series of lectures on C++0x. This will augment my presentations on C++ and Design Pattern. First trial run was done at Interra, Noida in 2009
Object-Oriented Programming in Modern C++. Borislav Stanimirov. CoreHard Spri...corehard_by
Object-oriented programming has been criticized a lot. Every now and then some article or talk appears denouncing it and proclaiming that it's dead. This talk will do the opposite. It defends OOP and presents many modern libraries and concepts to show that it's very much alive and kicking.
Learn and master the Conditional statements, conditional expressions and logical expressions in Python. These slides are part of the Python Masterclass by Python Whiz
This document is a summary of Part 1 of a Python Masterclass on functions taught by PythonWhiz. It discusses what functions are and how they are useful for reusability and avoiding code duplication. It explains how to define functions using the def keyword and return values from functions using the return keyword. It also covers adding parameters to functions, scoping rules, default parameters, keyword arguments, and documenting functions. The goal is to explain the basics of functions in Python.
This document provides an overview of Objective-C and discusses several key concepts:
1. It begins with instructions for setting up the Objective-C development environment on Linux, Mac OS X, and Windows systems.
2. A "Hello World" example program is presented to demonstrate the basic structure of an Objective-C application and how to print output.
3. Object-oriented concepts like classes, inheritance, and polymorphism are explained through examples showing how to define classes with interfaces and implementations, create class instances, and call methods.
4. Additional Objective-C features are demonstrated like method parameters, constructors, access privileges, class methods, and exceptions handling.
This document provides an introduction to object-oriented programming concepts in C++ including objects, classes, encapsulation, inheritance, polymorphism, and more. It explains the basic structure of a C++ program and demonstrates how to write a simple "Hello World" program. It also covers basic C++ elements like variables, data types, comments, strings, arithmetic operators, and input/output.
C# 4.0 introduced several new features to the C# language including dynamic programming, optional and named parameters, and improved support for covariance and contravariance. It also added the ability to invoke members of dynamic objects at runtime instead of compile-time. The .NET Framework 4.0 implemented these language changes and added support for variance in interfaces like IEnumerable and delegates.
This is Work-In-Progress. Developing a series of lectures on C++0x. This will augment my presentations on C++ and Design Pattern. First trial run was done at Interra, Noida in 2009
PHP 8 introduces several new features and backward compatibility breaks. It includes a just-in-time compiler, match expression, constructor property promotion, union types, static return type, attributes, named arguments, and improved type handling. Notable BC breaks are stricter error handling by default, locale independence for float conversions, and warning promotion to type errors. The changes aim to improve performance, type safety, and consistency.
Sometimes you see code that is perfectly OK according to the definition of the language, but which is flawed because it breaks too many established idioms and conventions. On the other hand, a solid piece of code is something that looks like it is written by an experienced person who cares about professionalism in programming.
A presentation at Norwegian Developer Conference 2010
Here is a potential solution to the problem in C++:
#include <iostream>
using namespace std;
int main() {
int num1, num2, num3;
cout << "Enter three numbers: ";
cin >> num1 >> num2 >> num3;
int total = num1 + num2 + num3;
float average = total / 3.0;
cout << "The numbers entered were: " << num1 << ", " << num2 << ", " << num3 << endl;
cout << "Their average is: " << average;
return 0;
}
Some key points:
- Use cin to input the 3 numbers from the
The document introduces some basic C++ idioms, rules, guidelines and best practices. The author notes that some items are based on their personal style preferences and the styles of groups they work with. The intention is to use the presentation to spark discussion, as it includes some controversial issues. Readers are encouraged to provide criticism of the example code presented.
The document is a lecture on C programming given on August 17th, 2008 at IIT Kanpur by Deepak Majeti. It covers basics of C including data types, operators, input/output functions, and provides examples of simple C programs. It also discusses compilation, debugging errors, and homework problems involving operator precedence.
Pointers,virtual functions and polymorphism cpprajshreemuthiah
This document discusses key concepts in object-oriented programming in C++ including polymorphism, pointers, pointers to objects and derived classes, virtual functions, and pure virtual functions. Polymorphism allows one name to have multiple forms through function and operator overloading as well as virtual functions. Pointers store the memory address of a variable rather than the data. Pointers can be used with objects, arrays, strings, and functions. Virtual functions allow calling a derived class version of a function through a base class pointer. Pure virtual functions define an abstract base class that cannot be instantiated.
Let's turn the table. Suppose your goal is to deliberately create buggy programs in C and C++ with serious security vulnerabilities that can be "easily" exploited. Then you need to know about things like stack smashing, shellcode, arc injection, return-oriented programming. You also need to know about annoying protection mechanisms such as address space layout randomization, stack canaries, data execution prevention, and more. These slides will teach you the basics of how to deliberately write insecure programs in C and C++.
A PDF version of the slides can be downloaded from my homepage: http://olvemaudal.com/talks
Here is a video recording of me presenting these slides at NDC 2014: http://vimeo.com/channels/ndc2014/97505677
Enjoy!
The document provides an introduction to the basics of C++, including a brief history of C and C++, comparing C and C++, and providing a simple C++ "Hello World" program example. C++ was created by Bjarne Stroustrup in 1979 as an enhancement to the C language by adding object-oriented programming capabilities while still maintaining efficiency and flexibility. The document outlines some key differences between C and C++, such as C++ supporting object-oriented programming, classes, and templates while maintaining similar performance to C.
OpenGurukul : Language : C++ ProgrammingOpen Gurukul
This document provides information about C++ classes and objects. It defines what a class is, noting that classes are like structures but with additional features such as data hiding and default private access. An object is defined as an instance of a class. The document discusses access specifiers like public, private, and protected. It also covers static variables and functions, constant functions, and friend functions/classes.
Virtual Functions support dynamic binding and object-oriented programming. A class that declares or inherits a virtual function is called a polymorphic class.
Microsoft does it again! With .Net Framework 4 Microsoft takes the C# language to new levels. In this session we will learn how to write better code using Dynamically Typed Objects, Optional & Named Parameters and Co-variance and Contra-variance.
This document provides an overview and outline of a presentation on exploring C++. It begins with background expectations for attendees and then outlines the session topics, which include C++ concepts like templates, exception handling, and an overview of the Standard Template Library and Boost library. The presentation aims to provide a high-level introduction to C++ basics rather than an exhaustive reference. It will cover primary programming paradigms in C++, best practices, and memory management techniques.
The document discusses key concepts in C++ including:
1. The main() function is the entry point of a C++ program and can call other functions defined in the source code.
2. main() returns an int value to the operating system. Functions can also return values and references.
3. Functions help reduce code size, save memory, and improve readability and reusability. Parameters can be passed by value or reference.
4. Inline functions provide faster execution by inserting the function code directly into the calling function. They are best for short functions without loops.
This document appears to be a student project submission for a post graduate diploma in information technology. It contains two questions and answers involving C programming. Question 1 involves accepting integer values from the user, sorting an array in ascending order, calculating the sum of odd values and number of even values. Question 2 involves reading from a file passed as a command line argument, displaying each word on a new line, counting vowels, occurrences of "the", and copying the file contents to a new file. The code provided implements the specified tasks for each question.
The document summarizes the evolution and future directions of the C# programming language. It discusses new features in recent versions such as generics in C# 2.0, language integrated query in C# 3.0, and dynamic programming in C# 4.0. It also covers trends toward declarative programming, concurrency, and compiler as a service. The presentation provides examples and demos of new C# 4.0 features like dynamic typing, optional and named parameters, and covariance and contravariance.
Programming is hard. Programming correct C and C++ is particularly hard. Indeed, both in C and certainly in C++, it is uncommon to see a screenful containing only well defined and conforming code.Why do professional programmers write code like this? Because most programmers do not have a deep understanding of the language they are using.While they sometimes know that certain things are undefined or unspecified, they often do not know why it is so. In these slides we will study small code snippets in C and C++, and use them to discuss the fundamental building blocks, limitations and underlying design philosophies of these wonderful but dangerous programming languages.
This content has a CC license. Feel free to use it for whatever you want. You may download the original PDF file from: http://www.pvv.org/~oma/DeepC_slides_oct2012.pdf
This document provides an introduction to programming concepts like algorithms, functions, objects, and programming style. It specifically focuses on C++ programming. Some key points covered include:
- C++ is an object-oriented programming language that combines procedural programming features from C with object-oriented capabilities.
- Programs are made up of algorithms, which are step-by-step procedures to solve problems. Functions allow breaking programs into modular pieces.
- The main() function acts as the driver that runs the program. It and other functions have specific formatting conventions.
- The cout object is used to output text to the screen using insertion operators. Libraries like iostream provide important input/output capabilities.
- Programming style guidelines promote
This document provides an overview of key concepts in the first chapter of a C++ programming book, including:
1) The chapter introduces programming, algorithms, functions, classes, and the main() function in C++.
2) It describes how C++ programs are compiled and processed, and defines important terms like variables, objects, and namespaces.
3) The document explains how to use the cout object to display output in C++ using the insertion operator and escape sequences.
Relationship in database lecture with English language and Persian Translation. This lecture is for absolutely beginners. This is the fifth lecture in database one.
PHP 8 introduces several new features and backward compatibility breaks. It includes a just-in-time compiler, match expression, constructor property promotion, union types, static return type, attributes, named arguments, and improved type handling. Notable BC breaks are stricter error handling by default, locale independence for float conversions, and warning promotion to type errors. The changes aim to improve performance, type safety, and consistency.
Sometimes you see code that is perfectly OK according to the definition of the language, but which is flawed because it breaks too many established idioms and conventions. On the other hand, a solid piece of code is something that looks like it is written by an experienced person who cares about professionalism in programming.
A presentation at Norwegian Developer Conference 2010
Here is a potential solution to the problem in C++:
#include <iostream>
using namespace std;
int main() {
int num1, num2, num3;
cout << "Enter three numbers: ";
cin >> num1 >> num2 >> num3;
int total = num1 + num2 + num3;
float average = total / 3.0;
cout << "The numbers entered were: " << num1 << ", " << num2 << ", " << num3 << endl;
cout << "Their average is: " << average;
return 0;
}
Some key points:
- Use cin to input the 3 numbers from the
The document introduces some basic C++ idioms, rules, guidelines and best practices. The author notes that some items are based on their personal style preferences and the styles of groups they work with. The intention is to use the presentation to spark discussion, as it includes some controversial issues. Readers are encouraged to provide criticism of the example code presented.
The document is a lecture on C programming given on August 17th, 2008 at IIT Kanpur by Deepak Majeti. It covers basics of C including data types, operators, input/output functions, and provides examples of simple C programs. It also discusses compilation, debugging errors, and homework problems involving operator precedence.
Pointers,virtual functions and polymorphism cpprajshreemuthiah
This document discusses key concepts in object-oriented programming in C++ including polymorphism, pointers, pointers to objects and derived classes, virtual functions, and pure virtual functions. Polymorphism allows one name to have multiple forms through function and operator overloading as well as virtual functions. Pointers store the memory address of a variable rather than the data. Pointers can be used with objects, arrays, strings, and functions. Virtual functions allow calling a derived class version of a function through a base class pointer. Pure virtual functions define an abstract base class that cannot be instantiated.
Let's turn the table. Suppose your goal is to deliberately create buggy programs in C and C++ with serious security vulnerabilities that can be "easily" exploited. Then you need to know about things like stack smashing, shellcode, arc injection, return-oriented programming. You also need to know about annoying protection mechanisms such as address space layout randomization, stack canaries, data execution prevention, and more. These slides will teach you the basics of how to deliberately write insecure programs in C and C++.
A PDF version of the slides can be downloaded from my homepage: http://olvemaudal.com/talks
Here is a video recording of me presenting these slides at NDC 2014: http://vimeo.com/channels/ndc2014/97505677
Enjoy!
The document provides an introduction to the basics of C++, including a brief history of C and C++, comparing C and C++, and providing a simple C++ "Hello World" program example. C++ was created by Bjarne Stroustrup in 1979 as an enhancement to the C language by adding object-oriented programming capabilities while still maintaining efficiency and flexibility. The document outlines some key differences between C and C++, such as C++ supporting object-oriented programming, classes, and templates while maintaining similar performance to C.
OpenGurukul : Language : C++ ProgrammingOpen Gurukul
This document provides information about C++ classes and objects. It defines what a class is, noting that classes are like structures but with additional features such as data hiding and default private access. An object is defined as an instance of a class. The document discusses access specifiers like public, private, and protected. It also covers static variables and functions, constant functions, and friend functions/classes.
Virtual Functions support dynamic binding and object-oriented programming. A class that declares or inherits a virtual function is called a polymorphic class.
Microsoft does it again! With .Net Framework 4 Microsoft takes the C# language to new levels. In this session we will learn how to write better code using Dynamically Typed Objects, Optional & Named Parameters and Co-variance and Contra-variance.
This document provides an overview and outline of a presentation on exploring C++. It begins with background expectations for attendees and then outlines the session topics, which include C++ concepts like templates, exception handling, and an overview of the Standard Template Library and Boost library. The presentation aims to provide a high-level introduction to C++ basics rather than an exhaustive reference. It will cover primary programming paradigms in C++, best practices, and memory management techniques.
The document discusses key concepts in C++ including:
1. The main() function is the entry point of a C++ program and can call other functions defined in the source code.
2. main() returns an int value to the operating system. Functions can also return values and references.
3. Functions help reduce code size, save memory, and improve readability and reusability. Parameters can be passed by value or reference.
4. Inline functions provide faster execution by inserting the function code directly into the calling function. They are best for short functions without loops.
This document appears to be a student project submission for a post graduate diploma in information technology. It contains two questions and answers involving C programming. Question 1 involves accepting integer values from the user, sorting an array in ascending order, calculating the sum of odd values and number of even values. Question 2 involves reading from a file passed as a command line argument, displaying each word on a new line, counting vowels, occurrences of "the", and copying the file contents to a new file. The code provided implements the specified tasks for each question.
The document summarizes the evolution and future directions of the C# programming language. It discusses new features in recent versions such as generics in C# 2.0, language integrated query in C# 3.0, and dynamic programming in C# 4.0. It also covers trends toward declarative programming, concurrency, and compiler as a service. The presentation provides examples and demos of new C# 4.0 features like dynamic typing, optional and named parameters, and covariance and contravariance.
Programming is hard. Programming correct C and C++ is particularly hard. Indeed, both in C and certainly in C++, it is uncommon to see a screenful containing only well defined and conforming code.Why do professional programmers write code like this? Because most programmers do not have a deep understanding of the language they are using.While they sometimes know that certain things are undefined or unspecified, they often do not know why it is so. In these slides we will study small code snippets in C and C++, and use them to discuss the fundamental building blocks, limitations and underlying design philosophies of these wonderful but dangerous programming languages.
This content has a CC license. Feel free to use it for whatever you want. You may download the original PDF file from: http://www.pvv.org/~oma/DeepC_slides_oct2012.pdf
This document provides an introduction to programming concepts like algorithms, functions, objects, and programming style. It specifically focuses on C++ programming. Some key points covered include:
- C++ is an object-oriented programming language that combines procedural programming features from C with object-oriented capabilities.
- Programs are made up of algorithms, which are step-by-step procedures to solve problems. Functions allow breaking programs into modular pieces.
- The main() function acts as the driver that runs the program. It and other functions have specific formatting conventions.
- The cout object is used to output text to the screen using insertion operators. Libraries like iostream provide important input/output capabilities.
- Programming style guidelines promote
This document provides an overview of key concepts in the first chapter of a C++ programming book, including:
1) The chapter introduces programming, algorithms, functions, classes, and the main() function in C++.
2) It describes how C++ programs are compiled and processed, and defines important terms like variables, objects, and namespaces.
3) The document explains how to use the cout object to display output in C++ using the insertion operator and escape sequences.
Relationship in database lecture with English language and Persian Translation. This lecture is for absolutely beginners. This is the fifth lecture in database one.
A simple architecture is perfect for a simple application. But, as the application grows in its complexity, the architecture must become more complex in order to prevent it from becoming unmaintainable.
In this talk we discuss some ideas for simplifying complex code bases.
We also discuss the important distinctions between presentation, service, and domain layers and strategies for separating high-level business policy from implementation.
Some Domain-Driven Design topics are discussed, but this is not a talk about DDD. DDD is not about design patterns, but rather is about business analysis, communication, and much more.
Cardinality and participation constraintsNikhil Deswal
Cardinality and participation constraints define the relationships between entities in a database. Cardinality constraints specify the maximum number of entities that can participate in a relationship, such as one-to-one, one-to-many, or many-to-many. Participation constraints indicate whether participation of an entity in a relationship is total, meaning every entity must participate, or partial, meaning only some entities participate. These constraints help maintain data integrity and ensure only valid relationships are stored in the database.
The document discusses requirements capture using UML use case diagrams. It describes how use case diagrams can be used to capture functional requirements by modeling actors, use cases, and relationships. Key aspects covered include identifying use cases and actors, documenting use case descriptions, modeling relationships between use cases and actors, and tips for effective use case modeling.
El documento describe los 5 pasos para configurar una cuenta de correo electrónico con Hotmail: 1) ir a la página web de Hotmail, 2) crear una cuenta eligiendo un nombre de usuario y contraseña, 3) completar datos personales y una pregunta de seguridad, 4) aceptar los términos legales, y 5) acceder al correo electrónico introduciendo el nombre de usuario y contraseña.
Este documento es la autobiografía de Cleotilde Jorge Rafael. Resume los principales eventos de su vida desde su nacimiento en 1991 en Oaxaca, México hasta el presente donde cursa el primer semestre de la carrera de Ingeniería en Sistemas Computacionales. Incluye detalles sobre su educación primaria, secundaria y preparatoria, así como sus logros deportivos y participación en grupos escolares. Concluye reconociendo que aunque ha recorrido un largo camino, todavía le queda mucho por aprender en su educación
The Member--Centric Association Configuring Your Organization for Membership...McKinley Advisors
Member-centric organizations prioritize understanding and serving member needs over other considerations like organizational needs or financial goals. Some of these scenarios could be interpreted either way depending on additional context, but in general:
- Conducting member research before decisions helps ensure choices align with what members value.
- Inviting broad member participation in advocacy recognizes the importance of member voices in shaping policy agendas.
- Exclusively CEO events may risk excluding or disengaging other important member roles.
- Requiring programs break even in one year could discourage innovation or investing in longer-term member value.
The key is balancing organizational sustainability with continuously learning about and responding to evolving member priorities.
This document consists of a blog by Marina Gorosito about using various online tools for English language teaching. It includes 17 posts providing samples and tutorials for tools like GoAnimate, Glogster, Sketchcast, and Zimmertwins. The final 4 posts propose activities for students to use these tools, including creating videos on issues, making posters about eating disorders, designing monsters in Sketchcast, and crafting cartoons in Zimmertwins.
EL PUEBLO ONE QUEZON CITY
CONDORMITEL FULLY FURNISHED
STUDIO UNIT, 1 BEROOM,
2 BEDROOM AND 3 BEDROOM
AVAILABLE FOR RENT AND RENT
TO OWN
FOR INQUIRIES CALL: 0916-525-2871
Este documento presenta el Código Nacional de Tránsito Terrestre de Colombia. Define los principios rectores del código como la seguridad de los usuarios, calidad, oportunidad, cubrimiento, libertad de acceso, plena identificación, libre circulación, educación y descentralización. También define más de 50 términos relacionados con el tránsito como acera, accidente de tránsito, alcoholemia, automóvil, autopista, bicicleta, bus, carretera, casco y conductor, entre otros.
The document outlines various administrative features for managing a website or application. It includes the ability to:
- Edit and suspend user profiles, ban or delete users, and view user profiles.
- Create and delete reports, customize search filters, add and delete promoters, and customize report views.
- Manage advertisements by setting times, dates, and company information.
- Send emails, messages, and set up promotions with start/end dates targeted at users or groups.
- Manage payments, credits, and gifts for users.
Este documento contiene una colección de calaveras, poemas cortos tradicionales mexicanos escritos para el Día de Muertos. Las calaveras describen interacciones humorísticas entre varias personas y la Calaca, una representación esquelética de la muerte. Algunas calaveras describen a la Calaca llevándose a personas como Rosario, Aracely, Miguel y Mónica mientras bailan, estudian o asisten a fiestas. Otras calaveras muestran a la Calaca coqueteando con personas como Ismael y Lil
Hepatitis A, B, and C are viral infections that cause inflammation of the liver. Hepatitis A spreads through ingestion of contaminated food or water. Hepatitis B spreads through bodily fluids and can be sexually transmitted or spread by sharing needles. Hepatitis C primarily spreads through exposure to infected blood, such as sharing needles. While symptoms are usually mild and resolve on their own for Hepatitis A, Hepatitis B and C can become chronic infections requiring treatment to prevent further liver damage. Testing identifies exposure and active infections, and immunizations protect against Hepatitis A and B.
This document provides an overview of C++ programming concepts including:
- Procedure-oriented programming focuses on tasks like reading, calculating and printing using functions, while object-oriented programming emphasizes data through objects and classes.
- Some problems with C include lack of consideration for data elements and lack of security for networks.
- C++ classes contain variables and functions to characterize objects. Data and functions are tied together and data is hidden.
- Key concepts explained include objects, member functions, constructors, destructors, inheritance and polymorphism.
- Examples demonstrate basic C++ programs, classes, objects, arrays of objects, function overloading and the this pointer.
This document provides an overview of object-oriented programming (OOP) concepts in C++. It defines key OOP concepts like class, object, inheritance, encapsulation, abstraction, polymorphism, and overloading. It provides examples to illustrate class and object, inheritance with different types, encapsulation by hiding data, and function overloading. The document was prepared by a trainee as part of a mentoring program and provides contact information for the training organization.
This document provides an overview of C++ programming concepts including:
- Procedure-oriented programming focuses on tasks like reading, calculating and printing using functions, while object-oriented programming emphasizes data through objects and classes.
- C++ was developed to include object-oriented features while retaining C's simplicity, with classes, inheritance, and other features enabling abstract data types.
- Key concepts covered include classes, objects, member functions, inline functions, passing objects as parameters, returning objects, arrays of objects, and function overloading. Examples are provided to illustrate each concept.
C++ is an enhanced version of C that adds support for object-oriented programming. Procedure-oriented programming focuses on functions and algorithms, dividing programs into functions that share global data. Object-oriented programming treats data as critical, tying it more closely to the functions that operate on it and protecting it from accidental modification. C++ uses cout and cin for input/output instead of printf and scanf, and supports comments with // for single-line and /* */ for multi-line comments. Classes allow for data hiding, inheritance, and operator overloading that structures cannot provide.
C++ is a general-purpose programming language created by Bjarne Stroustrup in 1979. It has imperative, object-oriented and generic programming features. The structure of a C++ program includes preprocessor directives, a main() function, and a program body. Variables are declared with a data type and used to store and manipulate data. C++ supports various operators for arithmetic, relational, logical, and bitwise operations.
Notes about moving from python to c++ py contw 2020Yung-Yu Chen
The document discusses moving from Python to C++. It notes that Python is commonly used for application development due to its ease of use, while C++ is used for high-performance computing kernels due to better performance. It recommends binding Python and C++ together, using C++ for performance critical parts and Python for user interfaces and scripting. Pybind11 is identified as a good tool for binding Python and C++ that provides modern C++ features and is easy to use.
The document discusses key concepts related to data structures and algorithms in C including:
1. Data structures allow for efficient storage and retrieval of data through logical organization and mathematical modeling.
2. Algorithms must be correct, finite, and efficient to solve problems by taking input and producing output through a defined sequence of steps.
3. Common data structures covered include arrays, stacks, queues, linked lists, trees, and graphs. Abstract data types allow separation of implementation from interface.
The document discusses key concepts related to data structures and algorithms in C including:
1. Data structures allow for efficient storage and retrieval of data through logical organization and mathematical modeling.
2. Algorithms must be correct, finite, and efficient to solve problems by taking input and producing output through a defined sequence of steps.
3. Common data structures covered include arrays, stacks, queues, linked lists, trees, and graphs. Abstract data types allow separation of implementation from interface.
Twins: Object Oriented Programming and Functional ProgrammingRichardWarburton
Object-Oriented Programming has well established design principles, such as SOLID. For many developers architecture and functional programming are at odds with each other: they don’t know how their existing tricks of the trade convert into functional design. This problem becomes worse as hybrid languages such as Java 8 or Scala become common. We’ll talk about how functional programming helps you implement the SOLID principles, and how a functional mindset can actually help you achieve cleaner and simpler OO design.
Object Oriented Programming using C++(UNIT 1)SURBHI SAROHA
This document provides an introduction to object-oriented programming (OOP) concepts using C++. It defines key OOP terms like class, object, encapsulation, inheritance, polymorphism and abstraction. It provides examples of different types of inheritance in C++ like single, multiple, hierarchical and hybrid inheritance. It also outlines advantages of OOP like easier troubleshooting, code reusability, increased productivity, reduced data redundancy, and flexible code.
C++ is most often used programming language. This slide will help you to gain more knowledge on C++ programming. In this slide you will learn the fundamentals of C++ programming. The slide will also help you to fetch more details on Object Oriented Programming concepts. Each of the concept under Object Oriented Programming is explained in detail and in more smoother way as it will helpful for everyone to understand.
This document provides an introduction and overview of Flutter and Dart. It discusses that Flutter is a framework for building cross-platform apps using a single codebase. Apps built with Flutter use widgets to construct the user interface, where widgets are basic UI elements like text, buttons, etc. Dart is the programming language used with Flutter, and it is similar to other popular languages. The document then demonstrates basic Dart syntax examples and how to build UI widgets in Flutter. Finally, it provides information on setting up the Android Studio IDE to develop Flutter apps and run them in emulators.
Functions And Header Files In C++ | Bjarne stroustrupSyedHaroonShah4
This document discusses functions and header/source files in C++. It covers declarations, definitions, and the differences between them. Declarations introduce names and specify types, while definitions also fully specify the entity. Declarations allow interfaces to be specified. Headers contain declarations to share interfaces between parts of a program. Functions are described as units of operation that can take parameters and return values. The document also discusses scopes, namespaces, and storage classes like static.
The document discusses functions in C programming. It defines functions and explains their various parts like declaration, definition, and invocation. It also differentiates between function declaration and definition. Various types of functions are classified based on their inputs and outputs. The key differences between call by value and call by reference are explained with examples. Advantages of pass by reference are also mentioned.
C++ is an enhanced version of the C language. C++ includes everything that is part of C language and adds support for object oriented programming (OOP). With very few, very major exceptions, C++ is a superset of C
C++ [ principles of object oriented programming ]Rome468
C++ is an enhanced version of C that adds support for object-oriented programming. It includes everything in C and allows for defining classes and objects. Classes allow grouping of related data and functions, and objects are instances of classes. Key concepts of OOP supported in C++ include encapsulation, inheritance, and polymorphism. Encapsulation binds data and functions together in a class and allows hiding implementation details. Inheritance allows defining new classes based on existing classes to reuse their functionality. Polymorphism enables different classes to have similarly named functions that demonstrate different behavior.
The document provides an introduction to basic concepts in object-oriented programming with C++, including data types, variables, operators, functions, input/output, arrays, pointers, and control structures. It explains fundamental data types like integers and characters, how to declare and assign variables, arithmetic and logical operators, how functions are defined by their name, parameters and return type, and how to pass arguments by value or reference. It also covers arrays, pointers, the relationship between arrays and pointers, pointer arithmetic, input/output streams, and control structures like if/else statements, for/while loops, switch statements, and do/while loops.
This document discusses distributed database management systems (DDBMS). It outlines the evolution of DDBMS from centralized systems to today's distributed systems over the internet. It describes the advantages and disadvantages of DDBMS, components of DDBMS including transaction processors and data processors, and levels of data and process distribution including single-site, multiple-site, and fully distributed systems. It also discusses concepts like distribution transparency, transaction transparency, and distributed concurrency control in DDBMS.
Lecture 09 dblc centralized vs decentralized designemailharmeet
The document discusses database design and the database lifecycle (DBLC). It describes the DBLC phases including initial study, database design, implementation and loading, testing and evaluation, operation, and maintenance and evaluation. The database design phase is the most critical and involves conceptual design including entity relationship modeling, logical design, and physical design. The document also discusses centralized versus decentralized database design and the tradeoffs between the two approaches.
Lecture 09 dblc centralized vs decentralized designemailharmeet
The document discusses database design and the database lifecycle (DBLC). It describes the DBLC phases including initial study, database design, implementation and loading, testing and evaluation, operation, and maintenance and evaluation. The database design phase is the most critical and involves conceptual design including entity relationship modeling, logical design, and physical design. The document also discusses centralized versus decentralized database design and the tradeoffs between the two approaches.
The document discusses distributed database management systems (DDBMS). It describes how DDBMS evolved from centralized systems to address needs for decentralized management, improved performance and reliability. Key components of a DDBMS include transaction processors, data processors and protocols to coordinate communication and ensure consistency. The document also covers different levels of data and process distribution, and techniques for providing transparency in distributed databases.
The document discusses key concepts in relational database management systems including:
1) Everything is represented as relations (tables) with attributes (columns) and tuples (rows) that make up the relations.
2) Schemas define the structure of relations with attributes and primary keys to uniquely identify tuples.
3) Relations can be related through foreign keys that match primary keys in other relations.
4) Integrity rules like entity and referential integrity enforce valid relationships between tuples in different relations.
Lecture 06 relational algebra and calculusemailharmeet
The document discusses data manipulation languages (DML) for databases. There are two main types of DML: navigational/procedural and non-navigational/non-procedural. Relational algebra is a non-navigational DML defined by Codd that uses algebraic operations like selection, projection, join, etc. on tables. Relational calculus is also a non-navigational DML that defines new relations in terms of predicates on tuple variables ranging over named relations.
The document contains examples of C++ code demonstrating basic concepts like variable declaration and initialization, input/output using cout and cin, comments, calculations, and passing variables by reference to allow functions to modify calling variables. Multiple code snippets are provided to illustrate different language features like declaring variables in loops, encapsulating code in curly braces, accessing global variables, and using references to alias variables.
This document contains debugging exercises and programming exercises in C++. The debugging exercises identify errors in sample code snippets, such as using the wrong data type or operator. The programming exercises provide tasks to write C++ programs, such as displaying output, reading user input, performing calculations, and converting between temperature scales using a class.
Object oriented programming involves creating classes that define objects and their behaviors, and then creating objects from those classes that can communicate by sending messages. The key aspects are:
1. Creating classes that define abstract data types with attributes and methods.
2. Instantiating objects from those classes that have unique identities and states.
3. Sending messages to objects by calling their methods using dot notation.
The document discusses key concepts in object-oriented programming (OOP) including objects, classes, encapsulation, inheritance, polymorphism, and message passing. It provides examples of a simple class named "item" that includes variables and methods. It also discusses how objects are composed of data and functions, and how classes are used to organize data and functions through principles like private/public access and data abstraction.
The document outlines the syllabus for an Object Oriented Programming using C++ course. It is divided into 3 sections - Introduction to OOP concepts and C++ basics, Classes and Objects, and Input/Output files. Section I covers OOP characteristics, C++ program statements, functions, arrays and pointers. Section II covers classes, objects, inheritance, polymorphism and static/friend functions. Section III discusses file I/O using streams in C++. The question paper for internal assessment will have 2 parts - short questions from each section in Part A and longer questions covering all sections in Part B.
This document discusses database design and the database lifecycle (DBLC). It explains that the DBLC involves 6 phases: initial study, design, implementation, testing, operation, and maintenance. The design phase is most critical and involves conceptual, logical, and physical design. Conceptual design uses entity relationship modeling and normalization. Logical design maps the conceptual model to the chosen DBMS. Physical design selects storage structures. The document also discusses top-down vs bottom-up design and centralized vs decentralized design approaches.
This document provides instructions for creating an entity relationship diagram for a time table assignment for PCTE. It lists the steps needed to identify the entities, attributes, relationships, primary keys, foreign keys, cardinality, connectivity, and dependencies to model the data. The assignment is due on August 23, 2010 and late submissions will not be accepted.
The document discusses normalization of database tables. It covers normal forms including 1NF, 2NF, 3NF, BCNF and 4NF. The process of normalization reduces data redundancies and helps eliminate data anomalies. Normalization is done concurrently with entity-relationship modeling to produce an effective database design. In some cases, denormalization may be needed to generate information more efficiently.
Lecture 03 data abstraction and er modelemailharmeet
The document discusses entity relationship (E-R) modeling and database design. It covers key concepts of E-R modeling including entities, attributes, relationships, cardinality, connectivity, weak/strong relationships, and inheritance. It also discusses developing E-R diagrams through an iterative process and reconciling conflicting goals of database design such as standards compliance, performance, and security.
This document provides an overview of databases and database management systems (DBMS). It discusses how databases evolved from file systems to address flaws in data management. It describes what a DBMS is and its functions in managing the database structure and controlling data access. The document also summarizes different database models including hierarchical, network, relational, entity-relationship, and object-oriented models. It highlights advantages and disadvantages of each model.
This document provides an introduction and overview for a course on Relational Database Management Systems. It outlines the instructor details, evaluation criteria including assignments and tests, marks distribution across internal and external assessments. Required textbooks are listed for both theory and practical components. Previous year question papers are linked. The course syllabus is broken down into four main sections covering database concepts, data models, relational model and relational query language SQL. Key points are highlighted regarding attendance, assignment deadlines, and accessing course materials on the college server.
This document outlines the syllabus for an MCA course on relational database management systems. The course introduces students to fundamental database concepts like data modeling, normalization, and SQL. It will cover topics such as the relational model, entity-relationship diagrams, functional dependencies, relational algebra, and database design principles. Students will learn to analyze business needs and design databases using tools like SQL. The course aims to help students develop skills for implementing database solutions to real-world problems.
2. 2 What are we doing today? Introduction of: the lecturer Objects Basic Terminology C++ the module
3. 3 What is Object Oriented Programming? Identifying objects and assigning responsibilities to these objects. Objects communicate to other objects by sending messages. Messages are received by the methods of an object An object is like a black box. The internal details are hidden.
4. 4 What is an object? Tangible Things as a car, printer, ... Roles as employee, boss, ... Incidents as flight, overflow, ... Interactions as contract, sale, ... Specifications as colour, shape, …
5. 5 So, what are objects? an object represents an individual, identifiable item, unit, or entity, either real or abstract, with a well-defined role in the problem domain. Or An "object" is anything to which a concept applies. Etc.
6. 6 Why do we care about objects? Modularity - large software projects can be split up in smaller pieces. Reuseability - Programs can be assembled from pre-written software components. Extensibility - New software components can be written or developed from existing ones.
7. Example: The Person class #include<string> #include<iostream> class Person{ char name[20]; int yearOfBirth; public: void displayDetails() { cout << name << " born in " << yearOfBirth << endl; } //... }; private data public processes
8. 8 The two parts of an object Object = Data + Methods or to say the same differently: An object has the responsibility to know and the responsibility to do. = +
9. 9 Basic Terminology Abstraction is the representation of the essential features of an object. These are ‘encapsulated’ into an abstract data type. Encapsulation is the practice of including in an object everything it needs hidden from other objects. The internal state is usually not accessible by other objects.
10. 10 Basic Terminology:Inheritance Inheritance means that one class inherits the characteristics of another class.This is also called a “is a” relationship: A car is a vehicle A dog is an animal A teacher is a person
11. 11 Basic Terminology:Polymorphism Polymorphism means “having many forms”. It allows different objects to respond to the same message in different ways, the response specific to the type of the object. E.g. the message displayDetails() of the Person class should give different results when send to a Student object (e.g. the enrolment number).
12. 12 Basic Terminology:Aggregation Aggregation describes a “has a” relationship. One object is a part of another object. We distinguish between composite aggregation (the composite “owns” the part) and shared aggregation (the part is shared by more then one composite). A car has wheels.
13. 13 Basic Terminology:Behaviour and Messages The most important aspect of an object is its behaviour (the things it can do). A behaviour is initiated by sending a message to the object (usually by calling a method).
14. 14 The two steps of Object Oriented Programming Making Classes: Creating, extending or reusing abstract data types. Making Objects interact: Creating objects from abstract data types and defining their relationships.
15. 15 Module Outline Introduction The non object oriented basics Classes Design Approaches Testing Inheritance Aggregation Polymorphism Multifile Development
16. 16 Today: Extensive analysis of an example program. Data types, operators, functions and I/O. Arrays, strings, pointers Control structures.
17. A typical C++ program // FileID: hello.cpp // Title: The program doing something #include <iostream.h> void doSomething(int p); int main() { int p = 7; doSomething(p); cout << “I have something done.” << endl; return 0; } void doSomething(int p) { for( int i = 0; i < p; i++ ) { cout << “*” << endl; } }
18. A typical C++ program // FileID: hello.cpp // Title: The program doing something #include <iostream.h> void doSomething(int p); int main() { int p = 7; doSomething(p); cout << “I have something done.” << endl; return 0; } void doSomething(int p) { for( int i = 0; i < p; i++ ) { cout << “*” << endl; } } The header of the file. Should contain general information as file name, author, description, etc. The compiler ignores these lines (see next slide).
19. A typical C++ program // FileID: hello.cpp // Title: The program doing something #include <iostream.h> void doSomething(int p); int main() { int p = 7; doSomething(p); cout << “I have something done.” << endl; return 0; } void doSomething(int p) { for( int i = 0; i < p; i++ ) { cout << “*” << endl; } } This is a C++ comment. Lines starting with // are ignored by the compiler. Also ignored is text enclosed by /* and */
20. A typical C++ program // FileID: hello.cpp // Title: The program doing something #include <iostream.h> void doSomething(int p); int main() { int p = 7; doSomething(p); cout << “I have something done.” << endl; return 0; } void doSomething(int p) { for( int i = 0; i < p; i++ ) { cout << “*” << endl; } } A pre-processor directive. Lines starting with a # are interpreted by a pre-processor before the compiler processes the file. Other important directives are #define, #ifdef, #endif, #pragma, ...
21. A typical C++ program // FileID: hello.cpp // Title: The program doing something #include <iostream.h> void doSomething(int p); int main() { int p = 7; doSomething(p); cout << “I have something done.” << endl; return 0; } void doSomething(int p) { for( int i = 0; i < p; i++ ) { cout << “*” << endl; } } In this example we include the file iostream.h into the program. iostream.h defines classes and objects related to input and output. We need it here because cout is declared there.
22. A typical C++ program // FileID: hello.cpp // Title: The program doing something #include <iostream.h> void doSomething(int p); int main() { int p = 7; doSomething(p); cout << “I have something done.” << endl; return 0; } void doSomething(int p) { for( int i = 0; i < p; i++ ) { cout << “*” << endl; } } Observation: cout is not a keyword of C++ but an identifier defined in the iostream library.
23. A typical C++ program // FileID: hello.cpp // Title: The program doing something #include <iostream.h> void doSomething(int p); int main() { int p = 7; doSomething(p); cout << “I have something done.” << endl; return 0; } void doSomething(int p) { for( int i = 0; i < p; i++ ) { cout << “*” << endl; } } A function prototype. In this line the compiler is told about a function with the name doSomething and its signature. The function here has one parameter (int) and no return value (void).
24. A typical C++ program // FileID: hello.cpp // Title: The program doing something #include <iostream.h> void doSomething(int p); int main() { int p = 7; doSomething(p); cout << “I have something done.” << endl; return 0; } void doSomething(int p) { for( int i = 0; i < p; i++ ) { cout << “*” << endl; } } Also global variables and class declarations usually come here.
25. A typical C++ program // FileID: hello.cpp // Title: The program doing something #include <iostream.h> void doSomething(int p); int main() { int p = 7; doSomething(p); cout << “I have something done.” << endl; return 0; } void doSomething(int p) { for( int i = 0; i < p; i++ ) { cout << “*” << endl; } } The main function is the entry point of a C++ program. Each C++ program must have exactly one main() method. The return value of main() is an int. This value is passed to the system which invoked the C++ program.
26. A typical C++ program // FileID: hello.cpp // Title: The program doing something #include <iostream.h> void doSomething(int p); int main() { int p = 7; doSomething(p); cout << “I have something done.” << endl; return 0; } void doSomething(int p) { for( int i = 0; i < p; i++ ) { cout << “*” << endl; } } The code which implements the main function is enclosed in { and }. Statements enclosed in { and } are called a block.
27. A typical C++ program // FileID: hello.cpp // Title: The program doing something #include <iostream.h> void doSomething(int p); int main() { int p = 7; doSomething(p); cout << “I have something done.” << endl; return 0; } void doSomething(int p) { for( int i = 0; i < p; i++ ) { cout << “*” << endl; } } We declare a variable p of type int. Other important data types of C++ are char, unsigned int, long, unsigned long, float, double, bool. The variable p is immediately initialised with the value 7.
28. A typical C++ program // FileID: hello.cpp // Title: The program doing something #include <iostream.h> void doSomething(int p); int main() { int p = 7; doSomething(p); cout << “I have something done.” << endl; return 0; } void doSomething(int p) { for( int i = 0; i < p; i++ ) { cout << “*” << endl; } } The function doSomething() is called with the parameter p.
29. A typical C++ program This statement prints the string “I have something done.” to the screen. The “stream manipulator” endl outputs a newline and then “flushes the output buffer”. // FileID: hello.cpp // Title: The program doing something #include <iostream.h> void doSomething(int p); int main() { int p = 7; doSomething(p); cout << “I have something done.” << endl; return 0; } void doSomething(int p) { for( int i = 0; i < p; i++ ) { cout << “*” << endl; } }
30. A typical C++ program Functions with a return value which is not void use the return keyword in order to return their value to the calling function. In the special situation here, the main() method has no calling function. The value 0 is passed back to system when the program is finished. Usually 0 means that the program worked correctly. // FileID: hello.cpp // Title: The program doing something #include <iostream.h> void doSomething(int p); int main() { int p = 7; doSomething(p); cout << “I have something done.” << endl; return 0; } void doSomething(int p) { for( int i = 0; i < p; i++ ) { cout << “*” << endl; } }
31. A typical C++ program // FileID: hello.cpp // Title: The program doing something #include <iostream.h> void doSomething(int p); int main() { int p = 7; doSomething(p); cout << “I have something done.” << endl; return 0; } void doSomething(int p) { for( int i = 0; i < p; i++ ) { cout << “*” << endl; } } The implementation of the previously defined function doSomething.
32. A typical C++ program // FileID: hello.cpp // Title: The program doing something #include <iostream.h> void doSomething(int p); int main() { int p = 7; doSomething(p); cout << “I have something done.” << endl; return 0; } void doSomething(int p) { for( int i = 0; i < p; i++ ) { cout << “*” << endl; } }
33. 33 Basics of C++ - data types Some Fundamental data types: char characters: ’a’, ’b’, ’’, ’’, ’7’ int integers: 3, 6883, -5, 0 double floating point numbers: 3.14, 7e9 bool true or false. Also: float, long, unsigned long, short, unsigned char, wchar_t
34. 34 Basics of C++ - variables Declaring variables in a program: char a; int b; double c; Assignment: b = 4; a = 'w’; c = -3.777; int x = 78;
35. 35 Basics of C++ - variables Constants: const double PI=3.1415926; const int MAXBUFFER=20; Note: the const keyword is also used for method parameters, methods and return values (later)
37. 37 Basics of C++ - operators The unary operators ++ and --: ++ increment by 1 -- decrement by 1 The language C++ got its name by this operator! Note, that i++ and ++i have different behaviour […]
38. 38 Basics of C++ - functions int someFunction(double f, char c) { // …} Name Body ParameterList Return Type
39. 39 Basics of C++ - functions Please note, that a function is specified by the name and the parameter types. The following functions are all different: int exampleFunction(int i, char c); int exampleFunction(double f); int exampleFunction(); int exampleFunction(char c, int i);
40. 40 Basics of C++ - functions Pass by reference, example: void square(int &v) { v = v * v; } In contrast, pass by value: int square(int v) { return v * v; } The parameter v is not copied.
41. 41 Basics of C++: I/O For output use cout, e.g. cout << “The result is: “ << result << endl; For input use cin, e.g. cin >> x; Note that iostream.h must be included via #include <iostream.h>
42. 42 Basics of C++ - arrays Declaration: int numbers[10]; Declaration & Initialisation: int primes[] = { 2, 3, 5, 7, 11, 13, 17, 19 }; Access: numbers[6] = 2483; cout << “The fourth prime is “ << primes[4];
43. 43 Basics of C++ - Strings There aren’t any strings in C++.
44. 44 Basics of C++ - Strings There aren’t any strings in C++. O.k., that’s only half of the truth. In fact, by convention, strings are represented in C++ as ’’ terminated arrays of characters. In addition, the file string.h declares useful string manipulating functions, e.g. strcpy, strlen which deal with ’’ terminated character arrays.
45. 45 Basics of C++ - pointer A pointer points to a memory location which contains data of a particular type. The contents of a pointer is the address of some data Declaration: int *p; double *aDoublePointer;
46. 46 Basics of C++ - pointer In C++ pointer and arrays are strongly related (“array = pointer + memory”). int primes[] = {2, 3, 5, 7, 11 }; int *aPr = primes; aPr++; cout << “The third prime is “ << *(aPr + 2); pointer arithmetic The * operator accesses the data on the memory address
47. 47 Control Structures - Decisions The if statement: if ( x > 0 ) { cout << “positive”; } else { cout << “negative or zero”; }
48. 48 Control Structures - Decisions The switch statement - example: int x; cout << "Enter choice (1, 2, or 3)"; cin >> x; switch(x) { case 1: doThis(); break; case 2: doThat(); break; case 3: doSomethingElse(); break; default: cout << "Sorry, invalid Input"; }
49. 49 Control Structures - Iteration The for loop: for(k = 0; k < 10; k++ ) { cout << “The square of “ << k << “ is “ << k * k << endl; } Terminating condition Start condition Action taking place atthe end of each iteration
50. 50 Control Structures - Iteration The while loop: while ( condition ) { // do something } Equivalent to: for( ; condition ; ) { // do something }
51. 51 Control structures - do … while The do … while loop: do { // something } while( condition); Equivalent to: // something while( condition) { // something }
55. 55 Basics of C++ - pointer A pointer points to a memory location which contains data of a particular type. The contents of a pointer is the address of some data Declaration: int *p; double *aDoublePointer; 2.73817
56. 56 Again: Basics of C++ - arrays Declaration: int numbers[10]; Declaration & Initialisation: int primes[] = { 2, 3, 5, 7, 11, 13, 17, 19 }; Access: numbers[6] = 2483; cout << “The fourth prime is “ << primes[4];
57. 57 Basics of C++ - pointer In C++ pointer and arrays are strongly related (“array = pointer + memory”). int primes[] = {2, 3, 5, 7, 11 }; int *aPr = primes; cout << “The third prime is “ << *(aPr + 3); The same as primes[3] The * operator accesses the data on the memory address
58. 58 What is Object Oriented Programming? Identifying objects and assigning responsibilities to these objects. Objects communicate to other objects by sending messages. Messages are received by the methods of an object An object is like a black box. The internal details are hidden.
59. 59 The two steps of Object Oriented Programming Making Classes: Creating, extending or reusing abstract data types. Making Objects interact: Creating objects from abstract data types and defining their relationships.
60. Example: The Creature class class Creature { private: int yearOfBirth; public: void setYearOfBirth(year) { yearOfBirth = year; } int getYearOfBirth() { return yearOfBirth; } }; born1997
65. Example: The Creature class class Creature { private: int yearOfBirth; public: void setYearOfBirth(year) { yearOfBirth = year; } int getYearOfBirth() { return yearOfBirth; } }; This class has two (public) methods. One to set the attribute value and the other to retrieve the attribute value.
66. Example: The Creature class class Creature { private: int yearOfBirth; public: void setYearOfBirth(year); int getYearOfBirth(); }; void Creature::setYearOfBirth { yearOfBirth = year; } int Creature::getYearOfBirth() { return yearOfBirth; } Note that unless the methods are very short, declaration and implementation is usually separated. The declaration goes into a header file (.h), the implementation in a .cpp file.
67. Example: The Creature class class Creature { private: int yearOfBirth; public: void setYearOfBirth(year) { yearOfBirth = year; } int getYearOfBirth() { return yearOfBirth; } }; This method is an example for a ‘modifier’ method. It modifies the attribute. The method changes the state of the object.
68. Example: The Creature class class Creature { private: int yearOfBirth; public: void setYearOfBirth(year) { yearOfBirth = year; } int getYearOfBirth() { return yearOfBirth; } }; This method is an example for a ‘selector’ method. It returns information about the attribute but does not change the state of the object.
69. 67 Classes & Objects What may be different for all objects in a class, and what remains the same? All the objects in a class may have different attribute values (state data), but their allowed behaviours are all the same. So a class is a blueprint for objects
70. 68 Objects & Classes A class is defined by: A Unique Name Attributes Methods An object is defined by: Identity State Behaviour
71. 69 Instantiating Objects An object is instantiated just like any other data type: int x; char y; Creature z; Declaring z of type ‘creature’ means we have generated an object with the attributes and methods of the class.
72. 70 Multiple Objects Of course we can create many objects of the same class: Creature myDog; Creature theMilkman; Creature myBestFriend; Creates three objects.
73. 71 Sending Messages / Calling Methods. A message is send to an object by calling a method of this object. Use the . (dot) for calling a method of an object. int k; k = theMilkman.getYearOfBirth(); myDog.setYearOfBirth(1998); Messages are sent to my dog and the milkman.
74. 72 Back to the Instantiation... An object is instantiated just like any other data type: int x; char y; Creature z; Here the “default constructor” of the Creature class is automatically called. If we don’t like this we can specify constructors explicitly!
75.
76.
77. The Creature with a copy constructor. Example: Creature myDog(1995); Creature myCat(myDog); creates a cat of the same age as the dog. class Creature { private: int yearOfBirth; public: // … Creature(Creature & otherCreature) { yearOfBirth = otherCreature.getYearOfBirth(); } };
78. 76 Constructors - summary A constructor is always called when an object is created. We can define our own constructors (Note: a class can have more than one constructor). If an object is copied from another object then the copy constructor is called.
79. 77 Again: Objects & Classes A class is defined by: A Unique Name Attributes Methods An object is defined by: Identity State Behaviour
80. 78 Again: Objects & Classes A class is defined by: A Unique Name Attributes Methods An object is defined by: Identity State Behaviour But: We can give a class state and behaviour with the keyword static!
81. Example: The Creature class class Creature { private: int yearOfBirth; static int numberOfAllCreatures = 0; public: Creature() { // Constructor - counts the creatures. numberOfAllCreatures++; } static int getNumberOfAllCreatures() { return numberOfAllCreatures; } }; Note that all objects share the same value of the “class attribute” numberOfAllCreatures.
82. 80 Summary. A class is a blueprint for an object. Objects are created similar to other data types (int, char, …). The construction of an object can be defined by the user. Messages are sent to an object by calling a method. static messes the concept of classes and objects (but is nevertheless useful).