This document provides a condensed crash course on C++, beginning with recommended C++ resources. It discusses why C++ is popular and relevant, comparing C and C++. It covers key C++ concepts like efficiency, maintainability, design goals, compatibility with C, classes, structs, access control, constructors/destructors, inheritance, polymorphism, pointers/arrays/references, argument passing, and type conversion. The document emphasizes object-oriented principles and encourages gradual learning of C++ features.
This document provides a condensed crash course on C++, covering recommended C++ resources, why C++ is used, the differences between C and C++, efficiency and maintainability considerations, design goals of C++, compatibility with C, fundamental data types, macros, memory allocation, object-oriented concepts in C++ like classes and structs, access control, constructor/destructor usage, and other key C++ concepts like references, pointers, arrays, inheritance, and polymorphism. The document aims to help readers learn C++ concepts and best practices in an approachable way.
This document provides an introduction to C and C++ programming. It discusses why C++ is a popular and relevant language, highlighting some of its key advantages over C like being more expressive and maintainable. It covers important C++ concepts like classes, inheritance, templates, and the standard template library. The document emphasizes designing classes for simplicity and elegance and using object-oriented principles like encapsulation and polymorphism. It also contrasts C++ programming paradigms like procedural, object-oriented, and generic programming.
This document provides a condensed crash course on C++, beginning with recommended C++ resources. It discusses why C++ is popular and relevant, how C++ is an increment of C while being more expressive and maintainable. It covers key C++ concepts like classes, inheritance, templates, exceptions, and polymorphism. It also compares C and C++ and discusses memory allocation, access control, constructors and destructors, pointers, references, and templates in C++. The document aims to help readers learn C++ and become better programmers.
The document outlines a lecture plan for object oriented programming. It covers topics like structures and classes, function overloading, constructors and destructors, operator overloading, inheritance, polymorphism, and file streams. It provides examples to explain concepts like structures, classes, access specifiers, friend functions, and operator overloading. The document also includes questions for students to practice these concepts.
The document discusses C++ and its evolution over time. Some key points include:
- C++ has been active for over 30 years and remains relevant due to its performance and use in applications like mobile.
- The new C++11 standard adds many new features that make the language more powerful yet easier to use, such as rvalue references, lambdas, and type inference.
- Examples are provided showing how new C++11 features like futures, lambdas and static assertions can be used concisely to solve common programming problems in a more modern style.
The document provides an overview of the C++ programming language. It discusses that C++ was designed by Bjarne Stroustrup to provide Simula's facilities for program organization together with C's efficiency and flexibility for systems programming. It outlines key C++ features such as classes, operator overloading, references, templates, exceptions, and input/output streams. It also covers topics like class definitions, constructors, destructors, friend functions, and operator overloading. The document provides examples of basic C++ programs and explains concepts like compiling, linking, and executing C++ programs.
Objective-C for iOS Application DevelopmentDhaval Kaneria
The document provides an introduction to Objective-C and iPhone development. It discusses key aspects of Objective-C including its syntax which extends C with object-oriented capabilities. Objective-C uses class definitions with interfaces and implementations. Programs create class instances that can receive messages to call methods. Classes can inherit from superclasses and support polymorphism. The document also outlines core concepts like memory management, frameworks for iOS development and examples of Hello World programs.
The document discusses several advanced C++ programming concepts including abstract classes, exception handling, standard libraries, templates, and containers. It defines abstract classes as classes that contain pure virtual functions and cannot be instantiated. Exception handling allows programs to continue running or terminate gracefully after errors using try, catch, and throw blocks. The standard library provides common functions and classes for input/output, strings, and containers. Templates allow writing generic and reusable code for different data types, including class templates and function templates. The Standard Template Library includes common containers like vectors, lists, and maps that store and organize data using templates and iterators.
This document provides a condensed crash course on C++, covering recommended C++ resources, why C++ is used, the differences between C and C++, efficiency and maintainability considerations, design goals of C++, compatibility with C, fundamental data types, macros, memory allocation, object-oriented concepts in C++ like classes and structs, access control, constructor/destructor usage, and other key C++ concepts like references, pointers, arrays, inheritance, and polymorphism. The document aims to help readers learn C++ concepts and best practices in an approachable way.
This document provides an introduction to C and C++ programming. It discusses why C++ is a popular and relevant language, highlighting some of its key advantages over C like being more expressive and maintainable. It covers important C++ concepts like classes, inheritance, templates, and the standard template library. The document emphasizes designing classes for simplicity and elegance and using object-oriented principles like encapsulation and polymorphism. It also contrasts C++ programming paradigms like procedural, object-oriented, and generic programming.
This document provides a condensed crash course on C++, beginning with recommended C++ resources. It discusses why C++ is popular and relevant, how C++ is an increment of C while being more expressive and maintainable. It covers key C++ concepts like classes, inheritance, templates, exceptions, and polymorphism. It also compares C and C++ and discusses memory allocation, access control, constructors and destructors, pointers, references, and templates in C++. The document aims to help readers learn C++ and become better programmers.
The document outlines a lecture plan for object oriented programming. It covers topics like structures and classes, function overloading, constructors and destructors, operator overloading, inheritance, polymorphism, and file streams. It provides examples to explain concepts like structures, classes, access specifiers, friend functions, and operator overloading. The document also includes questions for students to practice these concepts.
The document discusses C++ and its evolution over time. Some key points include:
- C++ has been active for over 30 years and remains relevant due to its performance and use in applications like mobile.
- The new C++11 standard adds many new features that make the language more powerful yet easier to use, such as rvalue references, lambdas, and type inference.
- Examples are provided showing how new C++11 features like futures, lambdas and static assertions can be used concisely to solve common programming problems in a more modern style.
The document provides an overview of the C++ programming language. It discusses that C++ was designed by Bjarne Stroustrup to provide Simula's facilities for program organization together with C's efficiency and flexibility for systems programming. It outlines key C++ features such as classes, operator overloading, references, templates, exceptions, and input/output streams. It also covers topics like class definitions, constructors, destructors, friend functions, and operator overloading. The document provides examples of basic C++ programs and explains concepts like compiling, linking, and executing C++ programs.
Objective-C for iOS Application DevelopmentDhaval Kaneria
The document provides an introduction to Objective-C and iPhone development. It discusses key aspects of Objective-C including its syntax which extends C with object-oriented capabilities. Objective-C uses class definitions with interfaces and implementations. Programs create class instances that can receive messages to call methods. Classes can inherit from superclasses and support polymorphism. The document also outlines core concepts like memory management, frameworks for iOS development and examples of Hello World programs.
The document discusses several advanced C++ programming concepts including abstract classes, exception handling, standard libraries, templates, and containers. It defines abstract classes as classes that contain pure virtual functions and cannot be instantiated. Exception handling allows programs to continue running or terminate gracefully after errors using try, catch, and throw blocks. The standard library provides common functions and classes for input/output, strings, and containers. Templates allow writing generic and reusable code for different data types, including class templates and function templates. The Standard Template Library includes common containers like vectors, lists, and maps that store and organize data using templates and iterators.
This document provides an overview of the C programming language. It discusses the basics of C programming including data types, variables, constants, keywords, operators, input/output statements, decision-making statements, and looping statements. It also covers basic C program structure, storage classes, and introduces different programming paradigms like procedural, structured, object-oriented and monolithic programming.
The document outlines the syllabus for the II Year / III Semester 20IT302 - C++ AND DATA STRUCTURES course. It covers 5 units - (1) Object Oriented Programming Fundamentals, (2) Object Oriented Programming Concepts, (3) C++ Programming Advanced Features, (4) Advanced Non-Linear Data Structures, and (5) Graphs. Some key concepts covered include classes, objects, encapsulation, inheritance, polymorphism, templates, containers, iterators, trees, and graph algorithms.
This document provides an outline for a lesson on data structures and algorithms in C++. It covers the history and overview of C++, basic features of the language like data types and operators, parameter passing techniques, classes and objects, inheritance and polymorphism, header files, input/output, memory management, common class methods like destructors and copy constructors, constants, and templates. The outline also describes key characteristics of C++ and what types of applications it can be used to develop.
C# is a component-oriented programming language that builds on the .NET framework. It has a familiar C-like syntax that is easy for developers familiar with C, C++, Java, and Visual Basic to adopt. C# is fully object-oriented and optimized for building .NET applications. Everything in C# belongs to a class, with basic data types including integers, floats, booleans, characters, and strings. C# supports common programming constructs like variables, conditional statements, loops, methods, and classes. C# can be easily combined with ASP.NET for building web applications in a powerful, fast, and high-level way.
This document provides an overview of object-oriented programming concepts using C++. It discusses key OOP concepts like objects, classes, encapsulation, inheritance, polymorphism, and dynamic binding. It also covers C++ specific topics like functions, arrays, strings, modular programming, and classes and objects in C++. The document is intended to introduce the reader to the fundamentals of OOP using C++.
C++ is an object-oriented programming language that is an extension of C. It was created in 1979 and has undergone several revisions. C++ allows for faster development time and easier memory management compared to C due to features like code reuse, new data types, and object-oriented programming. The document provides an overview of C++ including its history, differences from C, program structure, data types, variables, input/output, and integrated development environments.
The document discusses object-oriented programming concepts and their implementation in C++. It introduces five major principles of OOP: data abstraction, encapsulation, information hiding, polymorphism, and inheritance. It describes how these concepts are realized in C++ through classes, public and private members, operator overloading, and derived classes. The document also contrasts C and C++ features like strong typing and use of new/delete instead of malloc/free for memory management.
This document provides information on various programming language concepts like object-oriented programming, data types, loops, and control flow statements in C++. It defines key OOP concepts like encapsulation, inheritance, and polymorphism. It also explains C++ data types, common loop structures like for, while, and do-while loops, and control statements like break and continue.
This document provides an overview of object-oriented programming concepts in C++ including classes, objects, encapsulation, and templates. It introduces the stack data structure and shows how to implement it using structs in C and then classes in C++. It demonstrates how classes allow data and functions to be bundled together through methods and constructors. The document also discusses templates which allow classes to be parameterized for different data types.
The sole purpose of sharing these slides are to educate the beginners of IT and Computer Science/Engineering. Credits should go to the referred material and also CICRA campus, Colombo 4, Sri Lanka where I taught these in 2017.
This is an intermediate conversion course for C++, suitable for second year computing students who may have learned Java or another language in first year.
This document provides an overview of C++ programming concepts. It introduces C++, focusing on programming concepts and design techniques rather than technical language details. It discusses procedural and object-oriented programming concepts, and how C++ supports both as well as generic programming. The key characteristics of object-oriented programming languages are explained as encapsulation, inheritance, and polymorphism.
This document provides an overview of C++ programming concepts. It introduces C++, focusing on programming concepts and design techniques rather than technical language details. It discusses procedural and object-oriented programming concepts, and how C++ supports both as well as generic programming. The key characteristics of object-oriented programming languages are explained as encapsulation, inheritance, and polymorphism.
This document provides an overview of the CSE42D: Data Structures course. It introduces common data structures like queues and stacks. The goals of the course are to learn fundamental data structures, improve algorithmic problem solving skills, and gain proficiency with UNIX and X-windows. Common data structures are presented, including arrays, linked lists, trees, queues and stacks. Queues and stacks are defined as abstract data types and implementations like circular arrays and linked lists are discussed.
Templates in C++ allow the construction of generic functions and classes that can work with different data types. Some key points:
- Templates support generic programming and reusable components like functions and classes that can handle different data types.
- Function templates define functions that can work with a generic data type T, while class templates define classes that can work with generic data types.
- Templates allow defining functions and classes like stacks once that can work with data types like int, float, char etc. instead of separate definitions for each type.
C++ is an object-oriented programming language that is considered intermediate-level as it includes both high-level and low-level features. It was initially called 'C with Classes' but was renamed to C++ in 1983. C++ was created in the early 1980s at Bell Labs by Bjarne Stroustrup and is based on the C language. C++ is called an object-oriented language because it views problems in terms of objects rather than procedures. Key concepts of object-oriented programming in C++ include classes, objects, data abstraction, encapsulation, polymorphism, and inheritance.
This is an intermediate conversion course for C++, suitable for second year computing students who may have learned Java or another language in first year.
This document discusses templates in C++. Templates allow functions and classes to operate on different data types in a generic way. Function templates define functions that can accept different data types as parameters. Class templates define classes that can work with different types. Examples are provided to demonstrate function and class templates, including defining a max function and pair class that work for both integer and float data types. Templates support generic programming and allow reusable software components to handle different types in a single framework.
The document discusses the C programming language. It provides some key facts about C:
- C was developed in the late 1960s and early 1970s by Dennis Ritchie at Bell Labs.
- C became popular due to its use in developing the UNIX operating system.
- The IT world widely uses C, as evidenced by its use in operating systems like Linux, Windows, and iOS.
- The C language has undergone standardization with standards published in 1989 (C89), 1999 (C99), 2011 (C11), and 2018 (C18).
- C influenced many other popular programming languages and remains one of the most widely used languages today.
This document provides an overview of the C programming language. It discusses the basics of C programming including data types, variables, constants, keywords, operators, input/output statements, decision-making statements, and looping statements. It also covers basic C program structure, storage classes, and introduces different programming paradigms like procedural, structured, object-oriented and monolithic programming.
The document outlines the syllabus for the II Year / III Semester 20IT302 - C++ AND DATA STRUCTURES course. It covers 5 units - (1) Object Oriented Programming Fundamentals, (2) Object Oriented Programming Concepts, (3) C++ Programming Advanced Features, (4) Advanced Non-Linear Data Structures, and (5) Graphs. Some key concepts covered include classes, objects, encapsulation, inheritance, polymorphism, templates, containers, iterators, trees, and graph algorithms.
This document provides an outline for a lesson on data structures and algorithms in C++. It covers the history and overview of C++, basic features of the language like data types and operators, parameter passing techniques, classes and objects, inheritance and polymorphism, header files, input/output, memory management, common class methods like destructors and copy constructors, constants, and templates. The outline also describes key characteristics of C++ and what types of applications it can be used to develop.
C# is a component-oriented programming language that builds on the .NET framework. It has a familiar C-like syntax that is easy for developers familiar with C, C++, Java, and Visual Basic to adopt. C# is fully object-oriented and optimized for building .NET applications. Everything in C# belongs to a class, with basic data types including integers, floats, booleans, characters, and strings. C# supports common programming constructs like variables, conditional statements, loops, methods, and classes. C# can be easily combined with ASP.NET for building web applications in a powerful, fast, and high-level way.
This document provides an overview of object-oriented programming concepts using C++. It discusses key OOP concepts like objects, classes, encapsulation, inheritance, polymorphism, and dynamic binding. It also covers C++ specific topics like functions, arrays, strings, modular programming, and classes and objects in C++. The document is intended to introduce the reader to the fundamentals of OOP using C++.
C++ is an object-oriented programming language that is an extension of C. It was created in 1979 and has undergone several revisions. C++ allows for faster development time and easier memory management compared to C due to features like code reuse, new data types, and object-oriented programming. The document provides an overview of C++ including its history, differences from C, program structure, data types, variables, input/output, and integrated development environments.
The document discusses object-oriented programming concepts and their implementation in C++. It introduces five major principles of OOP: data abstraction, encapsulation, information hiding, polymorphism, and inheritance. It describes how these concepts are realized in C++ through classes, public and private members, operator overloading, and derived classes. The document also contrasts C and C++ features like strong typing and use of new/delete instead of malloc/free for memory management.
This document provides information on various programming language concepts like object-oriented programming, data types, loops, and control flow statements in C++. It defines key OOP concepts like encapsulation, inheritance, and polymorphism. It also explains C++ data types, common loop structures like for, while, and do-while loops, and control statements like break and continue.
This document provides an overview of object-oriented programming concepts in C++ including classes, objects, encapsulation, and templates. It introduces the stack data structure and shows how to implement it using structs in C and then classes in C++. It demonstrates how classes allow data and functions to be bundled together through methods and constructors. The document also discusses templates which allow classes to be parameterized for different data types.
The sole purpose of sharing these slides are to educate the beginners of IT and Computer Science/Engineering. Credits should go to the referred material and also CICRA campus, Colombo 4, Sri Lanka where I taught these in 2017.
This is an intermediate conversion course for C++, suitable for second year computing students who may have learned Java or another language in first year.
This document provides an overview of C++ programming concepts. It introduces C++, focusing on programming concepts and design techniques rather than technical language details. It discusses procedural and object-oriented programming concepts, and how C++ supports both as well as generic programming. The key characteristics of object-oriented programming languages are explained as encapsulation, inheritance, and polymorphism.
This document provides an overview of C++ programming concepts. It introduces C++, focusing on programming concepts and design techniques rather than technical language details. It discusses procedural and object-oriented programming concepts, and how C++ supports both as well as generic programming. The key characteristics of object-oriented programming languages are explained as encapsulation, inheritance, and polymorphism.
This document provides an overview of the CSE42D: Data Structures course. It introduces common data structures like queues and stacks. The goals of the course are to learn fundamental data structures, improve algorithmic problem solving skills, and gain proficiency with UNIX and X-windows. Common data structures are presented, including arrays, linked lists, trees, queues and stacks. Queues and stacks are defined as abstract data types and implementations like circular arrays and linked lists are discussed.
Templates in C++ allow the construction of generic functions and classes that can work with different data types. Some key points:
- Templates support generic programming and reusable components like functions and classes that can handle different data types.
- Function templates define functions that can work with a generic data type T, while class templates define classes that can work with generic data types.
- Templates allow defining functions and classes like stacks once that can work with data types like int, float, char etc. instead of separate definitions for each type.
C++ is an object-oriented programming language that is considered intermediate-level as it includes both high-level and low-level features. It was initially called 'C with Classes' but was renamed to C++ in 1983. C++ was created in the early 1980s at Bell Labs by Bjarne Stroustrup and is based on the C language. C++ is called an object-oriented language because it views problems in terms of objects rather than procedures. Key concepts of object-oriented programming in C++ include classes, objects, data abstraction, encapsulation, polymorphism, and inheritance.
This is an intermediate conversion course for C++, suitable for second year computing students who may have learned Java or another language in first year.
This document discusses templates in C++. Templates allow functions and classes to operate on different data types in a generic way. Function templates define functions that can accept different data types as parameters. Class templates define classes that can work with different types. Examples are provided to demonstrate function and class templates, including defining a max function and pair class that work for both integer and float data types. Templates support generic programming and allow reusable software components to handle different types in a single framework.
The document discusses the C programming language. It provides some key facts about C:
- C was developed in the late 1960s and early 1970s by Dennis Ritchie at Bell Labs.
- C became popular due to its use in developing the UNIX operating system.
- The IT world widely uses C, as evidenced by its use in operating systems like Linux, Windows, and iOS.
- The C language has undergone standardization with standards published in 1989 (C89), 1999 (C99), 2011 (C11), and 2018 (C18).
- C influenced many other popular programming languages and remains one of the most widely used languages today.
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesChristina Lin
Traditionally, dealing with real-time data pipelines has involved significant overhead, even for straightforward tasks like data transformation or masking. However, in this talk, we’ll venture into the dynamic realm of WebAssembly (WASM) and discover how it can revolutionize the creation of stateless streaming pipelines within a Kafka (Redpanda) broker. These pipelines are adept at managing low-latency, high-data-volume scenarios.
Advanced control scheme of doubly fed induction generator for wind turbine us...IJECEIAES
This paper describes a speed control device for generating electrical energy on an electricity network based on the doubly fed induction generator (DFIG) used for wind power conversion systems. At first, a double-fed induction generator model was constructed. A control law is formulated to govern the flow of energy between the stator of a DFIG and the energy network using three types of controllers: proportional integral (PI), sliding mode controller (SMC) and second order sliding mode controller (SOSMC). Their different results in terms of power reference tracking, reaction to unexpected speed fluctuations, sensitivity to perturbations, and resilience against machine parameter alterations are compared. MATLAB/Simulink was used to conduct the simulations for the preceding study. Multiple simulations have shown very satisfying results, and the investigations demonstrate the efficacy and power-enhancing capabilities of the suggested control system.
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELgerogepatton
As digital technology becomes more deeply embedded in power systems, protecting the communication
networks of Smart Grids (SG) has emerged as a critical concern. Distributed Network Protocol 3 (DNP3)
represents a multi-tiered application layer protocol extensively utilized in Supervisory Control and Data
Acquisition (SCADA)-based smart grids to facilitate real-time data gathering and control functionalities.
Robust Intrusion Detection Systems (IDS) are necessary for early threat detection and mitigation because
of the interconnection of these networks, which makes them vulnerable to a variety of cyberattacks. To
solve this issue, this paper develops a hybrid Deep Learning (DL) model specifically designed for intrusion
detection in smart grids. The proposed approach is a combination of the Convolutional Neural Network
(CNN) and the Long-Short-Term Memory algorithms (LSTM). We employed a recent intrusion detection
dataset (DNP3), which focuses on unauthorized commands and Denial of Service (DoS) cyberattacks, to
train and test our model. The results of our experiments show that our CNN-LSTM method is much better
at finding smart grid intrusions than other deep learning algorithms used for classification. In addition,
our proposed approach improves accuracy, precision, recall, and F1 score, achieving a high detection
accuracy rate of 99.50%.
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSIJNSA Journal
The smart irrigation system represents an innovative approach to optimize water usage in agricultural and landscaping practices. The integration of cutting-edge technologies, including sensors, actuators, and data analysis, empowers this system to provide accurate monitoring and control of irrigation processes by leveraging real-time environmental conditions. The main objective of a smart irrigation system is to optimize water efficiency, minimize expenses, and foster the adoption of sustainable water management methods. This paper conducts a systematic risk assessment by exploring the key components/assets and their functionalities in the smart irrigation system. The crucial role of sensors in gathering data on soil moisture, weather patterns, and plant well-being is emphasized in this system. These sensors enable intelligent decision-making in irrigation scheduling and water distribution, leading to enhanced water efficiency and sustainable water management practices. Actuators enable automated control of irrigation devices, ensuring precise and targeted water delivery to plants. Additionally, the paper addresses the potential threat and vulnerabilities associated with smart irrigation systems. It discusses limitations of the system, such as power constraints and computational capabilities, and calculates the potential security risks. The paper suggests possible risk treatment methods for effective secure system operation. In conclusion, the paper emphasizes the significant benefits of implementing smart irrigation systems, including improved water conservation, increased crop yield, and reduced environmental impact. Additionally, based on the security analysis conducted, the paper recommends the implementation of countermeasures and security approaches to address vulnerabilities and ensure the integrity and reliability of the system. By incorporating these measures, smart irrigation technology can revolutionize water management practices in agriculture, promoting sustainability, resource efficiency, and safeguarding against potential security threats.
International Conference on NLP, Artificial Intelligence, Machine Learning an...gerogepatton
International Conference on NLP, Artificial Intelligence, Machine Learning and Applications (NLAIM 2024) offers a premier global platform for exchanging insights and findings in the theory, methodology, and applications of NLP, Artificial Intelligence, Machine Learning, and their applications. The conference seeks substantial contributions across all key domains of NLP, Artificial Intelligence, Machine Learning, and their practical applications, aiming to foster both theoretical advancements and real-world implementations. With a focus on facilitating collaboration between researchers and practitioners from academia and industry, the conference serves as a nexus for sharing the latest developments in the field.
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMHODECEDSIET
Time Division Multiplexing (TDM) is a method of transmitting multiple signals over a single communication channel by dividing the signal into many segments, each having a very short duration of time. These time slots are then allocated to different data streams, allowing multiple signals to share the same transmission medium efficiently. TDM is widely used in telecommunications and data communication systems.
### How TDM Works
1. **Time Slots Allocation**: The core principle of TDM is to assign distinct time slots to each signal. During each time slot, the respective signal is transmitted, and then the process repeats cyclically. For example, if there are four signals to be transmitted, the TDM cycle will divide time into four slots, each assigned to one signal.
2. **Synchronization**: Synchronization is crucial in TDM systems to ensure that the signals are correctly aligned with their respective time slots. Both the transmitter and receiver must be synchronized to avoid any overlap or loss of data. This synchronization is typically maintained by a clock signal that ensures time slots are accurately aligned.
3. **Frame Structure**: TDM data is organized into frames, where each frame consists of a set of time slots. Each frame is repeated at regular intervals, ensuring continuous transmission of data streams. The frame structure helps in managing the data streams and maintaining the synchronization between the transmitter and receiver.
4. **Multiplexer and Demultiplexer**: At the transmitting end, a multiplexer combines multiple input signals into a single composite signal by assigning each signal to a specific time slot. At the receiving end, a demultiplexer separates the composite signal back into individual signals based on their respective time slots.
### Types of TDM
1. **Synchronous TDM**: In synchronous TDM, time slots are pre-assigned to each signal, regardless of whether the signal has data to transmit or not. This can lead to inefficiencies if some time slots remain empty due to the absence of data.
2. **Asynchronous TDM (or Statistical TDM)**: Asynchronous TDM addresses the inefficiencies of synchronous TDM by allocating time slots dynamically based on the presence of data. Time slots are assigned only when there is data to transmit, which optimizes the use of the communication channel.
### Applications of TDM
- **Telecommunications**: TDM is extensively used in telecommunication systems, such as in T1 and E1 lines, where multiple telephone calls are transmitted over a single line by assigning each call to a specific time slot.
- **Digital Audio and Video Broadcasting**: TDM is used in broadcasting systems to transmit multiple audio or video streams over a single channel, ensuring efficient use of bandwidth.
- **Computer Networks**: TDM is used in network protocols and systems to manage the transmission of data from multiple sources over a single network medium.
### Advantages of TDM
- **Efficient Use of Bandwidth**: TDM all
3. Why C++?
• Popular and relevant (used in nearly every application domain):
– end-user applications (Word, Excel, PowerPoint, Photoshop, Acrobat,
Quicken, games)
– operating systems (Windows 9x, NT, XP; IBM’s K42; some Apple OS X)
– large-scale web servers/apps (Amazon, Google)
– central database control (Israel’s census bureau; Amadeus; Morgan-
Stanley financial modeling)
– communications (Alcatel; Nokia; 800 telephone numbers; major
transmission nodes in Germany and France)
– numerical computation / graphics (Maya)
– device drivers under real-time constraints
• Stable, compatible, scalable
4. C vs. C++
• C++ is C incremented
(orig., “C with classes”)
• C++ is more expressive
(fewer C++ source lines needed than C source lines for same program)
• C++ is just as permissive
(anything you can do in C can also be done in C++)
• C++ can be just as efficient
(most C++ expressions need no run-time support;
C++ allows you to
– manipulate bits directly and interface with hardware without regard for safety
or ease of comprehension, BUT
– hide these details behind a safe, clean, elegant interface)
• C++ is more maintainable
(1000 lines of code – even brute force, spaghetti code will work;
100,000 lines of code – need good structure, or new errors will be
introduced as quickly as old errors are removed)
5. Efficiency and Maintainability
90/10 rule: 10% of your program will take 90% of the
processor time to run
optimize what needs to be optimized, but no more
focus on design
6. Design goals of C++
• Backward compatibility with C
(almost completely – every program in K&R is a C++ program –
but additional keywords can cause problems)
• Simplicity, elegance
(few built-in data types, e.g., no matrices)
• Support for user-defined data types
(act like built-in types; N.B. Standard Template Library (STL))
• No compromise in efficiency, run-time or memory
(unless “advanced features” used)
• Compilation analysis to prevent accidental corruption
of data
(type-checking and data hiding)
• Support object-oriented style of programming
7. Compatibility with C
C++ does not allow
• old-style C function declarations
void f(a) int a; {}
• generic function declarations
void f();
void g() { f(2); }
• setting enum to int
enum Dir {Up, Down};
Dir d=1;
• multiple declarations
int i; int i;
• assigning to void *
int* p = malloc(10);
• “implicit int”
signed a = 7;
Other differences:
• const global variables have
internal linkage in C++,
external in C
• extra keywords in C++
void main()
{ int catch = 5; }
• bizarre comments
int f(int a, int b)
{
return a//**/b
;
}
How is C++ not backward compatible with C (C89)?
(For these, C++ is backward
compatible with C99)
8. Purpose of a programming
language
• Programming languages serve two
purposes:
– vehicle for specifying actions to be executed
“close to the machine”
– set of concepts for thinking about what can
be done
“close to the problem being solved”
• Object-oriented C++ excels at both
9. Learning C++
• Goal: Don’t just learn new syntax, but become a
better programmer and designer; learn new and
better ways of building systems
• Be willing to learn C++’s style; don’t force
another style into it
• C++ supports gradual learning
– Use what you know
– As you learn new features and techniques, add those
tools to your toolbox
• C++ supports variety of programming paradigms
10. Programming paradigms
• procedural – implement algorithms via
functions (variables, functions, etc.)
• modular – partition program into modules
(separate compilation)
• object-oriented – divide problem into classes
(data hiding, inheritance)
• abstract – separate interface from
implementation (abstract classes)
• generic – manipulate arbitrary data types
(STL: containers, algorithms)
12. Some C++ concepts
• constructor / destructor / copy constructor
• initialization list
• inheritance
• exceptions
• overloading operators (e.g., assignment operator)
• namespace
• const
• virtual function
• pure virtual (abstract) function
• friend
• template
• standard template library (STL)
• pass by value, pass by reference
• composition versus derivation
13. A simple C++ program
#include <iostream> // std::cout
#include <cstdio> // printf
int main()
{
int a = 5; // 'a' is L-value
float b = 0.9f;
printf("Hello world %d %3.1f n", a, b);
std::cout << "Hello world" << a << " "
<< b << " " << std::endl;
return 0;
}
14. Declarations and definitions
• Declaration:
– extern char c;
– struct User;
– double sqrt(double);
Okay to have many
• Definition:
– char c;
– int count = 1;
– double abs(double a) {
a>0 ? a : -a;
}
Must have exactly one
15. Fundamental types
• bool (true 1, false 0)
• char (could be signed or unsigned
– implementation-defined)
• int (signed by default)
• double
• void (“pseudo-type”)
• enum
• class
• also short, long, struct, float,
wchar_t, etc.)
Do not rely on sizes of these!
(Implementation-dependent)
INTEGRAL
ARITHMETIC
USER-DEFINED
16. Macros
• Dangerous:
– compiler never sees them
source code translation unit
– global
• Instead, use
– const
– inline
– template
– enum
• Ok to use for include guards (“header wrappers”)
• If you must use a macro, give it a long ugly name with
lots of capital letters
Example:
template<typename T>
inline T max(T t){
t>0 ? t : -t;
}
17. Memory allocation
• “on the stack”
– block delimited by {}
– object alive till it falls out of scope
– calls constructor / destructor
• “on the heap”
– new and delete replace malloc, calloc, free
– object exists independently of scope in which it was created
– also “on the free store” or “allocated in dynamic memory”
– be careful: new delete, new[] delete[]
– for safety, same object should both allocate and deallocate
• “local static store” void foo() {
static int i=0;
}
18. Global variables
• Built-in types initialized to 0
(but local variables uninitialized)
• Initialized before main() invoked
• Initialization order:
– within translation unit, same as definition
– between translation units, arbitrary order
file1.cpp
double pi = 3.14;
file2.cpp
double twopi = 2*pi;
Bad!
No guarantee that twopi
will be initialized correctly
19. A class
class Date {
public:
enum Month {Jan, Feb, Mar, ...}
Date(int year, Month month, int day);
int GetDay() const;
void SetDay(int day);
Date& operator+=(int days);
private:
Month m_month;
int m_year, m_day;
};
member
functions
(methods)
member
variables
20. Struct vs. class
• In C++, no difference b/w struct and class
(except default public vs. private)
• In C++, struct can have
– member variables
– methods
– public, private, and protected
– virtual functions
– etc.
• Rule of thumb:
– Use struct when member variables are public (just a container)
– Use class otherwise
21. OO in C
• In C, a struct can have
both member variables
and methods:
• In C++, syntax is
simpler:
void CreateFoo()
{
}
struct Foo
{
void (*Construct)();
int m_data;
};
int main()
{
struct Foo a;
a.Construct = &CreateFoo;
a.Construct();
}
struct Foo
{
Foo()
int m_data;
};
Foo::Foo()
{
}
int main()
{
Foo a;
}
22. Names
• Maintain consistent naming style
– long names for large scope
– short names for small scope
• Don’t start with underscore; reserved for
special facilities
• Avoid similar-looking names: l and 1
• Choosing good names is an art
23. Access control
• Public: visible to everyone
• Private: visible only to the implementer of
this particular class
• Protected: visible to this class and derived
classes
• Good rule of thumb:
– member functions (methods):
• if non-virtual, then public or protected
• if virtual, then private
– member variables should be private
(except in the case of a struct)
24. The big four
• By default, each class has four methods:
– constructor Date();
– destructor ~Date();
– copy constructor
Date(const Date& other);
– assignment operator
Date& operator=(const Date& other);
• These call the appropriate functions on each
member variable
• Be careful: If this is not what you want, then
either override or disallow (by making private)
25. Constructor and destructor
• (Copy) constructor creates object
• Destructor destroys (“cleans up”) object
• Be aware of temporary objects
class Matrix {
Matrix(const Matrix& other);
Matrix operator+(const Matrix& other) const;
Matrix& operator=(const Matrix& other);
};
void foo() {
Matrix a, b, c, d;
a = b + c + d;
}
What functions get called?
(Note: There are ways to speed this up while preserving the syntax)
26. Example
Suppose we have a simple class.
class A {
public:
A() { printf("conn"); }
A(const A& other) { printf("copyconn"); }
~A() { printf("desn"); }
A& operator=(const A& other) { printf("assignn");
return *this;
}
};
27. Example 1
What is the output of the following program?
01 {
02 A a;
03 A* b = new A();
04 *b = a;
05 delete b;
06 A c = a;
07 }
02 con
03 con
04 assign
05 des
06 copycon
07 des
07 des
28. Example 2
What is the output of the following program?
01 void F(const A& f, A* g, A h)
02 {
03 *g = f;
04 }
05 {
06 A a, b;
07 F( a, &b, a);
08 }
06 con
06 con
01 copycon
03 assign
04 des
08 des
08 des
29. Example 3
What is the output of the following program?
01 A F()
02 {
03 A tmp;
04 return tmp;
05 }
06 {
07 A a = F();
08 }
(VC++ 6.0 -- Windows)
03 con
07 copycon
05 des
08 des
(g++ 3.4.3 -- Linux)
07 con
08 des
30. Avoid new and delete
• Whenever possible, avoid ‘new’ and ‘delete’
• Instead create object on stack
• Automatic destructor makes things easier
• No need to worry about forgetting to delete the
object (memory leak) or deleting the wrong
object (crash)
• If you must use ‘new’, then try to keep the
‘delete’ nearby
• This helps code maintenance – otherwise it is
hard to keep track of the new/delete pairs
31. When to use new and delete
• Sometimes you have to use new and
delete
• And sometimes the pair cannot be close
together
• Oh well
• The next slide shows an example where
we need to break both of these rules
32. An example of new/delete
• You have a base class:
class Command { virtual DoSomething(); };
• You have several derived classes:
class CommandAdd : public Command {};
class CommandMove : public Command {};
class CommandSet : public Command {};
• You have a list of objects whose types are unknown at compile time
(polymorphism):
std::vector<Command*> undo_list;
• Must put pointers in list – not actual objects – because the objects
may be of different sizes (among other reasons)
• Someone creates the object and puts its pointer on the list:
undo_list.push_back( new CommandAdd() );
• Later the object is removed from the list and deleted:
Command* com = undo_list.back();
undo_list.pop();
com->DoSomething(); // call a virtual method
delete com;
34. Concrete classes
• A concrete class
– does a single, relatively small thing well and
efficiently
– hides data members (encapsulation)
– provides clean interface
– acts like a built-in type
– is a “foundation of elegant programming” –
Stroustrup
• Don’t underestimate the importance of this
basic C++/OO feature!
35. Class relationships
• OK:
– A calls function from B
– A creates B
– A has a data member of type B
• Bad:
– A uses data directly from B
(without using B’s interface)
• Even worse:
– A directly manipulates data in B
36. Pointers, arrays, references
• Use 0, not NULL (stronger type checking)
• Name of array is equivalent to pointer to
initial element
• Access array using * or []; same
efficiency with modern compiler
• use std::vector, not built-in array,
when possible
• Reference is like a pointer
37. References
• Reference: alternate
name for an object (alias)
• There is no
null reference
• No reference to
a temporary
• Syntax confusing
• Basically a const
dereferenced pointer
with no operations
int &a;
int* c = &a;
int& a = 1;
“get address of”
(not a reference)
int b; int &a = b;
(Now use ‘a’ as ‘b’)
38. Confusing syntax
int a, b;
int c = a * b;
int* d = &a;
int e = *d;
int& f = a;
* means
• multiplication, or
• pointer, or
• dereference pointer
& means
• get address of, or
• reference
Same symbol, different meanings!
39. Pass by X
void f(int a, int* b, int& c)
{
// changes to a are NOT reflected outside the function
// changes to b and c ARE reflected outside the function
}
main()
{
int a, b, c;
f(a, &b, c);
}
pass
by
value
pass
by
pointer
pass
by
reference
DOES
make a copy
does NOT
make a copy
PBP and PBR are different syntax for the same functionality
40. Argument passing / return
• Pass / return by value
– calls copy constructor
– ok for built-in types
int foo(int a) { return 0; }
– performance penalty for structs and classes (temporary objects)
• Pass / return by reference or pointer
– does not call copy constructor
– pass inputs by const reference
– never pass inputs by “plain” reference
void update(int& a); update(2); // error
– pass outputs by pointer
int x = 1; next(x); // should not change x
int x = 1; next(&x); // may change x
– ok to return a ref, or const ref
41. C++ function mechanisms
• Overloaded function names
– Cleaner and safer
print(int);
print(float);
– But beware
print(int); print(int*); print(0);
• Default parameters
void print(int a, int b=0, int c=0);
• Operator overloading
Matrix& operator+=(const Matrix& other);
• Implicit conversion operator
operator int() const {} // converts to int
– Provides convenient syntax, but potentially dangerous so use
sparingly
42. Opaque pointers
• An opaque pointer is used to hide the internal
implementation of a datatype
• Also called Pimpl (pointer to implementation) idiom, or
Cheshire Cat
• Example: The d-pointer is the only private data
member of the class and points to an instance of a
struct defined in the class' implementation file
http://en.wikipedia.org/wiki/Opaque_pointer
43. Explicit type conversion
• C++ casts
– static_cast between 2 related types
(int/float, int/enum, 2 pointers in class hierarchy)
– reinterpret_cast between 2 unrelated types
(int/ptr, pointers to 2 unrelated classes)
– const_cast cast away constness
– dynamic_cast used for polymorphic types
Run-time type info (RTTI)
• Avoid casts, but use these instead of C casts
– e.g., compiler can perform minimal checking for
static_cast, none for reinterpret_cast
44. Namespaces
• Namespace expresses logical grouping
• using declaration
– Don’t use global using except for transition to
older code
– Ok in namespace for composition
– Ok in function for notational convenience
• Namespaces are open
• Unnamed namespaces restrict code to local
translation unit
• Aliases ( namespace ShortName = LongName; )
45. Const
• Const prevents object from being modified (orig., readonly)
• Avoid magic numbers
char a[128];
const int maxn = 128;
char a[maxn];
• Logical constness vs. physical constness
• Const is your friend; use it extensively and consistently
• can cast away constness, but be sure to use mutable
• const pointers:
– const int * const ptr = &a[0]; // const ptr to a const int
– int const * const ptr = &a[0]; // ”
– int * const p2 = &a[0]; // const ptr to an int
– const int * p1 = &a[0]; // ptr to a const int
– int const * p2 = &a[0]; // ”
46. Assert macro
• Assert allows the programmer to explicitly type assumptions about
expected inputs and values
• Use assert generously; it is your friend
• Assert helps to catch bugs early during development
• Assert is removed by precompiler before final release, so no run-
time penalty
• Use assert only to check values; do not change values!!!
#include <assert.h>
int GetValue(int index)
{
assert(index >= 0 && index < array.size());
if (index < 0 || index >= array.size())
return -1; // value should make sense
return array[index];
}
If performance is not a concern,
then it is okay to augment (but
not to replace) assert with an
extra check that will remain in
the final version.
47. Inheritance
• Subclass derived from base class
• Two classes should pass the “ISA” test:
derived class is a base class
class Shape {
};
class Circle : public Shape {
};
• Class hierarchy: means of building classes
incrementally, using building blocks
(subclass becomes base class for someone else)
• Facilitates code reuse
48. Inheritance vs. composition
• Inheritance: “is a”
class Circle : public Shape {
};
• Composition: “has a”
class Circle {
private:
Shape m_shape;
};
• Decision should be based on commonality of
interface
49. Virtual functions
• Function of derived class is called even if
you have only a pointer to the base class
File.h
class Shape
{
virtual void Draw();
};
class Circle : public Shape
{
virtual void Draw();
};
File.cpp
void Func1()
{
Circle mycirc;
Func2(&mycirc);
}
void Func2(Shape* s)
{
s->Draw();
}
// calls Circle::Draw()
50. How a virtual function works
Shape vtable
vfunc1 addr
vfunc2 addr
...
vfuncN addr
vfunc1 addr
vfunc2 addr
...
vfuncN addr
Circle vtable
var1
...
varM
vtable ptr
mycirc
var1
... varN
shape member
variables
circle member
variables
{
{
51. What is the penalty of a virtual
function?
• Space:
– one vtable per class with virtual function(s)
– one pointer per instance
• Time:
– one extra dereference if type not known at
compile time
– no penalty if type known at compile time
(ok to inline a virtual function)
52. Pure virtual function
• Pure virtual function
– Function intentionally undefined
– Same penalty as regular virtual function
• Abstract class
– Contains at least one pure virtual function
– Cannot instantiate; must derive from base class and override pure virtual
function
– Provides an interface
(separates interface from implementation)
• Advice: virtual functions should always be pure virtual
– i.e., “Make non-leaf classes abstract” (Scott Meyers, Item 29)
– Also, “Don’t derive from concrete classes” (Herb Sutter, p. 137)
• More advice: Make virtual functions private (Herb Sutter, p. 134). This
separates the override implementation details from the public interface.
class Shape {
virtual void Draw() = 0;
};
53. Multiple inheritance
• C++ allows you to inherit from multiple
base classes
• Works best if
– exactly one base class passes ISA test
– all other base classes are interfaces
• Advanced feature that is rarely needed
class MyDialog :
public CDialog, Observer {};
MyDialog is a CDialog
MyDialog needs a single method
from Observer (lightweight class)
(see MVC architecture)
54. Polymorphism
• Polymorphism
– “ability to assume different forms”
– one object acts like many different types of objects
(e.g., Shape*)
– getting the right behavior without knowing the type
– manipulate objects with a common set of operations
• Two types:
– Run-time (Virtual functions)
– Compile-time (Templates)
55. Exceptions
• Error handling in C:
– Half of code is error handling
– Dangerous: Easy for programmer to forget
to check return value
void Func() {
int ret;
ret = OpenDevice();
if (ret != 0) error(“Unable to open device”);
ret = SetParams();
if (ret != 0) error(“Unable to set params”);
}
56. Exceptions (cont.)
• Error handling in C++:
– try-catch blocks safer
– separate “real code” from error handling code
void Func() {
try {
OpenDevice();
SetParams();
} catch (const MyException& e) {
e.ReportToUser();
} catch (...) {
abort(1);
}
}
void OpenDevice()
{
if (bad) throw MyException(“Cannot open device”);
}
57. Templates
• Define a class or function once, to work with a variety
of types
• Types may not be known until future
• Better type checking and faster (cf. qsort)
• Specialization can be used to reduce code bloat
• Templates support generic programming
template<typename T>
T Max(T a, T b) { return a>b ? a : b; }
template<typename T>
class Vector {
Vector(int n, T init_val);
T* m_vals;
};
58. Generic programming
• Drawbacks of qsort in <stdlib.h>
– requires a compare function, even if trivial
– loss of efficiency b/c dereferencing pointer
– lost type safety b/c void*
– only works with contiguous arrays
– no control over construction / destruction /
assignment; all swapping done by raw
memory moves
59. Standard Template Library (STL)
• Containers:
– Sequences
• vector – array in contiguous memory (replaces realloc)
• list – doubly-linked list (insert/delete fast)
• deque (“deck”) – double-ended queue
• stack, queue, priority queue
– Associative
• map – dictionary; balanced tree of (key,value) pairs
like array with non-integer indices
• set – map with values ignored (only keys important)
• multimap, multiset (allow duplicate keys)
– Other
• string, basic_string – not necessarily contiguous
• valarray – vector for numeric computation
• bitset – set of N bits
61. std::string
• Example:
#include <string>
void Func()
{
std::string s, t;
char c = 'a';
s.push_back(c); // s is now “a”;
const char* cc = s.c_str(); // get ptr to “a”
const char dd[] = "afaf";
t = dd; // t is now “afaf”;
t = t + s; // append “a” to “afaf”
}
62. std::vector
#include <vector>
void Func()
{
std::vector<int> v(10);
int a0 = v[3]; // unchecked access
int a1 = v.at(3); // checked access
v.push_back(2); // append element to end
v.pop_back(); // remove last element
size_t howbig = v.size(); // get # of elements
v.insert(v.begin()+5, 2); // insert 2 after 5th element
}
• Example:
63. std::vector (cont.)
#include <vector>
#include <algorithm>
void Func()
{
std::vector<int> v(10);
v[5] = 3; // set fifth element to 3
std::vector<int>::const_iterator it
= std::find(v.begin(), v.end(), 3);
bool found = it != v.end();
if (found) {
int three = *it;
int indx = it - v.begin();
int four = 4;
}
}
• Example:
64. Iterators
• iterator – generalized pointer
• Each container has its own type of
iterator
void Func() {
stl::vector<int> v;
stl::vector<int>::const_iterator it = v.begin();
for (it = v.begin() ; it != v.end() ; it++) {
int val = *it;
}
}
65. Types of iterators
template<class InputIterator, class Type>
InputIterator
find( InputIterator _First,
InputIterator _Last,
const Type& _Val );
• Each container provides a
different type
input
forward
bidirectional
random access
output
Types
66. Allocators
• STL written for maximum flexibility
• Each container has an allocator
• Allocator is responsible for memory
management (new/delete)
template < class Type,
class Allocator = allocator<Type> >
class vector {
...
};
• Advice: Ignore allocators
67. Streams
• C
– flush, fprintf, fscanf, sprintf, sscanf
– fgets, getc
• C++
– cout, cin, cerr
68. Buffer overrun
• Never use sprintf!
• Use snprintf instead to avoid buffer
overrun
• Or use std::stringstream