Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
Object Oriented Programming: 7
First Steps in OOP using C++
Prof Neeraj Bhargava
Vaibhav Khanna
Department of Computer Science
School of Engineering and Systems Sciences
Maharshi Dayanand Saraswati University Ajmer
Benefits of OOP
• Through inheritance, we can eliminate redundant code extend the
use of existing
• Classes.
• We can build programs from the standard working modules that
communicate with one another, rather than having to start writing
the code from scratch.
• This leads to saving of development time and higher productivity.
• The principle of data hiding helps the programmer to build secure
program that can not be invaded by code in other parts of a
programs.
• It is possible to have multiple instances of an object to co-exist
without any interference.
Benefits of OOP
• It is possible to map object in the problem domain to
those in the program.
• It is easy to partition the work in a project based on
objects.
• The data-centered design approach enables us to
capture more detail of a model can implemental form.
• Object-oriented system can be easily upgraded from
small to large system.
• Message passing techniques for communication
between objects makes to interface descriptions with
external systems much simpler.
• Software complexity can be easily managed.
Application of OOP
• Real-time system
• Simulation and modeling
• Object-oriented data bases
• Hypertext, Hypermedia, and expert system
• AI and expert systems
• Neural networks and parallel programming
• Decision support and office automation systems
• CIM/CAM/CAD systems
Introduction of C++
• C++ is an object-oriented programming language.
• It was developed by Bjarne Stroustrup at AT&T Bell Laboratories in
Murray Hill, New Jersey, USA, in the early 1980’s.
• Stroustrup, an admirer of Simula67 and a strong supporter of C,
wanted to combine the best of both the languages and create a
more powerful language that could support object-oriented
programming features and still retain the power and elegance of C.
• The result was C++. Therefore, C++ is an extension of C with a major
addition of the class construct feature of Simula67.
• Since the class was a major addition to the original C language,
Stroustrup initially called the new language ‘C with classes’.
• However, later in 1983, the name was changed to C++. The idea of
C++ comes from the C increment operator ++, thereby suggesting
that C++ is an augmented version of C.
Introduction of C++
• The most important facilities that C++ adds on
to C are
– classes, inheritance,
– function overloading and
– operator overloading.
– These features enable creating of abstract data
types,
– inherit properties from existing data types and
support polymorphism, thereby making C++ a
truly object-oriented language.
Printing A String in C++
• #include<iostream>
• Using namespace std;
• int main()
• {
• cout<< “c++ is a very powerful Object
Oriented Programming Language n” ;
• return 0;
• }
Program feature
• Like C, the C++ program is a collection of
function.
• The above example contain only one function
main(). As usual execution begins at main().
• Every C++ program must have a main().
• C++ is a free form language.
• With a few exception, the compiler ignore
carriage return and white spaces.
• Like C, the C++ statements terminate with
semicolons.
Comments
• C++ comment symbol // (double slash) is used for single line
comments
• Comment start with a double slash symbol and terminate at the
end of the line.
• A comment may start anywhere in the line, and whatever follows
till the end of the line is ignored. (Note that there is no closing
symbol)
• The C comment symbols /*, */ are still valid and are more
suitable for multiline comments. The following comment is allowed:
• /* This is an example of
• C++ program to illustrate
• some of its features
• */
Output operator
• cout<< “c++ is a very powerful Object Oriented
Programming Language n” ;
• Causes the string in quotation marks to be displayed on the
screen.
• This statement introduces two new C++ features, cout and
<<.
• The identifier cout (pronounced as C out) is a predefined
object that represents the standard output stream in C++.
• Here, the standard output stream represents the screen.
• The operator << is called the insertion (or put to) operator
The iostream File
• We have used the following #include directive
in the program:
• #include <iostream>
• The #include directive instructs the compiler
to include the contents of the file enclosed
within angular brackets into the source file.
Namespace
• Namespace is a new concept introduced by the ANSI C++
standards committee.
• This defines a scope for the identifiers that are used in a
program. For using the identifier defined in the namespace
scope we must include the using directive, like
– Using namespace std;
• Here, std is the namespace where ANSI C++ standard class
libraries are defined.
• All ANSI C++ programs must include this directive.
• This will bring all the identifiers defined in std to the
current global scope.
• Using and namespace are the new keyword of C++.
Return Type of main()
• In C++, main () returns an integer value to the
operating system.
• Therefore, every main () in C++ should end
with a return (0) statement; otherwise a
warning an error might occur.
• Since main () returns an integer type for main
() is explicitly specified as int.
• Note that the default return type for all
function in C++ is int.
Assignment
• Discuss the benefits and applications of object
oriented programming
• Write a C++ program to print a string “Hello
World” on the console output. Briefly Explain
the elements of the program.

