SlideShare ist ein Scribd-Unternehmen logo
1 von 50
PRESENTATION ON     C++ Vs C# BY: SHUBHRA  CHAUHAN
INTRODUCTION C++ was written by Bjarne  Stroustrup at Bell Labs during 1983-1985. C++ is an extension of c. C#'s principal designer and lead architect at Microsoft is Anders Hejlsberg.
OOPs CONCEPT IN C++ AND C++ The basic concepts of oops used in c++  and c#  are as follows: Objects Classes Data abstraction Encapsulation Inheritance Polymorphism
OBJECTS When a program is executed, the objects interact by sending messages to one another. For example, if ‘customer’ and ‘account’ are two objects in a program, then the customer object may send message to account object requesting for a bank balance. Each object contains data and code to manipulate data. CLASS objects contain data and function or code to manipulate that data. The entire set of data and code of an object can be made a user-defined data type with the help of a class. In fact objects are variables of type class. Once a class has been defined, we can create any number of objects associated with that class.
PROGRAM TO ADD TWO NUMBERS USING CLASS IN C++ #include<iostream.h> #include<conio.h> class add { public: void sum(int,int); }; void add::sum(int a,int b) { int s; s=a+b; cout<<”sum is:”<<s; } void main() { add ob1; ob1.sum(6,8); getch(); } Output: sum is:14 Member function Object ob1  of  class add
CLASS IN C# The class is the most important element in C# because everything must be included inside a class . Unlike other languages, the C# compiler doesn’t allow you to declare any variables or methods outside a class. In fact, object-oriented programming is based on the concept of classes. Structs are similar to classes in some aspects and can be used instead of classes in some applications. The main difference between a class and a struct is that the class is a reference type, while the struct is a value type.
CLASS DECLARATION We  declare a class by using the keyword class as follows: class MyClass { // Class implementation } The class implementation (or class body) goes between the braces ({}).
FIELD INITIALIZATION In the following example, we declare the class Point, which contains two fields — x and y: class Point { int x; int y; } We can initialize the fields with values like this example: class Point { int x = 0; int y = 0; } This declaration initializes the fields x and y to their default values.
CLASS INSTANTIATION To create objects from the Point class, use the following statement: Point myPoint;  // create the object We  can also create the object and initialize the fields in the same statement: Point myPoint = new Point(); In the second statement, when the object is created the default constructor is invoked to initialize fields to their default values. Then we can assign each object its own coordinates: p1.x = 15; p1.y = 22;
Using system; class  A { private string name; private void show() { console.write(“welcome to c#”); } public static void main(string [ ] arg) { A obj=new a(); obj.name=arg[0]; obj.show();} } Class name field method Method body Class method Local variable Method invocation Method parameters CLASS EXAMPLE
C#: MAIN METHOD() Main must  –  be named Main  –  return void or int –  be static  –  have (void) or (string[]) parameters public static void Main() { // Main } public static int Main(string[] args) { // Main return result_code; } public static void Main(string[] args) { // Main }
PROGRAM TO ADD TWO NUMBERS USING CLASS IN C# using System; namespace add_num { class sum { static void Main(string[] args) { int a, b,c; Console.WriteLine(&quot;Enter the first no. :&quot;); a = Int32.Parse(Console.ReadLine()); Console.WriteLine(&quot;Enter the second no :&quot;); b = Int32.Parse(Console.ReadLine()); c = a + b; Console.WriteLine(&quot;total :&quot; + c); Console.ReadLine(); } } } Output: Enter the first no.:6 Enter the second no.:8 total: 14
DATA ABSTRACTION Abstraction refers to the act of representing essential features without including the background details. The concept of abstraction relates to the idea of hiding data that are not needed for presentation. The main idea behind data abstraction is to give a clear separation between properties of data type and the associated implementation details. ENCAPSULATION Encapsulation is the most basic concept of OOP. It is the way of combining both data and the functions that operate on that data under a single unit. The only way to access the data is provided by the functions .These functions are considered as member functions in C++. It is not possible to access the data directly.
INHERITANCE I t is the capability to define a new class in terms of an existing class. An existing class is known as a base class and the new class is known as derived class. Inheritance can be of following types: A B A B C A B C D SINGLE INHERITANCE MULTIPLE INHERITANCE HIEARCHICAL INHERITANCE
A B C A B C D MULTILEVEL INHERITANCE HYBRID INHERITANCE
SINGLE INHERITANCE If a class is derived from a single base class, it is called as single inheritance. SYNTAX: class derived_class_name : access_specifier base_class_name { data members of the derived class ; member functions of the derived class ; }; The colon (:), indicates that the class derived_class_name is derived from the class base_class_name. The access_specifier may be public, private or protected. If no access_specifier is specified, it is private by default. The access_specifier indicates whether the members of the base class are privately derived or publicly derived.
MULTIPLE INHERITANCE If a class is derived from more than one base class, it is known as multiple inheritance SYNTAX class derived-class-name : access_specifier Baseclass1, access_specifier Baseclass2, ……… …… .. access_specifier Baseclass_n { members of the derived class ; };
Hierarchical Inheritance When two or more classes are derived from a single base class, then Inheritance is called the hierarchical inheritance. Syntax class derived_class_name1:visibility base_class_name { . . }; class derived_class_name2:visibility base_class_name { . . };
MULTILEVEL INHERITANCE In multilevel inheritance  the derived class can also be derived by an another class, which in turn can further be inherited by another and so on.  Syntax class derived_class_name1:visibility base_class_name { . . }; class derived_class_name2:visibility derived_class_name1 { . . };
PROGRAM USING SINGLE INHERITACE IN C++ #include<iostream.h> #include<conio.h> class  A { public: void add() { int a=5,b=4,s; s=a+b; } }; class B: public A { public: void show() { cout<<”sum is:”<<s; } //class B publically inherit class A//
}; void main() { B obj; obj.add(); obj.show(); getch(); } Output: sum is:9
MERITS OF INHERITANCE Increase reuse and software quality programmers reuse the base class instead of writing new class using well tested base class  helps reduce bugs in applications  that use them Reduce object code size Enhance extensibility and comprehensibility helps support more flexible and extensible architectures  often useful for modeling and classifying hierarchically- related domains
DEMERITS OF INHERITANCE May create deep hierarchies  that  are difficult to understand. May decrease performance slightly. Subclass become dependent on parent class implementation. Complexity for very small programs.
INHERITANCE IN C# C# supports two types of Inheritance mechanisms 1) Implementation Inheritance When a class (type) is derived  from another class(type) such that it inherits all the members of the base type it is Implementation Inheritance 2) Interface Inheritance When a type (class or a struct) inherits only the signatures of the functions from another type it is Interface Inheritance.
PROGRAM USING SINGLE INHERITANCE IN C# using System;  class A {  public int x = 10;  public int y = 20;  }  class B : A  {  public int z = 30;  public void Sum()  {  int sum = x+y+z;  Console.WriteLine(“sum is:{0}”,sum);  }  }
class add  {  public static void Main()  {  Derived d1 = new Derived();  d1.Sum(); }  }  Output: sum is: 60
MERITS OF INHERITANCE IN C# Through inheritance you can very easily convert small system into large systems You can have  lots of classes with the same root but have different implementations of classes. Code reusability through inheritance increased. Code are easy to manage and divided into parent and child classes.
DEMERITS OF INHERITANCE IN C# We can't change the implementation inherited from super classes at runtime (obviously because inheritance is defined at compile time). Inheritance exposes a subclass to details of its parent's class implementation, that's whey it's often said that inheritance breaks encapsulation (in a sense that you really need to focus on interfaces only not implementation, so reusing by sub classing is not always preferred). The tight coupling provided by inheritance makes the implementation of a subclass very bound up with the implementation of a super class that any change in the parent implementation will force the sub class to change. Excessive reusing by sub-classing can make the inheritance stack very deep and very confusing too.
POLYMORPHISM Polymorphism is a key to the power of OOP. It is the concept that supports the capability of data to be processed in more than one form. For example, an operation may exhibit different behaviour in different instances. The behaviour depends upon the types of data used in the operation. Let us consider the operation of addition.For two numbers, the operation will generate a sum. If the operands are strings then the operation would produce a third string by concatenation. Polymorphism is of two types: Compile time Run time
COMPILE TIME POLYMORPHISM Compile time polymorphism is method and operators overloading. It is also called early binding. Method with same name but with different arguments is called method overloading. In method overloading, method performs the different task at the different input parameters. EXAMPLE OF METHOD OVERLOADING class A1 { void hello() { Console.WriteLine(“WELCOME”); } void hello(string s) { Console.WriteLine(“WELCOME {0}”,s); } }
RUN TIME POLYMORPHISM Runtime time polymorphism is done using inheritance and virtual functions. Method overriding is called runtime polymorphism. It is also called late binding. Method overriding occurs when child class declares a method that has the same type arguments as a method declared by one  of its superclass. When overriding a method, you change the behavior of the method for the derived class. Overloading a method simply involves having another method with the same prototype.Method overloading has nothing to do with inheritance or virtual methods.
EXAMPLE OF METHOD OVERRIDING Class parent { virtual void hello() { Console.WriteLine(“Hello from Parent”); } } class child:parent { override void hello() { Console.WriteLine(“Hello from Child”); } } static void main() { parent objParent = new child(); objParent.hello(); } Output Hello from Child.
DIFFRENCE BETWEEN INHERITANCE AND POLYMORPHISM Inheritance is the object oriented feature by which the functionality and features of one class are made available to another class without having to copy paste the code. Polymorphism is the object oriented feature by which multiple methods of a class can coexist with minor differences. Ex: method overloading.
SIMILARITIES BETWEEN C++ & C# Both supports pointers. Capable of defining pre-processor. Both supports structure. Both supports goto statement.
POINTER IN C++ A pointer is a variable that is used to store a memory address. The address is the location of the variable in the memory. Pointers help in allocating memory dynamically. The general form of declaring pointer is:- type *variable_name; type is the base type of the pointer and variable_name is the name of the variable of the pointer. Pointer Operators There are two important pointer operators such as ‘*’ and '&' .The ‘&’ is a unary operator. The unary operator returns the address of the memory where a variable is located.  The ‘*’ operator is called the indirection operator. It returns the contents of the memory location pointed to.  The indirection operator is also called deference operator.
PROGRAM USING POINTER #include<iostream.h> #include<conio.h> void main( ) { int *x; int c=100; x=&c; cout << &quot; The address of the memory location of x : &quot; << x <<endl; cout << &quot; The contents of the pointer x : &quot; << *x << endl; getch( ); } Output: The address of the memory location of x: 01212FF78 The contents of the pointer x: 100
POINTER IN C# Pointers are special kind of variables which hold addresses other variables.To create a pointer we  use the following declaration: type* variable_name;  As a type may be used each type that is not a reference-type and does not contain reference-type field. It can be only: sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, bool any enum-type. Pointer are only be used in unsafe context.
PROGRAM USING POINTER using System; class  A { public unsafe static void main() { int i=10; int *p; p=&x; console.WriteLine(“address is”+ p); console.WriteLine(“value is”+ *p); } } Output Address is 0012HM95 value is 10';
PREPROCESSOR IN C ++ The pre-processor is a utility program, which processes special instructions that can be or are written in a C++  program. These instructions can be include a library or some special instructions to the compiler about some certain terms used in the program. Pre-processor directives start with ‘#’ character.Pre-processor directives starts with # character. C++ supports the following preprocessor directives: #include #define #if #elif #else #endif #ifndef #ifdef #undef
PREPROCESSOR IN C# A preprocessor directive must be the only instruction on a line. Preprocessing directives are lines in your program that start with '#'. Whitespace is allowed before and after the '#'. The '#' is followed by an identifier that is the directive name. For example, '#define' is the directive . The C# language's preprocessor directives are as follows: #if #else #elif #endif #define #undef #error #line
STRUCTURE Structure is a collection of variables under a single name. Variables can be of any type: int, float, char etc.   Declaring a Structure: The structure is declared by using the keyword struct followed by structure name, also called a tag. Then the structure members (variables) are defined with their type and variable names inside the open and close braces { and } . Finally, the closed braces end with a semicolon denoted as ; following the statement. Struct student { char name[20]; int marks; int total; }; Keyword Structure name Structure member
Goto statement The goto statement  translates the program control directly to a labeled statement. It takes following form: goto identifier; goto case const-exp.; goto default;
DIFFERENCES BETWEEN C++ AND C# Most of the C# features are similar to those of C++. However, C# provides various additional features that make it a more type –safe and web enabled language. Various points of different between C# and C++ are : C# does not use semicolon at the end of class definition. C# does not contain any default constructor. Objects in C# can only be created using new keywords. C# does not support multiple inheritance C# does not support the header file,# include. Continue..
Continue... C++ supports operator overloading but C# does not. C++ is not completely object oriented based but C# is completely object oriented. C# have garbage collection capability but it is absent in C++ . C++ is statically typed whereas C# is dynamic in nature. C# is high level programming language while C++ is a middle level programming language.
ADVANTAGES OF C++ Better performance Portability Multiple inheritance Support for global variables, function and constants
DISADVANTAGE OF C++ Complex in very large high level program. C++ can't support garbage collection. C++ is not secure because it have pointer, friend function and global variable. When C++ used for web applications complex and difficult to debug .
ADVANTAGES OF C# Garbage collection Huge .NET framework library Supports constructor chaining No need for header files and #include Access to class members/ function is done only by the dot(. )
DISADVANTAGE OF C# C# is less flexible than C++.  C# depends greatly on .NET framework, anything that is not found in the .NET framework will be difficult to implement. All though portability is what with C# was developed, C# programs are largely for Microsoft Windows Environment which although happens to be the most widely used Operating system over the globe, but with Open Source technologies, especially platforms like Linux catching up, C# still has to long way to go. This is one major shortcoming of C# . Although C# programs can be written as little as a text editor and compiled using command line, it still needs the .NET framework to be present on the system, which cripples down the portability in the development of C# programs by a large amount, and makes it more Microsoft Windows dependent.
CONCLUSION While there are a number of differences between C++ and C#, the syntax of C# is not very different from C++ and the transition to the new language is more easy with  .NET framework. Also .NET's cross language interoperability can give us  the ability to use C++ and C# together Finally, if we want to use a strong programming language like C++ with the simplicity of VB  than we  can use C# powered  with CLR.
REFERENCES www.google.com www.msdnmicrosoft.com www.wikipedia.org

Weitere ähnliche Inhalte

Was ist angesagt?

ITFT-Constants, variables and data types in java
ITFT-Constants, variables and data types in javaITFT-Constants, variables and data types in java
ITFT-Constants, variables and data types in javaAtul Sehdev
 
Inheritance in oops
Inheritance in oopsInheritance in oops
Inheritance in oopsHirra Sultan
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#Doncho Minkov
 
Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2MOHIT TOMAR
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++Bishal Sharma
 
Control structures in java
Control structures in javaControl structures in java
Control structures in javaVINOTH R
 
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++Tech_MX
 
Constructor overloading & method overloading
Constructor overloading & method overloadingConstructor overloading & method overloading
Constructor overloading & method overloadinggarishma bhatia
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .NetGreg Sohl
 
Java - Generic programming
Java - Generic programmingJava - Generic programming
Java - Generic programmingRiccardo Cardin
 
Method Overloading In Java
Method Overloading In JavaMethod Overloading In Java
Method Overloading In JavaCharthaGaglani
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++rprajat007
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteTushar B Kute
 

Was ist angesagt? (20)

C# String
C# StringC# String
C# String
 
ITFT-Constants, variables and data types in java
ITFT-Constants, variables and data types in javaITFT-Constants, variables and data types in java
ITFT-Constants, variables and data types in java
 
Inheritance in oops
Inheritance in oopsInheritance in oops
Inheritance in oops
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
 
Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
 
Java 8 Lambda and Streams
Java 8 Lambda and StreamsJava 8 Lambda and Streams
Java 8 Lambda and Streams
 
Control structures in java
Control structures in javaControl structures in java
Control structures in java
 
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++
 
Constructor overloading & method overloading
Constructor overloading & method overloadingConstructor overloading & method overloading
Constructor overloading & method overloading
 
inheritance c++
inheritance c++inheritance c++
inheritance c++
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
 
File Handling in C++
File Handling in C++File Handling in C++
File Handling in C++
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
 
Java - Generic programming
Java - Generic programmingJava - Generic programming
Java - Generic programming
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
Method Overloading In Java
Method Overloading In JavaMethod Overloading In Java
Method Overloading In Java
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
 

Andere mochten auch

C++ vs C#
C++ vs C#C++ vs C#
C++ vs C#sudipv
 
difference between c c++ c#
difference between c c++ c#difference between c c++ c#
difference between c c++ c#Sireesh K
 
C# for C++ Programmers
C# for C++ ProgrammersC# for C++ Programmers
C# for C++ Programmersrussellgmorley
 
Difference between Java and c#
Difference between Java and c#Difference between Java and c#
Difference between Java and c#Sagar Pednekar
 
Introduction To Dotnet
Introduction To DotnetIntroduction To Dotnet
Introduction To DotnetSAMIR BHOGAYTA
 
01 c++ Intro.ppt
01 c++ Intro.ppt01 c++ Intro.ppt
01 c++ Intro.pptTareq Hasan
 
Difference between java and c#
Difference between java and c#Difference between java and c#
Difference between java and c#TECOS
 
Summer training in c++
Summer training in c++Summer training in c++
Summer training in c++DUCC Systems
 
C & C++ Training Centre in Ambala! BATRA COMPUTER CENTRE
C & C++ Training Centre in Ambala! BATRA COMPUTER CENTREC & C++ Training Centre in Ambala! BATRA COMPUTER CENTRE
C & C++ Training Centre in Ambala! BATRA COMPUTER CENTREjatin batra
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming CourseDennis Chang
 
Difference between c# generics and c++ templates
Difference between c# generics and c++ templatesDifference between c# generics and c++ templates
Difference between c# generics and c++ templatesUmar Ali
 

Andere mochten auch (20)

C++ vs C#
C++ vs C#C++ vs C#
C++ vs C#
 
Differences between c and c++
Differences between c and c++Differences between c and c++
Differences between c and c++
 
C vs c++
C vs c++C vs c++
C vs c++
 
difference between c c++ c#
difference between c c++ c#difference between c c++ c#
difference between c c++ c#
 
C vs c++
C vs c++C vs c++
C vs c++
 
Ppt of c vs c#
Ppt of c vs c#Ppt of c vs c#
Ppt of c vs c#
 
C# for C++ Programmers
C# for C++ ProgrammersC# for C++ Programmers
C# for C++ Programmers
 
Difference between Java and c#
Difference between Java and c#Difference between Java and c#
Difference between Java and c#
 
Java vs .Net
Java vs .NetJava vs .Net
Java vs .Net
 
Brain chips
Brain chipsBrain chips
Brain chips
 
Oops ppt
Oops pptOops ppt
Oops ppt
 
Introduction To Dotnet
Introduction To DotnetIntroduction To Dotnet
Introduction To Dotnet
 
01 c++ Intro.ppt
01 c++ Intro.ppt01 c++ Intro.ppt
01 c++ Intro.ppt
 
C++ ppt
C++ pptC++ ppt
C++ ppt
 
Difference between java and c#
Difference between java and c#Difference between java and c#
Difference between java and c#
 
Summer training in c++
Summer training in c++Summer training in c++
Summer training in c++
 
C & C++ Training Centre in Ambala! BATRA COMPUTER CENTRE
C & C++ Training Centre in Ambala! BATRA COMPUTER CENTREC & C++ Training Centre in Ambala! BATRA COMPUTER CENTRE
C & C++ Training Centre in Ambala! BATRA COMPUTER CENTRE
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
 
Difference between c# generics and c++ templates
Difference between c# generics and c++ templatesDifference between c# generics and c++ templates
Difference between c# generics and c++ templates
 
Vowels walking
Vowels walkingVowels walking
Vowels walking
 

Ähnlich wie Ppt of c++ vs c#

Ähnlich wie Ppt of c++ vs c# (20)

C++ presentation
C++ presentationC++ presentation
C++ presentation
 
OOPS IN C++
OOPS IN C++OOPS IN C++
OOPS IN C++
 
Opp concept in c++
Opp concept in c++Opp concept in c++
Opp concept in c++
 
Inheritance
InheritanceInheritance
Inheritance
 
Introduction to object oriented programming concepts
Introduction to object oriented programming conceptsIntroduction to object oriented programming concepts
Introduction to object oriented programming concepts
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer Programming
 
Inheritance
InheritanceInheritance
Inheritance
 
C++ Notes
C++ NotesC++ Notes
C++ Notes
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
 
Interoduction to c++
Interoduction to c++Interoduction to c++
Interoduction to c++
 
Unit 3 notes.pdf
Unit 3 notes.pdfUnit 3 notes.pdf
Unit 3 notes.pdf
 
C Sharp: Basic to Intermediate Part 01
C Sharp: Basic to Intermediate Part 01C Sharp: Basic to Intermediate Part 01
C Sharp: Basic to Intermediate Part 01
 
My c++
My c++My c++
My c++
 
Interfaces c#
Interfaces c#Interfaces c#
Interfaces c#
 
Synapseindia dot net development
Synapseindia dot net developmentSynapseindia dot net development
Synapseindia dot net development
 
Chapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).pptChapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).ppt
 
Class notes(week 6) on inheritance and multiple inheritance
Class notes(week 6) on inheritance and multiple inheritanceClass notes(week 6) on inheritance and multiple inheritance
Class notes(week 6) on inheritance and multiple inheritance
 
chapter-10-inheritance.pdf
chapter-10-inheritance.pdfchapter-10-inheritance.pdf
chapter-10-inheritance.pdf
 
Inheritance.pptx
Inheritance.pptxInheritance.pptx
Inheritance.pptx
 
Inheritance and its types explained.ppt
Inheritance and its types  explained.pptInheritance and its types  explained.ppt
Inheritance and its types explained.ppt
 

Kürzlich hochgeladen

Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 

Kürzlich hochgeladen (20)

Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 

Ppt of c++ vs c#

  • 1. PRESENTATION ON C++ Vs C# BY: SHUBHRA CHAUHAN
  • 2. INTRODUCTION C++ was written by Bjarne Stroustrup at Bell Labs during 1983-1985. C++ is an extension of c. C#'s principal designer and lead architect at Microsoft is Anders Hejlsberg.
  • 3. OOPs CONCEPT IN C++ AND C++ The basic concepts of oops used in c++ and c# are as follows: Objects Classes Data abstraction Encapsulation Inheritance Polymorphism
  • 4. OBJECTS When a program is executed, the objects interact by sending messages to one another. For example, if ‘customer’ and ‘account’ are two objects in a program, then the customer object may send message to account object requesting for a bank balance. Each object contains data and code to manipulate data. CLASS objects contain data and function or code to manipulate that data. The entire set of data and code of an object can be made a user-defined data type with the help of a class. In fact objects are variables of type class. Once a class has been defined, we can create any number of objects associated with that class.
  • 5. PROGRAM TO ADD TWO NUMBERS USING CLASS IN C++ #include<iostream.h> #include<conio.h> class add { public: void sum(int,int); }; void add::sum(int a,int b) { int s; s=a+b; cout<<”sum is:”<<s; } void main() { add ob1; ob1.sum(6,8); getch(); } Output: sum is:14 Member function Object ob1 of class add
  • 6. CLASS IN C# The class is the most important element in C# because everything must be included inside a class . Unlike other languages, the C# compiler doesn’t allow you to declare any variables or methods outside a class. In fact, object-oriented programming is based on the concept of classes. Structs are similar to classes in some aspects and can be used instead of classes in some applications. The main difference between a class and a struct is that the class is a reference type, while the struct is a value type.
  • 7. CLASS DECLARATION We declare a class by using the keyword class as follows: class MyClass { // Class implementation } The class implementation (or class body) goes between the braces ({}).
  • 8. FIELD INITIALIZATION In the following example, we declare the class Point, which contains two fields — x and y: class Point { int x; int y; } We can initialize the fields with values like this example: class Point { int x = 0; int y = 0; } This declaration initializes the fields x and y to their default values.
  • 9. CLASS INSTANTIATION To create objects from the Point class, use the following statement: Point myPoint; // create the object We can also create the object and initialize the fields in the same statement: Point myPoint = new Point(); In the second statement, when the object is created the default constructor is invoked to initialize fields to their default values. Then we can assign each object its own coordinates: p1.x = 15; p1.y = 22;
  • 10. Using system; class A { private string name; private void show() { console.write(“welcome to c#”); } public static void main(string [ ] arg) { A obj=new a(); obj.name=arg[0]; obj.show();} } Class name field method Method body Class method Local variable Method invocation Method parameters CLASS EXAMPLE
  • 11. C#: MAIN METHOD() Main must – be named Main – return void or int – be static – have (void) or (string[]) parameters public static void Main() { // Main } public static int Main(string[] args) { // Main return result_code; } public static void Main(string[] args) { // Main }
  • 12. PROGRAM TO ADD TWO NUMBERS USING CLASS IN C# using System; namespace add_num { class sum { static void Main(string[] args) { int a, b,c; Console.WriteLine(&quot;Enter the first no. :&quot;); a = Int32.Parse(Console.ReadLine()); Console.WriteLine(&quot;Enter the second no :&quot;); b = Int32.Parse(Console.ReadLine()); c = a + b; Console.WriteLine(&quot;total :&quot; + c); Console.ReadLine(); } } } Output: Enter the first no.:6 Enter the second no.:8 total: 14
  • 13. DATA ABSTRACTION Abstraction refers to the act of representing essential features without including the background details. The concept of abstraction relates to the idea of hiding data that are not needed for presentation. The main idea behind data abstraction is to give a clear separation between properties of data type and the associated implementation details. ENCAPSULATION Encapsulation is the most basic concept of OOP. It is the way of combining both data and the functions that operate on that data under a single unit. The only way to access the data is provided by the functions .These functions are considered as member functions in C++. It is not possible to access the data directly.
  • 14. INHERITANCE I t is the capability to define a new class in terms of an existing class. An existing class is known as a base class and the new class is known as derived class. Inheritance can be of following types: A B A B C A B C D SINGLE INHERITANCE MULTIPLE INHERITANCE HIEARCHICAL INHERITANCE
  • 15. A B C A B C D MULTILEVEL INHERITANCE HYBRID INHERITANCE
  • 16. SINGLE INHERITANCE If a class is derived from a single base class, it is called as single inheritance. SYNTAX: class derived_class_name : access_specifier base_class_name { data members of the derived class ; member functions of the derived class ; }; The colon (:), indicates that the class derived_class_name is derived from the class base_class_name. The access_specifier may be public, private or protected. If no access_specifier is specified, it is private by default. The access_specifier indicates whether the members of the base class are privately derived or publicly derived.
  • 17. MULTIPLE INHERITANCE If a class is derived from more than one base class, it is known as multiple inheritance SYNTAX class derived-class-name : access_specifier Baseclass1, access_specifier Baseclass2, ……… …… .. access_specifier Baseclass_n { members of the derived class ; };
  • 18. Hierarchical Inheritance When two or more classes are derived from a single base class, then Inheritance is called the hierarchical inheritance. Syntax class derived_class_name1:visibility base_class_name { . . }; class derived_class_name2:visibility base_class_name { . . };
  • 19. MULTILEVEL INHERITANCE In multilevel inheritance the derived class can also be derived by an another class, which in turn can further be inherited by another and so on. Syntax class derived_class_name1:visibility base_class_name { . . }; class derived_class_name2:visibility derived_class_name1 { . . };
  • 20. PROGRAM USING SINGLE INHERITACE IN C++ #include<iostream.h> #include<conio.h> class A { public: void add() { int a=5,b=4,s; s=a+b; } }; class B: public A { public: void show() { cout<<”sum is:”<<s; } //class B publically inherit class A//
  • 21. }; void main() { B obj; obj.add(); obj.show(); getch(); } Output: sum is:9
  • 22. MERITS OF INHERITANCE Increase reuse and software quality programmers reuse the base class instead of writing new class using well tested base class helps reduce bugs in applications that use them Reduce object code size Enhance extensibility and comprehensibility helps support more flexible and extensible architectures often useful for modeling and classifying hierarchically- related domains
  • 23. DEMERITS OF INHERITANCE May create deep hierarchies that are difficult to understand. May decrease performance slightly. Subclass become dependent on parent class implementation. Complexity for very small programs.
  • 24. INHERITANCE IN C# C# supports two types of Inheritance mechanisms 1) Implementation Inheritance When a class (type) is derived from another class(type) such that it inherits all the members of the base type it is Implementation Inheritance 2) Interface Inheritance When a type (class or a struct) inherits only the signatures of the functions from another type it is Interface Inheritance.
  • 25. PROGRAM USING SINGLE INHERITANCE IN C# using System; class A { public int x = 10; public int y = 20; } class B : A { public int z = 30; public void Sum() { int sum = x+y+z; Console.WriteLine(“sum is:{0}”,sum); } }
  • 26. class add { public static void Main() { Derived d1 = new Derived(); d1.Sum(); } } Output: sum is: 60
  • 27. MERITS OF INHERITANCE IN C# Through inheritance you can very easily convert small system into large systems You can have lots of classes with the same root but have different implementations of classes. Code reusability through inheritance increased. Code are easy to manage and divided into parent and child classes.
  • 28. DEMERITS OF INHERITANCE IN C# We can't change the implementation inherited from super classes at runtime (obviously because inheritance is defined at compile time). Inheritance exposes a subclass to details of its parent's class implementation, that's whey it's often said that inheritance breaks encapsulation (in a sense that you really need to focus on interfaces only not implementation, so reusing by sub classing is not always preferred). The tight coupling provided by inheritance makes the implementation of a subclass very bound up with the implementation of a super class that any change in the parent implementation will force the sub class to change. Excessive reusing by sub-classing can make the inheritance stack very deep and very confusing too.
  • 29. POLYMORPHISM Polymorphism is a key to the power of OOP. It is the concept that supports the capability of data to be processed in more than one form. For example, an operation may exhibit different behaviour in different instances. The behaviour depends upon the types of data used in the operation. Let us consider the operation of addition.For two numbers, the operation will generate a sum. If the operands are strings then the operation would produce a third string by concatenation. Polymorphism is of two types: Compile time Run time
  • 30. COMPILE TIME POLYMORPHISM Compile time polymorphism is method and operators overloading. It is also called early binding. Method with same name but with different arguments is called method overloading. In method overloading, method performs the different task at the different input parameters. EXAMPLE OF METHOD OVERLOADING class A1 { void hello() { Console.WriteLine(“WELCOME”); } void hello(string s) { Console.WriteLine(“WELCOME {0}”,s); } }
  • 31. RUN TIME POLYMORPHISM Runtime time polymorphism is done using inheritance and virtual functions. Method overriding is called runtime polymorphism. It is also called late binding. Method overriding occurs when child class declares a method that has the same type arguments as a method declared by one of its superclass. When overriding a method, you change the behavior of the method for the derived class. Overloading a method simply involves having another method with the same prototype.Method overloading has nothing to do with inheritance or virtual methods.
  • 32. EXAMPLE OF METHOD OVERRIDING Class parent { virtual void hello() { Console.WriteLine(“Hello from Parent”); } } class child:parent { override void hello() { Console.WriteLine(“Hello from Child”); } } static void main() { parent objParent = new child(); objParent.hello(); } Output Hello from Child.
  • 33. DIFFRENCE BETWEEN INHERITANCE AND POLYMORPHISM Inheritance is the object oriented feature by which the functionality and features of one class are made available to another class without having to copy paste the code. Polymorphism is the object oriented feature by which multiple methods of a class can coexist with minor differences. Ex: method overloading.
  • 34. SIMILARITIES BETWEEN C++ & C# Both supports pointers. Capable of defining pre-processor. Both supports structure. Both supports goto statement.
  • 35. POINTER IN C++ A pointer is a variable that is used to store a memory address. The address is the location of the variable in the memory. Pointers help in allocating memory dynamically. The general form of declaring pointer is:- type *variable_name; type is the base type of the pointer and variable_name is the name of the variable of the pointer. Pointer Operators There are two important pointer operators such as ‘*’ and '&' .The ‘&’ is a unary operator. The unary operator returns the address of the memory where a variable is located. The ‘*’ operator is called the indirection operator. It returns the contents of the memory location pointed to. The indirection operator is also called deference operator.
  • 36. PROGRAM USING POINTER #include<iostream.h> #include<conio.h> void main( ) { int *x; int c=100; x=&c; cout << &quot; The address of the memory location of x : &quot; << x <<endl; cout << &quot; The contents of the pointer x : &quot; << *x << endl; getch( ); } Output: The address of the memory location of x: 01212FF78 The contents of the pointer x: 100
  • 37. POINTER IN C# Pointers are special kind of variables which hold addresses other variables.To create a pointer we use the following declaration: type* variable_name; As a type may be used each type that is not a reference-type and does not contain reference-type field. It can be only: sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, bool any enum-type. Pointer are only be used in unsafe context.
  • 38. PROGRAM USING POINTER using System; class A { public unsafe static void main() { int i=10; int *p; p=&x; console.WriteLine(“address is”+ p); console.WriteLine(“value is”+ *p); } } Output Address is 0012HM95 value is 10';
  • 39. PREPROCESSOR IN C ++ The pre-processor is a utility program, which processes special instructions that can be or are written in a C++ program. These instructions can be include a library or some special instructions to the compiler about some certain terms used in the program. Pre-processor directives start with ‘#’ character.Pre-processor directives starts with # character. C++ supports the following preprocessor directives: #include #define #if #elif #else #endif #ifndef #ifdef #undef
  • 40. PREPROCESSOR IN C# A preprocessor directive must be the only instruction on a line. Preprocessing directives are lines in your program that start with '#'. Whitespace is allowed before and after the '#'. The '#' is followed by an identifier that is the directive name. For example, '#define' is the directive . The C# language's preprocessor directives are as follows: #if #else #elif #endif #define #undef #error #line
  • 41. STRUCTURE Structure is a collection of variables under a single name. Variables can be of any type: int, float, char etc. Declaring a Structure: The structure is declared by using the keyword struct followed by structure name, also called a tag. Then the structure members (variables) are defined with their type and variable names inside the open and close braces { and } . Finally, the closed braces end with a semicolon denoted as ; following the statement. Struct student { char name[20]; int marks; int total; }; Keyword Structure name Structure member
  • 42. Goto statement The goto statement translates the program control directly to a labeled statement. It takes following form: goto identifier; goto case const-exp.; goto default;
  • 43. DIFFERENCES BETWEEN C++ AND C# Most of the C# features are similar to those of C++. However, C# provides various additional features that make it a more type –safe and web enabled language. Various points of different between C# and C++ are : C# does not use semicolon at the end of class definition. C# does not contain any default constructor. Objects in C# can only be created using new keywords. C# does not support multiple inheritance C# does not support the header file,# include. Continue..
  • 44. Continue... C++ supports operator overloading but C# does not. C++ is not completely object oriented based but C# is completely object oriented. C# have garbage collection capability but it is absent in C++ . C++ is statically typed whereas C# is dynamic in nature. C# is high level programming language while C++ is a middle level programming language.
  • 45. ADVANTAGES OF C++ Better performance Portability Multiple inheritance Support for global variables, function and constants
  • 46. DISADVANTAGE OF C++ Complex in very large high level program. C++ can't support garbage collection. C++ is not secure because it have pointer, friend function and global variable. When C++ used for web applications complex and difficult to debug .
  • 47. ADVANTAGES OF C# Garbage collection Huge .NET framework library Supports constructor chaining No need for header files and #include Access to class members/ function is done only by the dot(. )
  • 48. DISADVANTAGE OF C# C# is less flexible than C++. C# depends greatly on .NET framework, anything that is not found in the .NET framework will be difficult to implement. All though portability is what with C# was developed, C# programs are largely for Microsoft Windows Environment which although happens to be the most widely used Operating system over the globe, but with Open Source technologies, especially platforms like Linux catching up, C# still has to long way to go. This is one major shortcoming of C# . Although C# programs can be written as little as a text editor and compiled using command line, it still needs the .NET framework to be present on the system, which cripples down the portability in the development of C# programs by a large amount, and makes it more Microsoft Windows dependent.
  • 49. CONCLUSION While there are a number of differences between C++ and C#, the syntax of C# is not very different from C++ and the transition to the new language is more easy with .NET framework. Also .NET's cross language interoperability can give us the ability to use C++ and C# together Finally, if we want to use a strong programming language like C++ with the simplicity of VB than we can use C# powered with CLR.