You are on page 1of 28

19CUG38 – OOPS WITH C++

Beginning with C++ :


What is C++?
Applications of C++
Prepared & Presented By
Mrs.B.Meena Preethi
Assistant Professor
Department of Software Systems
Sri Krishna Arts and Science College

ODD 2020-21
Topics to be Covered
Beginning with C++
What is C++?
Characteristics of C++
Difference between C & C ++
Applications of C++
Sample C++ program
Comments in C++
Input and Output Operator in C++
Session Outcome

To understand how to begin programming with


C++.
Introduction to C++

• Object Oriented Programming as an approach that


provides a way for modularizing programs by creating
Partitioned memory are for both data and functions
that can be used as templates for creating multiple
copies of such modules on demand.
What is C++?
• C++ is a compiled, general-purpose, case-
sensitive, free-form programming language
that supports procedural, object-oriented, and
generic programming.

• C++ is regarded as a middle-level language, as


it comprises a combination of both high-level
and low-level language features.
Saving and execution of Program
• "C with Classes"
• It runs under gcc compiler or Turbo C Compiler.
• It is named with the extension (.cpp)
Eg: Sum.cpp

• To Compile the Program Alt+F9


• To Run the Program Ctrl+F9
• C Language Features + OOPs Concepts = C++
The Basics of a C++ Program
• C++ is an Object Oriented Programming Language.
• C++ is called as “C with Classes”.
• It was designed and developed by Bjarne
Stroustrup in early 1980s at At & T Bell Laboratories
USA New Jersey.
• The idea of C++ came from the increment
Operator ++. Named as Extension of C called
C++ in the year 1983.
7
Characteristics of C++ Program
• C++ is a Superset of C.
 Support for object-oriented programming.
• A C++ program is a collection of one or more
subprograms (functions).
• Function :
– Collection of statements
– Statements accomplish a task
• Every C++ program has a function called main()
8
Characteristics of C++
Difference between C& C++
Applications of C++
C Language is mainly used for

•Design Operating system


•Design Language Compiler
•Design Database
•Utilities Eg : Calculator
•Application Software
Sample Program “Hello World” in C++
Use the standard namespace Include standard
iostream classes
using namespace std;
A C++ comment #include <iostream>
// My first C++ program!
int main(void)
{
cout << "hello world!" << endl;
cout is an return 0;
instance of }
ostream operator overloading
(two different argument types!)
12
Example Program
#include <iostream.h>
int main()
{
cout<<"Welcome to C++ Programming"<<endl;
return 0;
}

Welcome to C++ Programming


13 Program Output
Comment lines in C++

• Comments are explanatory notes; they are


ignored by the compiler.
• There are two ways to include comments in a
program:
- Single Comment Line \\
- Multiline Comment Line \* *\
A Comment Line my start anywhere in the
program and terminates at the end of the line.
14
Comments in C++

 Single Line Comment Line


// A double slash marks the start of a
//single line comment.

 Multi line Comment Line

/* A slash followed by an asterisk marks


the start of a multiple line comment. It
ends with an asterisk followed by a
slash. */
15
Input Output Operators in C++
Standard iostream objects:
cout- Object providing a connection to
the monitor
cin - Object providing a connection to the
keyboard
Input Output Operators in C++
Cout :
• cout<<”C++ is better than C”;
• This causes the string in quotation marks to be
displayed on the screen.
• This statement introduces two new C++ features,
cout and <<.
• cout: Is a predefined object that represents the
• standard output stream in C++.
• Here the standard output stream represents the
screen.
Output Operator (<<)
• To send output to the screen we use the insertion
operator on the object cout.
• Format: cout << Expression;
• The compiler figures out the type of the object and prints
it out appropriately
cout << 5; // Outputs 5
cout << 4.1; // Outputs 4.1
cout << “String”; // Outputs String
cout << „\n‟; // Outputs a newline
It is called as Put to or Insertion Operator (<<)
The Extraction Operator (>>)
• To get input from the keyboard we use the extraction
operator and the object cin.

• Format: cin >> Variable;


• The compiler figures out the type of the variable and
reads in the appropriate type
int X;
float Y;
cin >> X; // Reads in an integer
cin >> Y; // Reads in a float
The Extraction Operator (>>)
IO STREAM FILE

• #include<iostream.h>
• It is a directive which is used to add the contents of
iostream into the program.
• It allows << Insertion (Cout) and >> Extraction
Operator (Cin) to be used in the program.

22
Example Program

Object-based programming is the style of


programming that primarily supports encapsulation
and object identity.
Major feature that are required for object based
programming are:
• Data encapsulation
• Data hiding and access mechanisms
• Automatic initialization and clear-up of objects
• Operator overloading
Summary

How to begin with C++?


Characteristics
 Difference between C & C++
 Comment lines
 Input Output Operators
MCQ
1. ______is an Object Oriented Programming Language.
a) C
b) C++
c) Java
d) Ada

2. C++ is called as “C with _______”.


a) Objects
b) Functions
c) Classes
d) None of these
MCQ
3. It was designed and developed by ___________in early 1980s at At
& T Bell Laboratories USA New Jersey.
a) Bourn Stroustrup
b) Bjarne Stroustrup
c) Jarne Stroustrup
d) Denis Stroustrup

4. The idea of C++ came from the_________. Named as Extension


of C called C++ in the year ______
a) Increment Operator & 1983.
b) Decrement Operator & 1982.
c) Unary Operator & 1981.
MCQ
5. To get input from the keyboard we use the ______operator and the
object ____
a) Insertion , Cout
b) Extraction, Cin

6. To send output to the screen we use the _________ operator on the object
____
a) Insertion , Cout
b) Extraction, Cin
INTERACTION & QUERIES????????

You might also like