The document provides instructions for printing PowerPoint lectures in black and white to save printer ink. It advises users to select "File > Print", then change the "Color" setting to "Pure Black and White" to print without using color ink.
The document explains the components and functions of MIDI (Musical Instrument Digital Interface), which connects various electronic musical instruments and devices for music creation and editing. It describes key concepts such as channels, timbre, pitch, voices, and patches, outlining their roles in MIDI communication. Additionally, it details the MIDI connections including MIDI In, MIDI Out, and MIDI Through for data transmission.
This document discusses various types of computer input devices. It describes keyboards, mice, joysticks, light pens, trackballs, scanners, microphones, optical character readers, bar code readers, and voice recognition chips as common input devices. Keyboards and mice are highlighted as the most popular input devices, with keyboards allowing text input and mice used to control cursor movement.
VoIP allows users to make phone calls using an Internet connection instead of a traditional phone line. It works by converting voice signals to digital data that is transmitted in packets over the Internet. A VoIP network uses protocols like SIP and RTP to setup calls and transmit voice data. Components include VoIP protocols, gateways to interface with the PSTN, and codecs to compress voice signals. Businesses are attracted to VoIP as it can help reduce costs while improving utilization of bandwidth and network management. However, security risks like hacking and eavesdropping exist since VoIP uses the public Internet.
Bluetooth is a short-range wireless technology standard for exchanging data between devices like mobile phones, headphones, smartwatches and laptops. It was developed in 1994 and first released in 1999. Bluetooth allows for wireless connections between devices that are in close proximity to each other, within a range of around 10 meters. It uses radio waves to enable wireless communication between multiple devices without interference.
Voice over Internet Protocol (VoIP) is a technology that allows users to make voice calls using a broadband Internet connection instead of a regular phone line. VoIP converts voice signals from phone calls into digital data packets that travel over the Internet or a private network using protocols like SIP. This allows for phone calls between computers or VoIP-enabled phones and traditional phones at low cost. Some key requirements for VoIP include software for voice processing, call signaling, and packet processing, as well as hardware like IP phones and gateways to connect to the public switched telephone network. VoIP can be used for calls over the public Internet, between offices on a private network, or with an IP PBX for a business phone system. Advantages
Bluetooth is a wireless technology standard for exchanging data over short distances using short-wavelength UHF radio waves in the industrial, scientific and medical radio bands. It was created in 1994 by Ericsson to replace cables connecting devices like mobile phones, laptops, printers, and other electronic devices. Bluetooth allows for wireless connections between various devices to share information and transmit data wirelessly over short distances of around 10 meters. It uses a radio technology called frequency-hopping spread spectrum to handle interference and improve communication quality.
The document discusses the architecture of web browsers. It describes a reference architecture with 8 subsystems: user interface, browser engine, rendering engine, networking, JavaScript interpreter, XML parser, display backend, and data persistence. It then discusses specific architectures for Mozilla and other browsers. Key aspects covered include session and navigation control, caching, and modeling approaches for sessions, caching, and secure pages. Overall the document provides an overview of common elements in web browser architecture and differences between browser implementations.
The document discusses the architecture of the Internet of Things (IoT). It describes the IoT as a network of physical objects embedded with sensors that can collect and exchange data. The document outlines the history and development of IoT and describes its layered architecture which includes device, network, service, and application layers. It provides examples of current and potential IoT applications in various sectors and discusses security and privacy issues regarding connected devices.
The document provides a comprehensive overview of computer input devices, focusing on keyboards and mice. It outlines the history, types, and connectors of both keyboards and mice, detailing the evolution from typewriters to modern keyboards and from mechanical to optical mice. Each category is further divided into specific types and their respective connection methods.
A smart device is an electronic device capable of interactive and autonomous operation, connected via various protocols. Smart devices can be categorized by form factors such as tabs, pads, and boards, and possess characteristics like dynamic resource access and context awareness. While they offer significant advantages, such as enhanced accessibility and functionality, they also present challenges, including potential addiction and misuse in educational contexts.
This document summarizes the key aspects of routers and Wi-Fi technology. It explains that routers are networking devices that forward data packets between computer networks by reading information in the packets to determine the ultimate destination. It then describes that Wi-Fi uses radio frequency to transmit data wirelessly as an alternative to wired technology. Finally, it outlines some of the advantages of Wi-Fi including no wires, fast deployment and ease of installation, while also noting disadvantages such as slower speeds, limited range, and data security risks compared to wired connections.
The document describes the seven layers of the Open Systems Interconnection (OSI) model from the physical layer to the application layer. It provides details on the responsibilities of each layer, including moving bits at the physical layer, packaging data into frames at the data link layer, routing packets at the network layer, managing flows at the transport layer, maintaining sessions at the session layer, and providing access to applications at the application layer. The presentation layer is responsible for translation, compression, and encryption between the application and network layers.
This document provides an overview of various computer networking concepts and components. It begins with definitions of networking basics like communications and telecommunications. It then describes the essential parts of a basic network including a message, transmitter, medium, receiver and destination. The document outlines different network topologies like bus, ring, star, star-bus and mesh. It also discusses network types like peer-to-peer and client-server networks. The document provides details on common networking media and components including coaxial cable, twisted pair cables, optical fibers, wireless transmission, hubs, gateways, routers, bridges and switches. It concludes with a brief introduction to the IEEE 802 family of standards related to local and metropolitan area networks.
Lec1 :- Data communication and networkDhrumil Shah
The document provides an overview of data communication and networking, covering fundamental characteristics, components, and models involved in data transmission. It discusses the various modes of data flow including simplex, half-duplex, and full-duplex, as well as the physical structures and criteria of networks, types of topologies, and categorization of networks like LANs, WANs, and MANs. Additionally, it highlights the significance of protocols that govern data communications, detailing their syntax, semantics, and timing.
A LAN is a group of computers and devices connected together over a small area through high-speed, relatively inexpensive connections like Ethernet. A MAN connects multiple nearby LANs over an area of a few dozen kilometers, while a WAN connects networks across larger geographic areas like countries. Wired connections offer faster speeds than wireless but require Ethernet cables, while Wi-Fi is more convenient but can have interference issues. LANs are used to share resources, communicate, and ensure access to information for specified groups. Key LAN components include cables, servers, workstations, and hubs or switches. Common LAN topologies include bus, ring, star, tree and hybrid configurations.
TELNET is a standard TCP/IP protocol that allows a user to access resources on a remote host from their local computer. It works by having a TELNET client program establish a TCP connection to a TELNET server on the destination system, allowing the client to send keystrokes and receive output character-by-character. While it was commonly used to administer network devices, TELNET has disadvantages like lack of graphics, security issues, and mouse support. However, it remains useful for configuring some network devices, participating in online communities that value its retro interface, and recreational uses.
FireWire is a standard for connecting digital devices at high speeds. It allows up to 63 devices to connect to a single FireWire bus and transfer data at speeds up to 800 Mbps. FireWire uses peer-to-peer connectivity and provides power to devices through cables. It has advantages over USB for applications involving high-speed transfer of large amounts of digital media like video. FireWire is well-suited for uses like connecting digital cameras and camcorders to computers.
Protocols define rules for formatting and transmitting data over a network. Common protocols include TCP/IP, HTTP, FTP, and SMTP. TCP/IP provides reliable data transmission and IP specifies packet delivery. HTTP is the protocol for web pages and hyperlinks. FTP transfers files between hosts using separate channels for commands and data. SMTP enables email transmission over IP networks.
i-mode was launched in Japan in 1999 as a wireless internet service. Unlike WAP, i-mode uses a wider variety of internet standards over a packet-switched network, allowing access to services like email, games, and financial services. Content is provided through mobile carriers who control billing. i-mode works through a packet network, i-mode server, and information providers. It provides constant connectivity without usage charges. Security includes password protection and securing private networks.
A network switch is a telecommunications device that receives messages and sends them to their intended destinations. It connects network segments or devices and forwards data to one or multiple targets that need to receive it. Switches operate at the data link layer to process and forward data, unlike hubs but similar to routers. They improve network performance by reducing broadcast domains and using hardware to map ports to device addresses.
The document discusses various authentication techniques, including:
- Password-based authentication using clear text passwords, message digests of passwords, and adding randomness with challenges.
- Authentication tokens, which generate one-time passwords based on a seed value stored in the token and authentication server database.
- Multifactor authentication using passwords, biometrics, and authentication tokens or smart cards.
- Certificate-based authentication using digital certificates issued in a public key infrastructure for verifying user identities.
SNMP is a widely used protocol for monitoring network devices and their conditions. It uses a simple client-server architecture with SNMP managers querying SNMP agents running on devices to retrieve information defined in MIBs. SNMP is popular due to its simplicity, though it has limitations in security since it operates over UDP. The document discusses the components of SNMP including managers, agents, MIBs and messages as well as how it works, benefits, limitations and security considerations.
Network security involves protecting computer networks from threats. It targets a variety of threats to stop them from entering or spreading on a network. The objectives of network security are access, confidentiality, authentication, integrity, and non-repudiation. As networks became more common in the 1980s and 1990s, security concerns increased and organizations like CERT were created to address issues. Network security uses multiple layers including firewalls, intrusion prevention systems, antivirus software, and encryption to secure networks from threats.
Ethernet is a family of networking technologies used for local area networks (LANs). It was introduced in 1980 and standardized in 1985, providing data link layer services divided into logical link control and media access control sublayers. Ethernet has evolved to support higher data rates up to 10 Gbps while maintaining compatibility through consistent frame formats and addressing. Fiber optic and twisted pair cable implementations allow Ethernet to scale from campus to wide area networks.
A computer is defined as an electronic device that can process data. The basic idea of computing developed in the 1200s with the invention of the abacus. Major developments included the first mechanical calculators in the 1600s and the first general-purpose electronic computer in the 1940s. A computer has basic components like a processor, memory, input devices like a keyboard and mouse, and output devices like a monitor and printer. It processes data through input, processing, output, and storage cycles using binary language and increasing units of data storage. Computers are now used widely in homes, businesses, medicine, science, and institutions but also have limitations and disadvantages.
The document provides an overview of Internet Protocol (IP) and its integration with Transmission Control Protocol (TCP) within the context of network communication. It covers the functionalities of both IP and TCP, their roles in data transfer, network addressing, and the layered structure of network protocols, particularly within the OSI and TCP/IP models. Additionally, it discusses the evolution of IP addresses, including classification and subnetting, culminating in the introduction of IPv6 as a solution for the limitations of IPv4.
The document provides an overview of Secure Shell (SSH), covering its purpose, history, architecture, and security features. SSH serves as a secure protocol for remote access and file transfer, replacing older systems like Telnet and FTP, while ensuring data encryption and integrity. It highlights the benefits of using SSH, including strong authentication methods, protection against common security threats, and the ability to secure TCP/IP applications.
The document discusses various modes of wireless communication, including Bluetooth, NFC, WiFi, and LiFi, outlining their functions, advantages, and applications. Bluetooth enables short-range data transmission via radio waves, while NFC focuses on fast, secure exchanges over very short distances. WiFi provides internet access wirelessly, and LiFi offers an optical alternative that uses light for data transmission.
Here are some common applications of object-oriented programming and C++:
- Desktop applications like word processors, spreadsheets, etc. The document is an object and formatting, editing operations are methods.
- Game development. Characters, weapons, levels etc. are modeled as objects with behaviors and properties.
- GUI (Graphical User Interface) toolkits like MFC, Qt. Windows, buttons etc. are predefined object classes.
- Web applications and frameworks. Objects represent pages, forms, database entities etc.
- Database connectivity libraries. Objects used to represent rows, columns, connections etc.
- Operating system design. Processes, files, devices modeled as objects.
- Scientific and engineering
The document discusses inheritance in object-oriented programming. It defines inheritance as a mechanism where a subclass inherits attributes and behaviors from its superclass. This allows code reuse and simplifies maintenance. The key points covered include inheritance terminology like "is-a" relationship; defining subclasses using colon syntax; initializing superclass constructors from subclasses; multiple levels and types of inheritance like multiple and diamond inheritance; protected access privilege; function overriding; and the call order of constructors and destructors between superclasses and subclasses.
The document provides a comprehensive overview of computer input devices, focusing on keyboards and mice. It outlines the history, types, and connectors of both keyboards and mice, detailing the evolution from typewriters to modern keyboards and from mechanical to optical mice. Each category is further divided into specific types and their respective connection methods.
A smart device is an electronic device capable of interactive and autonomous operation, connected via various protocols. Smart devices can be categorized by form factors such as tabs, pads, and boards, and possess characteristics like dynamic resource access and context awareness. While they offer significant advantages, such as enhanced accessibility and functionality, they also present challenges, including potential addiction and misuse in educational contexts.
This document summarizes the key aspects of routers and Wi-Fi technology. It explains that routers are networking devices that forward data packets between computer networks by reading information in the packets to determine the ultimate destination. It then describes that Wi-Fi uses radio frequency to transmit data wirelessly as an alternative to wired technology. Finally, it outlines some of the advantages of Wi-Fi including no wires, fast deployment and ease of installation, while also noting disadvantages such as slower speeds, limited range, and data security risks compared to wired connections.
The document describes the seven layers of the Open Systems Interconnection (OSI) model from the physical layer to the application layer. It provides details on the responsibilities of each layer, including moving bits at the physical layer, packaging data into frames at the data link layer, routing packets at the network layer, managing flows at the transport layer, maintaining sessions at the session layer, and providing access to applications at the application layer. The presentation layer is responsible for translation, compression, and encryption between the application and network layers.
This document provides an overview of various computer networking concepts and components. It begins with definitions of networking basics like communications and telecommunications. It then describes the essential parts of a basic network including a message, transmitter, medium, receiver and destination. The document outlines different network topologies like bus, ring, star, star-bus and mesh. It also discusses network types like peer-to-peer and client-server networks. The document provides details on common networking media and components including coaxial cable, twisted pair cables, optical fibers, wireless transmission, hubs, gateways, routers, bridges and switches. It concludes with a brief introduction to the IEEE 802 family of standards related to local and metropolitan area networks.
Lec1 :- Data communication and networkDhrumil Shah
The document provides an overview of data communication and networking, covering fundamental characteristics, components, and models involved in data transmission. It discusses the various modes of data flow including simplex, half-duplex, and full-duplex, as well as the physical structures and criteria of networks, types of topologies, and categorization of networks like LANs, WANs, and MANs. Additionally, it highlights the significance of protocols that govern data communications, detailing their syntax, semantics, and timing.
A LAN is a group of computers and devices connected together over a small area through high-speed, relatively inexpensive connections like Ethernet. A MAN connects multiple nearby LANs over an area of a few dozen kilometers, while a WAN connects networks across larger geographic areas like countries. Wired connections offer faster speeds than wireless but require Ethernet cables, while Wi-Fi is more convenient but can have interference issues. LANs are used to share resources, communicate, and ensure access to information for specified groups. Key LAN components include cables, servers, workstations, and hubs or switches. Common LAN topologies include bus, ring, star, tree and hybrid configurations.
TELNET is a standard TCP/IP protocol that allows a user to access resources on a remote host from their local computer. It works by having a TELNET client program establish a TCP connection to a TELNET server on the destination system, allowing the client to send keystrokes and receive output character-by-character. While it was commonly used to administer network devices, TELNET has disadvantages like lack of graphics, security issues, and mouse support. However, it remains useful for configuring some network devices, participating in online communities that value its retro interface, and recreational uses.
FireWire is a standard for connecting digital devices at high speeds. It allows up to 63 devices to connect to a single FireWire bus and transfer data at speeds up to 800 Mbps. FireWire uses peer-to-peer connectivity and provides power to devices through cables. It has advantages over USB for applications involving high-speed transfer of large amounts of digital media like video. FireWire is well-suited for uses like connecting digital cameras and camcorders to computers.
Protocols define rules for formatting and transmitting data over a network. Common protocols include TCP/IP, HTTP, FTP, and SMTP. TCP/IP provides reliable data transmission and IP specifies packet delivery. HTTP is the protocol for web pages and hyperlinks. FTP transfers files between hosts using separate channels for commands and data. SMTP enables email transmission over IP networks.
i-mode was launched in Japan in 1999 as a wireless internet service. Unlike WAP, i-mode uses a wider variety of internet standards over a packet-switched network, allowing access to services like email, games, and financial services. Content is provided through mobile carriers who control billing. i-mode works through a packet network, i-mode server, and information providers. It provides constant connectivity without usage charges. Security includes password protection and securing private networks.
A network switch is a telecommunications device that receives messages and sends them to their intended destinations. It connects network segments or devices and forwards data to one or multiple targets that need to receive it. Switches operate at the data link layer to process and forward data, unlike hubs but similar to routers. They improve network performance by reducing broadcast domains and using hardware to map ports to device addresses.
The document discusses various authentication techniques, including:
- Password-based authentication using clear text passwords, message digests of passwords, and adding randomness with challenges.
- Authentication tokens, which generate one-time passwords based on a seed value stored in the token and authentication server database.
- Multifactor authentication using passwords, biometrics, and authentication tokens or smart cards.
- Certificate-based authentication using digital certificates issued in a public key infrastructure for verifying user identities.
SNMP is a widely used protocol for monitoring network devices and their conditions. It uses a simple client-server architecture with SNMP managers querying SNMP agents running on devices to retrieve information defined in MIBs. SNMP is popular due to its simplicity, though it has limitations in security since it operates over UDP. The document discusses the components of SNMP including managers, agents, MIBs and messages as well as how it works, benefits, limitations and security considerations.
Network security involves protecting computer networks from threats. It targets a variety of threats to stop them from entering or spreading on a network. The objectives of network security are access, confidentiality, authentication, integrity, and non-repudiation. As networks became more common in the 1980s and 1990s, security concerns increased and organizations like CERT were created to address issues. Network security uses multiple layers including firewalls, intrusion prevention systems, antivirus software, and encryption to secure networks from threats.
Ethernet is a family of networking technologies used for local area networks (LANs). It was introduced in 1980 and standardized in 1985, providing data link layer services divided into logical link control and media access control sublayers. Ethernet has evolved to support higher data rates up to 10 Gbps while maintaining compatibility through consistent frame formats and addressing. Fiber optic and twisted pair cable implementations allow Ethernet to scale from campus to wide area networks.
A computer is defined as an electronic device that can process data. The basic idea of computing developed in the 1200s with the invention of the abacus. Major developments included the first mechanical calculators in the 1600s and the first general-purpose electronic computer in the 1940s. A computer has basic components like a processor, memory, input devices like a keyboard and mouse, and output devices like a monitor and printer. It processes data through input, processing, output, and storage cycles using binary language and increasing units of data storage. Computers are now used widely in homes, businesses, medicine, science, and institutions but also have limitations and disadvantages.
The document provides an overview of Internet Protocol (IP) and its integration with Transmission Control Protocol (TCP) within the context of network communication. It covers the functionalities of both IP and TCP, their roles in data transfer, network addressing, and the layered structure of network protocols, particularly within the OSI and TCP/IP models. Additionally, it discusses the evolution of IP addresses, including classification and subnetting, culminating in the introduction of IPv6 as a solution for the limitations of IPv4.
The document provides an overview of Secure Shell (SSH), covering its purpose, history, architecture, and security features. SSH serves as a secure protocol for remote access and file transfer, replacing older systems like Telnet and FTP, while ensuring data encryption and integrity. It highlights the benefits of using SSH, including strong authentication methods, protection against common security threats, and the ability to secure TCP/IP applications.
The document discusses various modes of wireless communication, including Bluetooth, NFC, WiFi, and LiFi, outlining their functions, advantages, and applications. Bluetooth enables short-range data transmission via radio waves, while NFC focuses on fast, secure exchanges over very short distances. WiFi provides internet access wirelessly, and LiFi offers an optical alternative that uses light for data transmission.
Here are some common applications of object-oriented programming and C++:
- Desktop applications like word processors, spreadsheets, etc. The document is an object and formatting, editing operations are methods.
- Game development. Characters, weapons, levels etc. are modeled as objects with behaviors and properties.
- GUI (Graphical User Interface) toolkits like MFC, Qt. Windows, buttons etc. are predefined object classes.
- Web applications and frameworks. Objects represent pages, forms, database entities etc.
- Database connectivity libraries. Objects used to represent rows, columns, connections etc.
- Operating system design. Processes, files, devices modeled as objects.
- Scientific and engineering
The document discusses inheritance in object-oriented programming. It defines inheritance as a mechanism where a subclass inherits attributes and behaviors from its superclass. This allows code reuse and simplifies maintenance. The key points covered include inheritance terminology like "is-a" relationship; defining subclasses using colon syntax; initializing superclass constructors from subclasses; multiple levels and types of inheritance like multiple and diamond inheritance; protected access privilege; function overriding; and the call order of constructors and destructors between superclasses and subclasses.
Here are the key steps to perform a deep copy in the copy constructor:
1. Allocate new memory for the target object's pointer attribute using new.
2. Loop through the source object's pointer attribute array and copy each element to the target's array.
3. The target object now has its own independently allocated copy of the pointer attribute array.
This avoids the target object sharing/pointing to the source object's pointer attribute memory.
A copy constructor implementing deep copy for the Student class pointer attribute could be:
Student(const Student& s) {
size = s.size;
marks = new double[size];
for(int i=0; i<size;
Lecture05 operator overloading-and_exception_handlingHariz Mustafa
The document discusses operator overloading and exception handling in C++. It describes how to overload operators like +, -, *, / by defining special functions for them and the advantages of doing so. It also explains how to handle exceptions using try, throw, and catch blocks to handle runtime errors.
This document discusses static and dynamic polymorphism in C++. Static polymorphism is determined at compile-time based on the variable type, while dynamic polymorphism uses virtual functions and runtime binding. Making superclass functions virtual allows subclasses to override them and have the correct implementation called through upcasting. Abstract classes with pure virtual functions force subclasses to implement common behaviors.
This document provides an overview of object-oriented programming (OOP) including:
- The history and key concepts of OOP like classes, objects, inheritance, polymorphism, and encapsulation.
- Popular OOP languages like C++, Java, and Python.
- Differences between procedural and OOP like top-down design and modularity.
The document discusses various object-oriented programming concepts in C#, including abstraction, encapsulation, inheritance, polymorphism, interfaces, abstract classes, virtual methods, classes, sealed classes, and provides code examples for foreach loops, switch statements, arrays, data types, boxing and unboxing, overloading and overriding, interfaces, classes vs. structures, access modifiers, abstract classes, and sealed classes.
Domain specific languages are languages created to solve problems in a particular domain. They provide an abstraction layer on top of an existing domain model and can be used by domain experts. Fluent interfaces aim to provide more readable code by implementing an object-oriented API where method calls can be chained together. Fluent interfaces do not require additional libraries and can make code more discoverable and maintainable by creating usage directions for teammates through readable syntax. Extension methods allow quick and easy addition of functionality to existing types, including third party libraries, without modifying the original API.
The document focuses on object-oriented programming concepts, including inheritance, interfaces, and class organization. It explains how derived classes inherit members from base classes and emphasizes the importance of 'is-a' relationships in class design. Additionally, it covers abstract classes, sealed classes, and the use of namespaces for organizing related classes.
The document discusses stacks and queues. It describes stacks as last-in first-out (LIFO) data structures that support push, pop, peek and isEmpty operations. It provides examples of implementing stacks using arrays and linked lists. It also briefly introduces queues as first-in first-out (FIFO) data structures.
The document discusses recursion through the example of a recursive factorial function. It explains that a recursive function calls itself, resulting in the creation of identical nested functions. The recursive process is illustrated step-by-step using the factorial function, showing how each function call passes arguments and returns values until the base case is reached.
Lecture07 the linked-list_as_a_data_structure_v3Hariz Mustafa
This document describes the implementation of a linked list data structure in C++. It defines a Node struct to hold each element and a LinkedList class to manage the list. The LinkedList class implements common list operations like insert, retrieve, find, replace through methods that traverse the linked nodes. A current pointer tracks the active node during operations like getNext to iterate through the list sequentially. The implementation allows storing and accessing elements by value or key in a flexible linked list.
Lecture06 methods for-making_data_structures_v2Hariz Mustafa
The document discusses methods for implementing dynamic data structures using arrays and linked lists. It describes how insertion and removal of elements from an array requires shifting all subsequent elements, which is inefficient. Linked lists allow efficient insertion and removal by using pointer connections between nodes. The document provides an example of traversing a linked list to search for a node matching given criteria.
There are three key points about trees:
1) A tree is a set of linked nodes with a unique path from a root node to every other node. There can be no cycles in a tree.
2) Binary trees restrict nodes to having at most two children. Binary search trees order nodes so that all left children are less than the parent and all right children are greater.
3) Insertion into a binary search tree involves recursively comparing the key of the node to be inserted with the key of each parent node until a suitable position is found.
The document summarizes the key components of the Standard Template Library (STL) including containers, iterators, and algorithms. It describes common STL containers like vector, list, set, map and their uses. Iterators are used to point to container elements and algorithms perform operations on container elements. Examples are provided to demonstrate how to use STL containers like vector, set and map as well as common algorithms like sort.
Object oriented programming (OOP) addresses limitations of procedural programming by dividing programs into objects that encapsulate both data and behaviors. OOP supports features like inheritance, polymorphism, and abstraction. Inheritance allows new classes to inherit attributes and behaviors from parent classes, polymorphism allows the same message to be interpreted differently depending on the object receiving it, and abstraction focuses on essential characteristics without implementation details. These features help make programs more modular, reusable, and maintainable.
20. Object-Oriented Programming Fundamental PrinciplesIntro C# Book
The document outlines the fundamental concepts of object-oriented programming (OOP), including inheritance, encapsulation, abstraction, and polymorphism. It discusses how inheritance allows classes to derive characteristics from parent classes, while encapsulation keeps data hidden and accessible through interfaces. The document emphasizes the importance of strong cohesion and loose coupling to avoid complexities and promote maintainable code.
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 key concepts and principles of object-oriented system design, including definitions of object orientation, identity, encapsulation, and modeling. It covers the history and evolution of object-oriented programming, particularly highlighting the introduction of influential concepts and languages like Simula and Smalltalk. Additionally, it provides insights into the structure of classes and objects, methods, and the importance of encapsulation for data protection and code organization.
This document discusses object-oriented concepts in software development. It describes the four main types of object-oriented paradigms used in the software lifecycle: object-oriented analysis, design, programming, and testing. It then explains some benefits of the object-oriented approach like modularity, reusability, and mapping to real-world entities. Key concepts like inheritance, encapsulation, and polymorphism are defined. The document also provides examples of how classes and objects are represented and compares procedural with object-oriented programming.
The document discusses classes and objects in C++. Some key points:
- A class defines a new user-defined data type that encapsulates data members and member functions. Data members represent the attributes of an object, while member functions represent the behaviors.
- When a class is defined, objects can be instantiated from that class. Objects are instances of a class that allocate memory to store the class's data members. Multiple objects of the same class can exist.
- Member functions can access private data members, while non-member functions cannot. Member functions can be defined inside or outside the class. Static members exist only once per class rather than per object.
- Classes allow data abstraction by hiding implementation
The document presents an overview of object-oriented concepts including objects, classes, methods, attributes, and key principles such as abstraction, encapsulation, and inheritance. It explains the classification of objects and the role of UML in modeling software systems, while detailing the importance of constructor methods and access modifiers for data encapsulation. Additionally, it covers features like method overloading, interfaces, and the use of accessors and mutators to enhance data protection and manipulation in object-oriented programming.
This document discusses object oriented programming using C++. It begins by defining OOP and its key features like encapsulation, inheritance, and polymorphism. It then discusses objects, classes, properties, functions, and how to declare classes with access specifiers. The document provides examples of creating objects from classes and accessing class members using objects. It also discusses defining member functions outside of classes. Finally, it provides exercises for readers to practice implementing classes with data members and member functions.
The document discusses objects and classes in object-oriented programming, explaining that classes define templates for objects with data fields and methods, objects are instances of classes that contain state in their data fields and behavior through methods, and constructors are used to initialize objects when they are created from a class.
This document is a comprehensive course outline for Object-Oriented Programming (OOP) focusing on concepts such as classes, inheritance, polymorphism, templates, and exception handling. It includes detailed explanations of fundamental principles, member functions, constructors, destructors, operator overloading, and access control in C++. The document also provides examples of class implementation and a list of textbooks for further reference.
The document provides an introduction to object oriented programming (OOP) by comparing it to procedural programming. It discusses that OOP treats data as a critical element and ties data more closely to functions that operate on it. It allows decomposition of problems into objects that contain both data and functions. The four main pillars of OOP are discussed as objects, classes, encapsulation, and inheritance. Classes are defined as collections of similar objects that define attributes and behaviors of objects. Constructors and different types of constructors like parameterized and copy constructors are also introduced.
Object oriented programming 6 oop with c++Vaibhav Khanna
This document discusses core concepts of object-oriented programming (OOP). It explains that OOP aims to represent real-world entities as objects that interact by sending messages. It then defines key OOP concepts - objects are run-time entities representing people or things, classes are user-defined types that define objects, encapsulation wraps data and functions into classes, inheritance allows classes to inherit properties from other classes, polymorphism allows the same operation to behave differently based on object type, dynamic binding determines behavior at run-time based on object type, and message passing allows objects to communicate by sending requests.
Here is the Cal class to calculate the area of a rectangle:
#include <iostream>
using namespace std;
class Cal {
private:
double width, height;
public:
void setnum(double a, double b) {
width = a;
height = b;
}
double cal_area() {
return width * height;
}
double getnum() {
return cal_area();
}
};
This document provides an introduction to general object-oriented programming concepts. It discusses that OOP offers a powerful way to develop software by creating objects that encapsulate both data and functions. The core concepts of OOP explained are objects, classes, encapsulation, inheritance, polymorphism, and message passing. Objects communicate by sending and receiving messages, and classes act as templates for creating object instances that share common properties.
Here are the key points about global, static and local objects:
- Global object constructors are called before main() and destructors after main() returns
- Local automatic objects are constructed when they are declared and destructed when they go out of scope
- Static local objects are constructed before main() and destructed after main() returns
- Objects declared within a function are local to that function
- The order of constructor/destructor calls follows the order of object declarations
So in summary, global and static objects persist for the duration of the program while local objects are temporary with lifetime of the block they are declared in.
This document provides an introduction to object-oriented system design. It defines key object-oriented concepts like objects, classes, encapsulation, inheritance, and polymorphism. It also outlines the processes of object-oriented analysis, design, and programming. Finally, it provides examples of how these concepts are implemented in C++, including how to define classes and create objects.
The document explains the principles of C++ object-oriented programming (OOP), covering key concepts such as classes, objects, constructors, destructors, and features like data abstraction, encapsulation, inheritance, dynamic binding, and polymorphism. It emphasizes the role of objects as real-world entities and details the functionalities of member functions, access specifiers, and the processes for creating and managing objects. Additionally, it discusses advanced topics like static members, friend functions, constructor overloading, and differences between normal and static data members.
1. The document introduces classes, explaining concepts like data hiding, abstraction, and encapsulation. It defines a class as a way to bind data and associated functions together to represent real-world entities.
2. A class has four attributes - data members to describe characteristics, member functions for behaviors, an access level to control access, and a class name used to create objects. An example class Account is given with attributes like account number, type, balance and functions like deposit and withdraw.
3. Objects are instances of a class that allow manipulating the data and calling the functions of the class. Some examples of class objects are given.
A class in C++ allows developers to group together related data and functions to represent an object. The document discusses the basics of classes and objects in C++, including:
- What a class is and how it can constrain and manipulate data like an int primitive.
- The components of a class declaration including data members and methods.
- How objects are instances of a class that occupy memory and can access class members.
- The importance of encapsulation through making data private and providing public accessors.
- How to define methods and access class members using the scope resolution operator.
- Best practices like placing class declarations in header files and definitions in cpp files.
A class in C++ allows developers to group together related data and functions to represent an object. The document discusses the basics of classes and objects in C++, including:
- What a class is and how it can constrain and manipulate data like an int primitive.
- The components of a class declaration including data members and methods.
- How objects are instances of a class that occupy memory and can access class members.
- The importance of encapsulation through making data private and providing public accessors.
- How to define methods and access class members using the scope resolution operator.
- Best practices like placing class declarations in header files and definitions in cpp files.
A class in C++ allows developers to group together related data and functions to represent an object. The document discusses the basics of classes and objects in C++, including:
- What a class is and how it can constrain and manipulate data like an int primitive.
- The components of a class declaration including data members and methods.
- How objects are instances of a class that occupy memory and can access class members.
- The importance of encapsulation through making data private and providing public accessors.
- How to define methods and access class members using the scope resolution operator.
- Best practices like placing class declarations in header files and definitions in cpp files.
This document discusses decision making and problem solving. It defines decision making as choosing between alternatives to solve a problem. Decision making can be done individually or in groups. Individual decision making is constrained by imperfect information and time factors, while psychological forces can influence choices. Group decision making has advantages like greater knowledge but also drawbacks like social pressure. The concept of "groupthink" is introduced, where the desire for group cohesion can undermine objective decision making. The document concludes with tips for harnessing the power of decisions, like learning from mistakes and committing to decisions while staying flexible.
This document provides an overview of cognition, problem solving, and critical thinking concepts. It defines cognition as the process of obtaining, transforming, storing, and using information. It discusses two main types of reasoning - formal and everyday. It also covers emotional intelligence, problem solving steps and barriers, ways to generate solutions, and Stephen Covey's method of thinking "win-win". The document is intended to provide foundational information on these topics for students in a critical thinking course.
This document provides an overview of argumentation and critical thinking. It defines an argument as a claim defended with reasons, and identifies the key components of arguments as premises and conclusions. It also distinguishes between simple and complex arguments, and defines five types of non-arguments. The document discusses how to evaluate arguments by assessing whether premises are true and whether premises provide good reasons for the conclusion. It also contrasts deductive and inductive arguments and provides examples of common patterns of reasoning for each. Finally, it defines logical fallacies and identifies two major groups - fallacies of relevance and fallacies of insufficient evidence.
An argument consists of one or more premises intended to support a conclusion. Premises provide evidence or reasons to accept the conclusion. Arguments contain indicators like "therefore" or "so" but these are not always present. Conditionals, reports, unsupported assumptions, illustrations, and explanations are not considered arguments. Arguments differ from explanations in that arguments aim to prove something is the case while explanations provide a causal account for something already accepted as true.
The document defines critical thinking as using cognitive skills and intellectual dispositions to analyze and evaluate arguments, identify biases, form reasonable conclusions, and make intelligent decisions. The goals of critical thinking are to teach students how to reason well and succeed in life by using facts intelligently. Some standards of critical thinking discussed are clarity, precision, accuracy, relevance, consistency, logical correctness, and completeness. The document also discusses benefits of critical thinking in education, careers, and everyday life, as well as common barriers like egocentrism, sociocentrism, assumptions, stereotypes, and wishful thinking.
A fire broke out on a chartered yacht in the South Pacific, destroying much of the boat and killing the skipper and crew. You and your friends managed to save 15 items before abandoning the slowly sinking yacht. You are approximately 1000 miles from the nearest land and must rank these items in order of importance to survive until rescue.
This document provides exercises and discussion questions from a critical thinking textbook. It includes sample answers to questions about moral relativism and inconsistencies that can arise from it. It also provides examples of statements and non-statements, and examines arguments with multiple premises and conclusions.
A man started a courier business called "Street Kids International" to provide employment for street children in developing countries. He had the children deliver packages to embassies by bicycle. Since many children could not read, he had each embassy include a picture of its flag with packages so the children could identify deliveries. This solution helped the business succeed. The children were grateful for the work and later decided to learn to read to make the company more efficient.
The document discusses different types of decision making including individual and group decision making. It notes that individual decision making is done alone based on one's own abilities and factors like personality, emotions, and perceptions, while group decision making involves consensus among members. However, group decisions can be impacted by issues like social pressure, compromise on quality, and phenomena like groupthink, where the desire for harmony overrides objectively evaluating alternatives.
1. Cognition involves obtaining, transforming, storing, retrieving and using information. It processes information actively and purposefully.
2. There are several theories of intelligence including Spearman's theory of general intelligence, Horn and Cattell's two-factor theory, Sternberg's triarchic theory, Gardner's theory of multiple intelligences, and Goleman's theory of emotional intelligence.
3. Problem solving involves identifying the problem, understanding its elements, and generating and evaluating solutions. Common barriers to problem solving are functional fixedness and only applying past methods.
This document outlines logical fallacies of insufficient evidence, including inappropriate appeal to authority, appeal to ignorance, false alternatives, loaded questions, questionable cause, hasty generalization, slippery slope, weak analogy, and inconsistency. These fallacies are mistakes in reasoning where the premises provided fail to sufficiently support the conclusions. Examples of each fallacy type are then briefly described.
This document provides information on language and precise communication. It discusses (1) the need for precision to avoid misunderstandings, (2) ways language can be imprecise including vagueness, overgenerality, and ambiguity, and (3) the importance of precise definitions. Precise definitions are needed to communicate clearly and support arguments. Strategies for defining terms include ostensive, enumerative, subclass, etymological, synonymous, and genus/difference definitions.
This document discusses evaluating arguments by determining whether an argument is "good" based on criteria such as the acceptability of its premises, logical validity, clarity, precision, relevance, consistency, completeness, and fairness. Premises should not conflict with personal experience or background beliefs unless sufficient evidence is provided. Arguments can be refuted by showing a critical premise is false or dubious, or that the conclusion does not logically follow from the premises.
The document discusses logical fallacies, which are mistakes in reasoning that make an argument invalid. There are two major groups of logical fallacies: fallacies of relevance and fallacies of insufficient evidence. Fallacies of relevance occur when the premises of an argument are irrelevant to the conclusion. Some examples of fallacies of relevance include personal attacks, attacking an argument's motive rather than its merit, ignoring one's own failures, and distorting or ignoring parts of an opponent's argument.
The document discusses the key differences between deductive and inductive arguments. It notes that when evaluating an argument, one should consider whether the premises are true and whether the premises provide good reasons to accept the conclusion. For chapter 3, it will only focus on the latter. It provides examples of deductive and inductive arguments. It also outlines different ways to determine whether an argument is deductive or inductive, such as looking for indicator words, applying tests of strict necessity and charity, and identifying if the argument follows a commonly used pattern of deductive or inductive reasoning.
The document discusses several logical fallacies of insufficient evidence including:
1) Inappropriate appeal to authority, which occurs when an unreliable authority is cited.
2) Appeal to ignorance, which claims something is true just because it hasn't been proven false.
3) False alternatives, which insists there are fewer options than actually exist.
4) Loaded questions, which contain hidden assumptions that make it difficult to answer without appearing to endorse those assumptions.
The document defines logical fallacies and fallacies of relevance. It discusses several types of fallacies of relevance including personal attacks, attacking the motive, "look who's talking", scare tactics, appeals to pity, bandwagon arguments, straw man arguments, red herrings, equivocation, and begging the question. Each fallacy is explained with an example.
The document discusses the importance of precision in language to avoid misunderstandings. It provides examples of ways language can be imprecise, such as through vagueness, ambiguity, overgenerality, and different definitions of key terms. It also outlines various strategies for defining terms precisely, such as stipulating definitions, persuasive definitions, lexical definitions, and definitions by genus and difference.
This document provides examples of logical fallacies discussed in Chapter 6 about fallacies of insufficient evidence. It analyzes arguments that commit the fallacies of appeal to ignorance and hasty generalization by failing to provide sufficient evidence to support their conclusions. Another argument uses a slippery slope fallacy in suggesting that watching cartoons will inevitably lead children to become toy-obsessed and out of control without proving the intermediate steps. The document demonstrates how to identify conclusions, analyze evidence used to support them, and determine if the reasoning commits a logical fallacy.
This document provides an overview of deductive and inductive arguments. It explains that deductive arguments have conclusions that necessarily follow from the premises, while inductive arguments have conclusions that probably follow from the premises. Several examples are provided and analyzed to illustrate the difference between deductive and inductive arguments using various tests like the indicator word test, strict necessity test, common pattern test, and principle of charity test.
1. Tip to Save Printer Ink
If you prefer to save your printer ink, follow the
steps below to print the lectures in black text on
white background.
1. In PowerPoint, select File > Print.
2. In the Settings section, locate an item with
value "Color", change it to "Pure Black and
While".
2. Introduction to
Object-Oriented
Programming
Lecture 1
TCP1201 OOPDS
3. Learning Objectives
To understand object & class
To understand abstraction in C++
To understand encapsulation in C++
To categorize similar objects
To categorize objects by Composition
To understand object behaviors
To construct UML Class Diagram
To differentiate between Procedural
Programming and Object-Oriented
Programming
4. What is an “object”?
An object is a computer representation of
real-world person, place, event or anything in
the problem that we are solving.
5. What is an “object”?
An object consists of:
– attributes/data/states/fields/variables (typically
noun), e.g. name, date, balance, size, mark, etc.
– behaviors/procedures/methods/operations/functions
(typically verb), e.g. eat, drive, set, get, push, etc.
We refer to a group of similar objects with the
same attributes and behaviors as a class.
Same attribute does not mean same value for
the attribute, e.g. 2 students have attribute
'name', but the name of each student can be
different.
6. Object and Class
Class: Student.
Attributes: name, student_ID.
Behavior/method: do_homeworks().
Objects of Student class: steve, victor.
7. Object and Class
Steve and victor share the same attributes (name &
student_id), but each object has its own value for the
attributes.
8. Object and Class
We refer to a group of similar objects with the
same attributes and behaviors as a class.
Thus, we can define a class as:
– “a set of objects comprised of the same
attributes and behaviors”.
Thus, we can define object as “a particular
instance of a class”.
9. Object-Oriented Programming
The idea is to design a program to solve a
problem by combining both the data and
procedures (member functions) that operate on
that data into a singe unit called object.
Object2
Data
Object1 Member Object3
Function
Data Data
Member Member
Function Function
Messages
Popular OOP languages: C++, Java, C#, VB, etc.
C++ in TCP1201 focuses on OOP.
10. Steps to Use OOP
1. Identify the objects in the problem.
2. Identify the data/attributes and
operations/methods in each object.
3. Determine how the objects interact with one
another (messaging).
Object2
Data
Object1 Member Object3
Function
Data Data
Member Member
Function Function
Messages
11. 4 Principles of OOP
1. Abstraction – identify the properties that are
important to the user in the problem, and
create representations that are similar to its
original meaning.
2. Encapsulation – combine data and its
operations in a single unit, and hide the
implementation from user.
3. Inheritance – create new classes from existing
classes (Lecture 3).
4. Polymorphism – use the same expression to
denote different operations (Lecture 4).
12. OOP Principle – Abstraction
Abstraction is the process of identifying
important logical properties (object, attributes,
methods) that simplifies the modeling and
working of the problem.
If you are designing a mobile phone, example
properties that are important to the user are the
screen, keypad, UI, cover, etc., but not the
internal working of the processor, how the
screen is actually rendered, etc.
13. OOP in Practice – Abstraction
Assume that we are developing simple system to
keep track of subjects registered by student. It
won't be difficult to identify the following Student
class, its attributes and behaviors/methods.
– We keep the class simple for the purpose of discussion.
Class
Student
Attributes
id
subjects
Methods
show_subjects
register_subject
withdraw_subject
14. OOP in Practice – Abstraction
Based on what we collected and consider
appropriate data type, the following class definition
can be declared:
class Student {
int id;
vector<string> subjects;
void show_subjects();
void register_subject();
void withdraw_subject();
};
The next step is to consider encapsulation – the
2nd OOP principle.
15. OOP Principle – Encapsulation
Encapsulation is the idea that the internal
workings of an object can be hidden from the
outside world.
Encapsulation is performed in 2 ways:
1. We encapsulate how attributes are
accessed via access privileges
(private, public, protected, friend).
2. We encapsulate how methods are
implemented by separating interface and
implementation into different files.
16. Access Privileges in C++
Access privileges allow us to restrict the access
to an object’s members.
4 types of access privileges in C++:
1. private
2. public
3. protected (Lecture 3 Inheritance)
4. friend (Lecture 5 Operator Overloading)
17. private and public Access
Privileges
private members public members
Not accessible from Accessible from
anywhere except for the anywhere including
object itself. outside the class.
We generally declare We generally declare
attributes as private. methods as public.
By default, all members By default, all members
of a C++ class are of a C++ struct are
declared as private if declared as public if
unspecified. unspecified.
18. OOP Principle – Encapsulation
To maintain data integrity, attribute is usually set
hidden/private inside a class to prevent direct
modification from outside the class.
To access or modify an object' attribute from
outside the class, we provide public get or set
methods.
Get method – a method that returns the value of
an attribute but does not modify it.
Set method – a method that modifies the value of
an attribute.
19. OOP in Practice – Encapsulation
Since all our methods are meant to be used from
outside the class, we should declare them as
public.
class Student {
// private by default
int id;
vector<string> subjects;
public: // public from now on
int getId(); // get method for id
void setId (int id); // set method for id
void show_subjects();
void register_subject();
void withdraw_subject();
};
The next step is to consider where to place the
implementation.
20. Placing Implementation
There are 2 ways to place the implementation
(method body) in C++.
Inside of class declaration Outside of class declaration
class Student { class Student {
int id; int id;
... ...
int getId() { int getId(); //prototype
return id; void setId (int id); //prototype
} ...
void setId (int id) { }; // End of class
this->id = id;
} int Student::getId() {
... return id;
}; // End of class }
void Student::setId (int id) {
this->id = id;
}
21. Placing Implementation Outside
of Class Declaration
"::" is a scope resolution operator.
"Student::" indicates that the function is a
method of Student class, not a global function.
class Student {
int id;
...
int getId(); //prototype
void setId (int id); //prototype
...
}; // End of class
int Student::getId() {
return id;
}
void Student::setId (int id) {
this->id = id;
}
22. The this Pointer
We use this pointer to refer to a member of a
class. class Student {
int id;
...
void setId (int id); //prototype
...
}; // End of class
...
void Student::setId (int id) {
this->id = id;
}
id here is attribute id here is function
parameter, not attribute
23. The this Pointer
We use this pointer to refer to a member of a
class.
class Student {
int id;
...
void setId (int id); //prototype
...
}; // End of class
...
void Student::setId (int id) {
id = id; // Wrong, "parameter = parameter".
// Attribute id is not updated.
this->id = id; // Correct, "attribute = parameter".
Student::id = id; // Correct, "attribute = parameter".
}
24. Maintaining Data Integrity with
Encapsulation
By declaring attributes as private and providing
public set methods, we can prevent erroneous
data being entered into the object.
...
// Ensure id entered is within range.
void Student::setId (int id) {
if (id < 1000000000 || id > 9999999999) {
cout << "Error: Id out of range.n";
this->id = 0;
}
else
this->id = id;
}
25. Placing Interface and
Implementation in Separate Files
To bring encapsulation to the next level, we
separate the interfaces and its implementations
into different files.
For every class:
– Place its interface in a .hpp file – called header file, e.g.
Student.hpp.
– Place its implementation in a .cpp file – called source
file, e.g. Student.cpp.
– In every cpp that needs to refer to the class, "#include"
the hpp.
26. HPP Header File
The use of #ifndef, #define & #endif is to
prevent multiple inclusion.
// Student.hpp header file
#ifndef STUDENT_HPP // Prevent multiple inclusion.
#define STUDENT_HPP
#include <iostream>
#include <string>
using namespace std;
class Student {
int id;
vector<string> subjects;
public:
int getId();
void setId (int id);
void show_subjects();
void register_subject();
void withdraw_subject();
}; // End of class
#endif
27. CPP Source File
Every cpp source file that needs to refer to the
class should "#include" the hpp.
// Student.cpp source file
#include "Student.hpp" // Use "", not <>.
int Student::getId() { return id; }
void Student::setId (int id) { this->id = id; }
void Student::show_subjects() { ... }
void Student::register_subject() { ... }
void Student::withdraw_subject() { ... }
// main.cpp source file
#include "Student.hpp" // Use "", not <>.
int main() {
Student s;
s.register_subject();
...
}
28. Why Encapsulation?
1. To maintain data integrity
– By limiting direct access to attributes, we prevent class
users from providing invalid data to the object.
2. To reduce the need for class users to worry
about the implementation
– By separating the interface from the implementation
(shorter class declaration), class users can focus on
using the class instead of being bothered by the
implementation of the class.
3. To improve program maintenance
– Separating the interface from the implementation
enables us to change the implementation without the
class users ever being aware (provided that the
interface remains the same).
29. Categorizing Objects
There might be many objects.
2 common ways to categorize objects are:
1. Categorize similar objects that have the same
attributes and behaviors, e.g. the student
example.
– We have covered this one up until now.
2. Categorize objects by composition, that is
when an attribute of a class is a class by
itself, e.g. a faculty has many students.
30. Categorizing by Composition
When categorizing objects by composition, an attribute of
a class is a class by itself.
Is also referred to as a “has-a” relationship.
Example 1: A faculty has many students (both faculty and
student are classes).
Example 2: Typical corporate organization:
– 3 classes can be identified: Dept, Staff, Data.
– A Dept has Staff and Data.
Personnel Data Personnel Dept.
Sales Dept. Personnel Finance Dept.
Staff
Sales Data Finance Data
Sales Messages Finance
Staff Staff
31. Categorizing by Composition
Sample code for the composition involving faculty
and student.
class Student { // Student is a class.
...
}; // End of class
class Faculty { // Faculty is a class.
string name;
vector<Student> students1; // Composition, attribute is
// a class by itself.
//vector<Student*> students2; // Also composition.
//Student students3[10]; // Also composition.
//Student* students3; // Also composition.
...
};
32. UML Class Diagram
UML is a formal notation to describe models
(representations of things/objects) in sofware
development.
Class Diagram is one type of many diagrams
in UML.
Class Diagram contains 2 elements:
– Classes represent objects with common
attributes, operations, and associations.
– Associations represent relationships that relate
two or more classes.
32
33. Class Diagram
Must have 3 sections.
Class name is placed at the top Student
section.
-id:int
Attributes are placed at the middle -subjects:string[*]
section.
+getId():int
Behaviors are placed at the bottom +setId(id:int):void
section. +show_subjects():void
+register_subject():void
'-' denotes private access privilege. +withdraw_subject():void
'+' denotes public access privilege.
'[*]' denotes "many" (array, vector).
34. Class Diagram
Faculty Student
Association
-name:string -id: int
-students:Student[*] -subjects:string[*]
1 1..n
+getId():int
+setId(id:int):void
+intake()
'n' means many +show_subjects():void
+register_subject():void
+withdraw_subject():void
Associations shows the relationship between
instances of classes, e.g. a faculty has one or more
students, a student belongs to exactly one faculty
only.
35. Revisiting Procedural Programming
C++ in TCP1101 is taught as a procedural programming
language.
In procedural programming, the idea is to design a program
to solve a problem by concentrating on the procedures first
and data second. This approach is known as top-down
design.
Procedures and data are 2 separate units that relate
primarily via function parameter.
Main Program
Data
Function1 Function2 Function3
36. Problems with Procedural Programming
Unrestricted access to global data struct Student {
and procedures. int id;
vector<string> subjects;
Poor modeling of the real world };
(data and procedures are
void register_subject
separated). (Student& a)
Not the way that humans naturally { ... }
think about a situation.
void withdraw_subject
Poor code reusability. (Student& s)
{ ... }
int main() {
Student s;
register_subject (s);
withdraw_subject (s);
}
37. Why Object-Oriented Programming?
Solve the problems of procedural programming.
Restrict access to data and procedures (via
encapsulation).
Better modeling of real world objects (via
abstraction).
– Data and procedures are combined in a single unit.
– Easier to understand, correct, and modify.
Better code reusability – existing objects can be
reused to create new objects via inheritance (Lecture
3).
More useful for development of large and complex
systems.
38. Converting Procedural Program
to OOP
1. Identify the variables and the global functions
that use the variables as parameters, create a
class and include the variables and the global
functions as class members.
2. Make all attributes private. Const attributes can
opt for public.
3. For methods that use the class as
parameter(s), remove ONE such parameter.
Then update the method body to refer to the
member instead of the removed parameter.
39. // Procedural version Point readPoint() {
#include <iostream> Point p;
#include <string> cout << "Enter point x y : ";
#include <cmath> cin >> p.x >> p.y;
using namespace std; return p;
struct Point { }
int x, y; // public by default
}; void printPoint (Point p) {
cout << "(x = " << p.x
Point readPoint(); << ", y = "<< p.y
void printPoint (Point); << ")" << endl;
double distPoint (Point, Point); }
int main() { double distPoint (Point p, Point q)
Point p1 = readPoint(); {
cout << "p1 = "; double dx = p.x - q.x;
printPoint (p1); double dy = p.y - q.y;
cout << endl; double dsquared = dx*dx + dy*dy;
Point p2 = readPoint(); return sqrt (dsquared);
cout << "p2 = "; }
printPoint (p2);
cout << endl << endl;
double d = distPoint (p1, p2);
cout << "Distance p1 to p2 = "
<< d << endl;
}
40. // OOP version double Point::distPoint (Point q) {
#include <iostream> double dx = x - q.x;
#include <string> double dy = y - q.y;
#include <cmath> double dsquared = dx*dx + dy*dy;
using namespace std; return sqrt(dsquared);
}
class Point {
int x, y; // private by default int main() {
public: Point p1, p2;
void readPoint();
void printPoint(); p1.readPoint();
double distPoint (Point q); cout << "p1 = ";
}; p1.printPoint();
cout << endl;
void Point::readPoint() { p2.readPoint();
cout << "Enter point x y : "; cout << "p2 = ";
cin >> x >> y; p2.printPoint();
} cout << endl;
void Point::printPoint() {
cout << "(x = " << x double d = p1.distPoint (p2);
<< ", y = " << y cout << "Distance p1 to p2 = "
<< ")" << endl; << d << endl;
} }