SlideShare a Scribd company logo
C++
Programming language: It is an artificial language
designed to communicate to a machine, particularly
a computer.
Programs: These are set of instructions written in
any programming language to serve some purpose &
are written by following the syntax of the
programming language.
C++: It was developed in 1980s at Bell Laboratory by
Bjarn Stroustrup as an Object Oriented Programming
Language.
OOP Programming: This approach views a problem in
terms of objects involved rather than procedure for
doing it.
Character set: A set of valid characters that a
language can recognize.
Letters: A to Z, a-z.
Digits: 0 to 9
Special Symbols: Space + - * / ^  ( ) { } [ ] = < > ,
‘ “ $ . ; : % ! & ? _(Underscore) # <= >= @
White Spaces: Blank Space, Horizontal Tab (à),
Carriage return(J), Newline, Form Feed
Other Characters: C++ can process any of the
256 ASCII characters as data or as literals
Tokens: The smallest unit of a program. They are
a. Keywords
b. Identifier
c. Literals(constants)
d. Operators
e. Punctuators
Keywords : they are reserved words meant for
specific purpose. They can not be used for giving
names to variables, arrays, functions etc.
For e.g, If , if else , int , float , case, switch
Identifiers: a name given to program elements such
as variables, arrays, functions etc.
Rule for giving a name to variable :
1. It must start with an alphabet or a character(_).
2. It cannot contain any other character other
than (_) but can contain numbers only after first
character.
Literals : (Often referred to as constants) are data
items that never change their values during a
program run.
Operators: Operators are tokens that trigger some
computation when applied to variables and other
object in an expression. They are
I/o : << and >>
Arithmetic : +, - , * , / , %
Increment/Decrement : ++ , - -
Relational : ==, <, >, <=, >=, !=
Logical : &&, ||, !
Conditional : ?
Punctuators : Also known as separators. They
enhance a program’s readability. For eg
[ ] , { } , ( ) , ; , : , * , = , #
C++
A graphic outline of a simplistic approach to show how programs
get developed.
Define the problem to be solvedSTEP1::
Design a solutionSTEP2::
Write a program that implements the solutionSTEP3::
Compile the programSTEP4::
Link object filesSTEP5::
Test & Debug programSTEP6::
/*Program to display area & perimeter of rectangle*/
#include<iostream.h>
void main()
{
int L,B,A,P;
L=6;
cout<<“Enter Length”<<endl;
cin>>L;
cout<<“Enter Breadth”<<endl;
cin>>B;
A=L*B;
P=2*(L+B);
cout<<“Area is ”<<A<<endl;
cout<<“Perimeter is ”<<P<<endl;
}
Preprocessor Directives
Comments
Function Declarator
Variable Declaration
Variable Initialisation
Displaying text on screen
Assigning entered value to L
Formula
Displaying result
Function Begin
Function ends
To save a file: F2
To run a program: Ctrl+F9
To view the output screen: Alt+F5
To exit from the TC++ editor: Alt+x
To exit from DOS prompt: Type exit
Next you have a summary of the basic fundamental data types in C++, as
well as the range of values that can be represented with each one:
Name Description Size Range*
char
Character or small
integer.
1
signed: -128 to 127
unsigned: 0 to 255
int Integer. 4
signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
long int
(long)
Long integer. 4
signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
float
Floating point
number.
4 +/- 3.4e +/- 38 (~7 digits)
Comments: are statements which are not compiled & are
used for programmer’s reference to describe the purpose of
statements or block of statements. It can be done by using
single line comment(//) and multi line comment(/*…..*/).
Header files: files that are included in C++ program to
incorporate the use of functions as required. for e.g.,
iostream.h : cin & cout are used to input value through
keyboard & display the message on display device.
Data Types: are the means to identify the type of data &
associated operations of handling it. They are of two types:
fundamental & derived data types.
Fundamental data types are:
char (stores single character) , int ( stores whole numbers) &
float/double (stores real numbers). declaration of
variable(syntax) :
data_type variable_name;
INPUT AND OUTPUT
cout (to be read as “SEE OUT”): Output Operator(<<) also
called insertion operator. It is used to direct a value to
standard output generally a Monitor.
cin (to be read as “SEE IN”): input operator(>>) also known as
extraction operator. It is used to read a value from standard
input generally a Keyboard.
//PROGRAM TO CALCULATE AREA OF TRIANGLE
#include<iostream.h>
#include<math.h>
void main ( )
{
float S1 ,S2 ,S3, S, area, perimeter;
cout<<“Enter sides of the triangle”<<endl;
cin>>S1>>S2>>S3;
S=(S1+S2+S3)/2.0;
area=sqrt(S*(S-S1)*(S-S2)*(S-S3));
perimeter=S1+S2+S3;
cout<<“Area=“<<Area;
cout<<“ Perimeter=“<<Perimeter;
}
Write a program to :
1. Calculate area & circumference of circle
2. Calculate Sum & Product of two numbers and display them.
3. Input a number in Meters and convert it in Centimeters
4. Calculate the square and cube of a number input by the user
// Area & Circumference of circle
#include<iostream.h>
#include<conio.h>
void main ( )
{
clrscr();
float pi=3.14 ,r , area, cir;
cout<<“Enter radius : ”<<endl;
cin>>r;
area=pi*r*r;
cir=2*pi*r;
cout<<“Area=“<<area;
cout<<“circumference=“<<cir;
getch();
}
//Sum & Product of 2 Numbers
#include<iostream.h>
#include<conio.h>
void main ( )
{
clrscr();
float a, b, sum, pr;
cout<<“Enter a and b: ”<<endl;
cin>>a>>b;
sum=a+b;
pr=a*b;
cout<<“sum=“<<sum;
cout<<“product =“<<pr;
getch();
}
// Input a number in Meters and convert it in Centimeters
#include<iostream.h>
#include<conio.h>
void main ( )
{
clrscr();
float num, cm;
cout<<“Enter a number in meters : ”<<endl;
cin>>num;
cm = num*100;
cout<<“The Entered number is”<<cm << “centimeters”;
getch();
}
To Find Errors in a C++ Program
/* A program to add two numbers
#include<iosteam.h>
void main ( );
{
clrscr();
int a, b, sum;
cout<<“Enter Value for a”<<endl;
cin>>A;
cout<<“Enter Value for b”;
cin>>b;
Sum=a+b;
cout<<“ Sum is =“<<sum
}
Errors are:
Comment not terminated / closed
Spelling of iosteam.h
‘ ; ’ not to used at the end of main
Header (conio.h) is not included
Variable is ‘a’ and not ‘A’
Variable is ‘sum’ and not ‘Sum’
End of Statement should be ‘ ; ’
PRACTICE QUESTIONS
Write a program to Convert the following:
1. Meter to Kilometer (1 Km = 1000 Meter)
2. Centigrade to Fahrenheit (F = C*(9/5)+32)
3. Feet into Meters(1 Meter = 3.28 Feet)
4. Hours into Minutes, Seconds (1 Hr = 60 Min = 3600 Sec)
ACTIVITY QUESTIONS 9A( Oct 13)
Write a program to
Get temperature in Centigrade to Fahrenheit
(F = C*9/5+32)
OR
Input three values from the user. Add & multiply them and
then display the output
Save it with your roll no and class. For Eg: 9A424
ACTIVITY QUESTIONS 9B( Oct 13)
Write a program to
Get temperature in Centigrade to Fahrenheit
(F = C*9/5+32)
OR
Input three values from the user. Add & multiply them and
then display the output
Save it with your roll no and class. For Eg: 9B255
ACTIVITY QUESTIONS 9C( Oct 13)
Write a program to
Get length in feet and then convert it into meters
(1 Meter = 3.28 Feet)
OR
Input two values from the user. Add & multiply them and
then display the output
Save it with your roll no and class. For Eg: 9A245
ACTIVITY QUESTIONS 9D( Oct 13)
Write a program to
Get length in feet and then convert it into meters
(1 Meter = 3.28 Feet)
OR
Input two values from the user. Add & multiply them and
then display the output
Save it with your roll no and class. For Eg: 9A245
ACTIVITY QUESTIONS 9E( Oct 13)
Write a program to
Get temperature in Centigrade to Fahrenheit
(F = C*9/5+32)
OR
Input three values from the user. Add & multiply them and
then display the output
Save it with your roll no and class. For Eg: 9B255

More Related Content

PDF
I PUC CS Lab_programs
PPTX
Compiler Design - Ambiguous grammar, LMD & RMD, Infix & Postfix, Implementati...
PDF
important C questions and_answers praveensomesh
PPTX
Back patching
DOCX
Ankita sharma focp
PDF
Pointers in C language
PPT
Unit 3 arrays and_string
PPT
Lesson 4 PowerPoint
I PUC CS Lab_programs
Compiler Design - Ambiguous grammar, LMD & RMD, Infix & Postfix, Implementati...
important C questions and_answers praveensomesh
Back patching
Ankita sharma focp
Pointers in C language
Unit 3 arrays and_string
Lesson 4 PowerPoint

What's hot (20)

PPT
Intermediate code generation
PPT
T03 b basicioscanf
PDF
ICP - Lecture 6
DOCX
C programming Lab 1
PPT
Intermediate code generation (Compiler Design)
DOCX
CS291(C Programming) assignment
DOCX
Ecs40 winter 2017 homework 3
PPTX
Intermediate code
PPT
Unit 5 structure and unions
PPTX
COMPILER DESIGN AND CONSTRUCTION
PDF
Xi CBSE Computer Science lab programs
PPTX
Strings and pointers
PPTX
3. user input and some basic problem
PPTX
Basic Input and Output
PDF
VIT351 Software Development VI Unit2
PPTX
Three Address code
PPT
DOCX
Compiler Design Lab File
PDF
Assignment9
PPTX
2. introduction of a c program
Intermediate code generation
T03 b basicioscanf
ICP - Lecture 6
C programming Lab 1
Intermediate code generation (Compiler Design)
CS291(C Programming) assignment
Ecs40 winter 2017 homework 3
Intermediate code
Unit 5 structure and unions
COMPILER DESIGN AND CONSTRUCTION
Xi CBSE Computer Science lab programs
Strings and pointers
3. user input and some basic problem
Basic Input and Output
VIT351 Software Development VI Unit2
Three Address code
Compiler Design Lab File
Assignment9
2. introduction of a c program
Ad

Similar to C++ (20)

PPTX
Basic Programming concepts - Programming with C++
PPTX
C++ basics
PPT
Elementary_Of_C++_Programming_Language.ppt
PPT
Pengaturcaraan asas
PPT
Apclass (2)
PPT
PPTX
#Code2 create c++ for beginners
PPTX
Presentation c++
PDF
C++ Chapter I
PPTX
Intro in understanding to C programming .pptx
PPTX
Cs1123 11 pointers
PPTX
C++ lecture 01
PPTX
Cs1123 3 c++ overview
PPT
Apclass (2)
PDF
c++ lab manual
PPTX
Chap_________________1_Introduction.pptx
PPT
02a fundamental c++ types, arithmetic
PPT
FP 201 Unit 2 - Part 2
PDF
2 BytesC++ course_2014_c1_basicsc++
Basic Programming concepts - Programming with C++
C++ basics
Elementary_Of_C++_Programming_Language.ppt
Pengaturcaraan asas
Apclass (2)
#Code2 create c++ for beginners
Presentation c++
C++ Chapter I
Intro in understanding to C programming .pptx
Cs1123 11 pointers
C++ lecture 01
Cs1123 3 c++ overview
Apclass (2)
c++ lab manual
Chap_________________1_Introduction.pptx
02a fundamental c++ types, arithmetic
FP 201 Unit 2 - Part 2
2 BytesC++ course_2014_c1_basicsc++
Ad

Recently uploaded (20)

PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
01-Introduction-to-Information-Management.pdf
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Business Ethics Teaching Materials for college
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Complications of Minimal Access Surgery at WLH
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
Pre independence Education in Inndia.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
01-Introduction-to-Information-Management.pdf
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
human mycosis Human fungal infections are called human mycosis..pptx
Final Presentation General Medicine 03-08-2024.pptx
Business Ethics Teaching Materials for college
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Complications of Minimal Access Surgery at WLH
Supply Chain Operations Speaking Notes -ICLT Program
2.FourierTransform-ShortQuestionswithAnswers.pdf
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Microbial diseases, their pathogenesis and prophylaxis
Microbial disease of the cardiovascular and lymphatic systems
TR - Agricultural Crops Production NC III.pdf
Anesthesia in Laparoscopic Surgery in India
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Week 4 Term 3 Study Techniques revisited.pptx
Pre independence Education in Inndia.pdf

C++

  • 2. Programming language: It is an artificial language designed to communicate to a machine, particularly a computer. Programs: These are set of instructions written in any programming language to serve some purpose & are written by following the syntax of the programming language. C++: It was developed in 1980s at Bell Laboratory by Bjarn Stroustrup as an Object Oriented Programming Language. OOP Programming: This approach views a problem in terms of objects involved rather than procedure for doing it.
  • 3. Character set: A set of valid characters that a language can recognize. Letters: A to Z, a-z. Digits: 0 to 9 Special Symbols: Space + - * / ^ ( ) { } [ ] = < > , ‘ “ $ . ; : % ! & ? _(Underscore) # <= >= @ White Spaces: Blank Space, Horizontal Tab (à), Carriage return(J), Newline, Form Feed Other Characters: C++ can process any of the 256 ASCII characters as data or as literals
  • 4. Tokens: The smallest unit of a program. They are a. Keywords b. Identifier c. Literals(constants) d. Operators e. Punctuators Keywords : they are reserved words meant for specific purpose. They can not be used for giving names to variables, arrays, functions etc. For e.g, If , if else , int , float , case, switch Identifiers: a name given to program elements such as variables, arrays, functions etc. Rule for giving a name to variable : 1. It must start with an alphabet or a character(_). 2. It cannot contain any other character other than (_) but can contain numbers only after first character.
  • 5. Literals : (Often referred to as constants) are data items that never change their values during a program run. Operators: Operators are tokens that trigger some computation when applied to variables and other object in an expression. They are I/o : << and >> Arithmetic : +, - , * , / , % Increment/Decrement : ++ , - - Relational : ==, <, >, <=, >=, != Logical : &&, ||, ! Conditional : ? Punctuators : Also known as separators. They enhance a program’s readability. For eg [ ] , { } , ( ) , ; , : , * , = , #
  • 7. A graphic outline of a simplistic approach to show how programs get developed. Define the problem to be solvedSTEP1:: Design a solutionSTEP2:: Write a program that implements the solutionSTEP3:: Compile the programSTEP4:: Link object filesSTEP5:: Test & Debug programSTEP6::
  • 8. /*Program to display area & perimeter of rectangle*/ #include<iostream.h> void main() { int L,B,A,P; L=6; cout<<“Enter Length”<<endl; cin>>L; cout<<“Enter Breadth”<<endl; cin>>B; A=L*B; P=2*(L+B); cout<<“Area is ”<<A<<endl; cout<<“Perimeter is ”<<P<<endl; } Preprocessor Directives Comments Function Declarator Variable Declaration Variable Initialisation Displaying text on screen Assigning entered value to L Formula Displaying result Function Begin Function ends
  • 9. To save a file: F2 To run a program: Ctrl+F9 To view the output screen: Alt+F5 To exit from the TC++ editor: Alt+x To exit from DOS prompt: Type exit
  • 10. Next you have a summary of the basic fundamental data types in C++, as well as the range of values that can be represented with each one: Name Description Size Range* char Character or small integer. 1 signed: -128 to 127 unsigned: 0 to 255 int Integer. 4 signed: -2147483648 to 2147483647 unsigned: 0 to 4294967295 long int (long) Long integer. 4 signed: -2147483648 to 2147483647 unsigned: 0 to 4294967295 float Floating point number. 4 +/- 3.4e +/- 38 (~7 digits)
  • 11. Comments: are statements which are not compiled & are used for programmer’s reference to describe the purpose of statements or block of statements. It can be done by using single line comment(//) and multi line comment(/*…..*/). Header files: files that are included in C++ program to incorporate the use of functions as required. for e.g., iostream.h : cin & cout are used to input value through keyboard & display the message on display device. Data Types: are the means to identify the type of data & associated operations of handling it. They are of two types: fundamental & derived data types. Fundamental data types are: char (stores single character) , int ( stores whole numbers) & float/double (stores real numbers). declaration of variable(syntax) : data_type variable_name;
  • 12. INPUT AND OUTPUT cout (to be read as “SEE OUT”): Output Operator(<<) also called insertion operator. It is used to direct a value to standard output generally a Monitor. cin (to be read as “SEE IN”): input operator(>>) also known as extraction operator. It is used to read a value from standard input generally a Keyboard. //PROGRAM TO CALCULATE AREA OF TRIANGLE #include<iostream.h> #include<math.h> void main ( ) { float S1 ,S2 ,S3, S, area, perimeter; cout<<“Enter sides of the triangle”<<endl; cin>>S1>>S2>>S3; S=(S1+S2+S3)/2.0; area=sqrt(S*(S-S1)*(S-S2)*(S-S3)); perimeter=S1+S2+S3; cout<<“Area=“<<Area; cout<<“ Perimeter=“<<Perimeter; }
  • 13. Write a program to : 1. Calculate area & circumference of circle 2. Calculate Sum & Product of two numbers and display them. 3. Input a number in Meters and convert it in Centimeters 4. Calculate the square and cube of a number input by the user // Area & Circumference of circle #include<iostream.h> #include<conio.h> void main ( ) { clrscr(); float pi=3.14 ,r , area, cir; cout<<“Enter radius : ”<<endl; cin>>r; area=pi*r*r; cir=2*pi*r; cout<<“Area=“<<area; cout<<“circumference=“<<cir; getch(); } //Sum & Product of 2 Numbers #include<iostream.h> #include<conio.h> void main ( ) { clrscr(); float a, b, sum, pr; cout<<“Enter a and b: ”<<endl; cin>>a>>b; sum=a+b; pr=a*b; cout<<“sum=“<<sum; cout<<“product =“<<pr; getch(); }
  • 14. // Input a number in Meters and convert it in Centimeters #include<iostream.h> #include<conio.h> void main ( ) { clrscr(); float num, cm; cout<<“Enter a number in meters : ”<<endl; cin>>num; cm = num*100; cout<<“The Entered number is”<<cm << “centimeters”; getch(); }
  • 15. To Find Errors in a C++ Program /* A program to add two numbers #include<iosteam.h> void main ( ); { clrscr(); int a, b, sum; cout<<“Enter Value for a”<<endl; cin>>A; cout<<“Enter Value for b”; cin>>b; Sum=a+b; cout<<“ Sum is =“<<sum } Errors are: Comment not terminated / closed Spelling of iosteam.h ‘ ; ’ not to used at the end of main Header (conio.h) is not included Variable is ‘a’ and not ‘A’ Variable is ‘sum’ and not ‘Sum’ End of Statement should be ‘ ; ’
  • 16. PRACTICE QUESTIONS Write a program to Convert the following: 1. Meter to Kilometer (1 Km = 1000 Meter) 2. Centigrade to Fahrenheit (F = C*(9/5)+32) 3. Feet into Meters(1 Meter = 3.28 Feet) 4. Hours into Minutes, Seconds (1 Hr = 60 Min = 3600 Sec)
  • 17. ACTIVITY QUESTIONS 9A( Oct 13) Write a program to Get temperature in Centigrade to Fahrenheit (F = C*9/5+32) OR Input three values from the user. Add & multiply them and then display the output Save it with your roll no and class. For Eg: 9A424
  • 18. ACTIVITY QUESTIONS 9B( Oct 13) Write a program to Get temperature in Centigrade to Fahrenheit (F = C*9/5+32) OR Input three values from the user. Add & multiply them and then display the output Save it with your roll no and class. For Eg: 9B255
  • 19. ACTIVITY QUESTIONS 9C( Oct 13) Write a program to Get length in feet and then convert it into meters (1 Meter = 3.28 Feet) OR Input two values from the user. Add & multiply them and then display the output Save it with your roll no and class. For Eg: 9A245
  • 20. ACTIVITY QUESTIONS 9D( Oct 13) Write a program to Get length in feet and then convert it into meters (1 Meter = 3.28 Feet) OR Input two values from the user. Add & multiply them and then display the output Save it with your roll no and class. For Eg: 9A245
  • 21. ACTIVITY QUESTIONS 9E( Oct 13) Write a program to Get temperature in Centigrade to Fahrenheit (F = C*9/5+32) OR Input three values from the user. Add & multiply them and then display the output Save it with your roll no and class. For Eg: 9B255