More Related Content

Object oriented programming 7 first steps in oop using c++

  • 1. Object Oriented Programming: 7 First Steps in OOP using C++ Prof Neeraj Bhargava Vaibhav Khanna Department of Computer Science School of Engineering and Systems Sciences Maharshi Dayanand Saraswati University Ajmer
  • 2. Benefits of OOP • Through inheritance, we can eliminate redundant code extend the use of existing • Classes. • We can build programs from the standard working modules that communicate with one another, rather than having to start writing the code from scratch. • This leads to saving of development time and higher productivity. • The principle of data hiding helps the programmer to build secure program that can not be invaded by code in other parts of a programs. • It is possible to have multiple instances of an object to co-exist without any interference.
  • 3. Benefits of OOP • It is possible to map object in the problem domain to those in the program. • It is easy to partition the work in a project based on objects. • The data-centered design approach enables us to capture more detail of a model can implemental form. • Object-oriented system can be easily upgraded from small to large system. • Message passing techniques for communication between objects makes to interface descriptions with external systems much simpler. • Software complexity can be easily managed.
  • 4. Application of OOP • Real-time system • Simulation and modeling • Object-oriented data bases • Hypertext, Hypermedia, and expert system • AI and expert systems • Neural networks and parallel programming • Decision support and office automation systems • CIM/CAM/CAD systems
  • 5. Introduction of C++ • C++ is an object-oriented programming language. • It was developed by Bjarne Stroustrup at AT&T Bell Laboratories in Murray Hill, New Jersey, USA, in the early 1980’s. • Stroustrup, an admirer of Simula67 and a strong supporter of C, wanted to combine the best of both the languages and create a more powerful language that could support object-oriented programming features and still retain the power and elegance of C. • The result was C++. Therefore, C++ is an extension of C with a major addition of the class construct feature of Simula67. • Since the class was a major addition to the original C language, Stroustrup initially called the new language ‘C with classes’. • However, later in 1983, the name was changed to C++. The idea of C++ comes from the C increment operator ++, thereby suggesting that C++ is an augmented version of C.
  • 6. Introduction of C++ • The most important facilities that C++ adds on to C are – classes, inheritance, – function overloading and – operator overloading. – These features enable creating of abstract data types, – inherit properties from existing data types and support polymorphism, thereby making C++ a truly object-oriented language.
  • 7. Printing A String in C++ • #include<iostream> • Using namespace std; • int main() • { • cout<< “c++ is a very powerful Object Oriented Programming Language n” ; • return 0; • }
  • 8. Program feature • Like C, the C++ program is a collection of function. • The above example contain only one function main(). As usual execution begins at main(). • Every C++ program must have a main(). • C++ is a free form language. • With a few exception, the compiler ignore carriage return and white spaces. • Like C, the C++ statements terminate with semicolons.
  • 9. Comments • C++ comment symbol // (double slash) is used for single line comments • Comment start with a double slash symbol and terminate at the end of the line. • A comment may start anywhere in the line, and whatever follows till the end of the line is ignored. (Note that there is no closing symbol) • The C comment symbols /*, */ are still valid and are more suitable for multiline comments. The following comment is allowed: • /* This is an example of • C++ program to illustrate • some of its features • */
  • 10. Output operator • cout<< “c++ is a very powerful Object Oriented Programming Language n” ; • Causes the string in quotation marks to be displayed on the screen. • This statement introduces two new C++ features, cout and <<. • The identifier cout (pronounced as C out) is a predefined object that represents the standard output stream in C++. • Here, the standard output stream represents the screen. • The operator << is called the insertion (or put to) operator
  • 11. The iostream File • We have used the following #include directive in the program: • #include <iostream> • The #include directive instructs the compiler to include the contents of the file enclosed within angular brackets into the source file.
  • 12. Namespace • Namespace is a new concept introduced by the ANSI C++ standards committee. • This defines a scope for the identifiers that are used in a program. For using the identifier defined in the namespace scope we must include the using directive, like – Using namespace std; • Here, std is the namespace where ANSI C++ standard class libraries are defined. • All ANSI C++ programs must include this directive. • This will bring all the identifiers defined in std to the current global scope. • Using and namespace are the new keyword of C++.
  • 13. Return Type of main() • In C++, main () returns an integer value to the operating system. • Therefore, every main () in C++ should end with a return (0) statement; otherwise a warning an error might occur. • Since main () returns an integer type for main () is explicitly specified as int. • Note that the default return type for all function in C++ is int.
  • 14. Assignment • Discuss the benefits and applications of object oriented programming • Write a C++ program to print a string “Hello World” on the console output. Briefly Explain the elements of the program.