SlideShare una empresa de Scribd logo
1 de 14
Testing Lecture C to C++
You can use / / to type a remark : #include <iostream.h> 	// This library is often used void main () 			// The program's main routine. { 	double a; 			// Declaration of variable a. 	a = 456; 	a = a + a * 21.5 / 100; 	// A calculation. cout << a; 			// Display the content of a. }
Input from keyboard and output to screen can be performed through cout << and cin >> : #include <iostream.h> void main() { int a; 			// a is an integer variable 	char s [100]; 			// s points to a sring of 99 characters cout << "This is a sample program." << endl; cout << endl; 			// Line feed (end of line) cout << "Type your age : "; cin >> a; cout << "Type your name : "; cin >> s; cout << endl; cout << "Hello " << s << " you're " << a << " old." << endl; cout << endl << endl << "Bye !" << endl; }
Variables can be declared everywhere: #include <iostream.h> void main () { double a; cout << "Hello, this is a test program." << endl; cout << "Type parameter a : "; cin >> a; a = (a + 1) / 2; double c; c = a * 5 + 1; cout << "c contains : " << c << endl; inti, j; i = 0; j = i + 1; cout << "j contains : " << j << endl; }
A variable can be initialised by a calculation : #include <iostream.h> void main () { double a = 12 * 3.25; double b = a + 1.112; cout << "a contains : " << a << endl; cout << "b contains : " << b << endl; a = a * 2 + b; double c = a + b * a; cout << "c contains : " << c << endl; }
Like in C, variables can be encapsulated between hooks : #include <iostream.h> void main() { 	double a; cout << "Type a number : "; cin >> a; 	{ int a = 1; 		a = a * 10 + 4; cout << "Local number : " << a << endl; 	} cout << "You typed : " << a << endl; }
C++ allows to declare a variable inside the for loop declaration. It's like if the variable hadbeen declared just before the loop : #include <iostream.h> void main () { for (int i = 0; i < 4; i++) { cout << i << endl; } cout << "i contains : " << i << endl; for (i = 0; i < 4; i++) { for (inti = 0; i < 4; i++) 	// we're between {					 // previous for's hooks cout << i; } cout << endl; } }
A global variable can be accessed even if another variable with the same name has beendeclared inside the function : #include <iostream.h> double a = 128; void main () { double a = 256; cout << "Local a : " << a << endl; cout << "Global a : " << ::a << endl; }
It is possible to make one variable be another : #include <iostream.h> void main () { double a = 3.1415927; double &b = a; // b IS a b = 89; cout << "a contains : " << a << endl; 	// Displays 89. }
(If you are used at pointers and absolutely want to know what happens, simply think double &b = a is translated to double *b = &a and all subsequent b are replaced by *b.) The value of REFERENCE b cannot be changed afther its declaration. For example you cannot write, a few lines further, &b = c expecting now b IS c. It won't work. Everything is said on the declaration line of b. Reference b and variable a are married on that line and nothing will separate them.
References can be used to allow a function to modify a calling variable : #include <iostream.h> void change (double &r, double s) { 	r = 100; 	s = 200; } void main () { 	double k, m; 	k = 3; 	m = 4; 	change (k, m); cout << k << ", " << m << endl; // Displays 100, 4. }
If you are used at pointers in C and wonder how exactly the program above works, here is howthe C++ compiler translates it (those who are not used at pointers, please skip this ugly piece ofcode) : #include <iostream.h> void change (double *r, double s) { *r = 100; s = 200; } void main () { double k, m; k = 3; m = 4; change (&k, m); cout << k << ", " << m << endl; // Displays 100, 4. } A
Testing lecture after lec 4
Testing lecture after lec 4

Más contenido relacionado

La actualidad más candente

Function recap
Function recapFunction recap
Function recapalish sha
 
Mathematics Function in C ,ppt
Mathematics Function in C ,pptMathematics Function in C ,ppt
Mathematics Function in C ,pptAllNewTeach
 
Expressions using operator in c
Expressions using operator in cExpressions using operator in c
Expressions using operator in cSaranya saran
 
c++ exp 1 Suraj...pdf
c++ exp 1 Suraj...pdfc++ exp 1 Suraj...pdf
c++ exp 1 Suraj...pdfayush616992
 
Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04hassaanciit
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branchingSaranya saran
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7Rumman Ansari
 
Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)Ahmed Khateeb
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]Abhishek Sinha
 
C programming pointer
C  programming pointerC  programming pointer
C programming pointerargusacademy
 
please sir i want to comments of every code what i do in eachline . in this w...
please sir i want to comments of every code what i do in eachline . in this w...please sir i want to comments of every code what i do in eachline . in this w...
please sir i want to comments of every code what i do in eachline . in this w...hwbloom27
 
Lab 10 sem ii_12_13
Lab 10 sem ii_12_13Lab 10 sem ii_12_13
Lab 10 sem ii_12_13alish sha
 
CBSE Class XI Programming in C++
CBSE Class XI Programming in C++CBSE Class XI Programming in C++
CBSE Class XI Programming in C++Pranav Ghildiyal
 

La actualidad más candente (19)

Function recap
Function recapFunction recap
Function recap
 
comp1
comp1comp1
comp1
 
Mathematics Function in C ,ppt
Mathematics Function in C ,pptMathematics Function in C ,ppt
Mathematics Function in C ,ppt
 
First c program
First c programFirst c program
First c program
 
Expressions using operator in c
Expressions using operator in cExpressions using operator in c
Expressions using operator in c
 
c++ exp 1 Suraj...pdf
c++ exp 1 Suraj...pdfc++ exp 1 Suraj...pdf
c++ exp 1 Suraj...pdf
 
Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7
 
Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)
 
Labsheet_3
Labsheet_3Labsheet_3
Labsheet_3
 
Practical no 3
Practical no 3Practical no 3
Practical no 3
 
Practical no 1
Practical no 1Practical no 1
Practical no 1
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
C programming pointer
C  programming pointerC  programming pointer
C programming pointer
 
please sir i want to comments of every code what i do in eachline . in this w...
please sir i want to comments of every code what i do in eachline . in this w...please sir i want to comments of every code what i do in eachline . in this w...
please sir i want to comments of every code what i do in eachline . in this w...
 
Lab 10 sem ii_12_13
Lab 10 sem ii_12_13Lab 10 sem ii_12_13
Lab 10 sem ii_12_13
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
CBSE Class XI Programming in C++
CBSE Class XI Programming in C++CBSE Class XI Programming in C++
CBSE Class XI Programming in C++
 

Destacado

Lecture 09 dblc centralized vs decentralized design
Lecture 09   dblc centralized vs decentralized designLecture 09   dblc centralized vs decentralized design
Lecture 09 dblc centralized vs decentralized designemailharmeet
 
Lecture 02 terminology of database
Lecture 02 terminology of  databaseLecture 02 terminology of  database
Lecture 02 terminology of databaseemailharmeet
 
Lecture 08 distributed dbms
Lecture 08 distributed dbmsLecture 08 distributed dbms
Lecture 08 distributed dbmsemailharmeet
 
Lecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculusLecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculusemailharmeet
 
Lecture 03 data abstraction and er model
Lecture 03 data abstraction and er modelLecture 03 data abstraction and er model
Lecture 03 data abstraction and er modelemailharmeet
 
Lecture 09 dblc centralized vs decentralized design
Lecture 09   dblc centralized vs decentralized designLecture 09   dblc centralized vs decentralized design
Lecture 09 dblc centralized vs decentralized designemailharmeet
 
Lecture 04 normalization
Lecture 04 normalization Lecture 04 normalization
Lecture 04 normalization emailharmeet
 
Lecture 10 distributed database management system
Lecture 10   distributed database management systemLecture 10   distributed database management system
Lecture 10 distributed database management systememailharmeet
 
Lecture 01 introduction to database
Lecture 01 introduction to databaseLecture 01 introduction to database
Lecture 01 introduction to databaseemailharmeet
 
Design computer system group a
Design computer system group aDesign computer system group a
Design computer system group aRaheem Mohamed
 
MOBILE NUMBER PORTABILITY
MOBILE NUMBER PORTABILITYMOBILE NUMBER PORTABILITY
MOBILE NUMBER PORTABILITYShivam Yadav
 
Crossectoraal samenwerken het kan
Crossectoraal samenwerken het kanCrossectoraal samenwerken het kan
Crossectoraal samenwerken het kanPiet Verhoeve
 
Ingles bob marley
Ingles bob marleyIngles bob marley
Ingles bob marleycamilo
 
Resumen
ResumenResumen
Resumentony
 
Arta & nlp 3
Arta & nlp 3Arta & nlp 3
Arta & nlp 3adrianuta
 

Destacado (20)

Lecture 09 dblc centralized vs decentralized design
Lecture 09   dblc centralized vs decentralized designLecture 09   dblc centralized vs decentralized design
Lecture 09 dblc centralized vs decentralized design
 
Lecture 02 terminology of database
Lecture 02 terminology of  databaseLecture 02 terminology of  database
Lecture 02 terminology of database
 
Lecture 05 dblc
Lecture 05 dblcLecture 05 dblc
Lecture 05 dblc
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Lecture 08 distributed dbms
Lecture 08 distributed dbmsLecture 08 distributed dbms
Lecture 08 distributed dbms
 
Lecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculusLecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculus
 
Lecture 03 data abstraction and er model
Lecture 03 data abstraction and er modelLecture 03 data abstraction and er model
Lecture 03 data abstraction and er model
 
Lecture 09 dblc centralized vs decentralized design
Lecture 09   dblc centralized vs decentralized designLecture 09   dblc centralized vs decentralized design
Lecture 09 dblc centralized vs decentralized design
 
Lecture 04 normalization
Lecture 04 normalization Lecture 04 normalization
Lecture 04 normalization
 
Lecture 10 distributed database management system
Lecture 10   distributed database management systemLecture 10   distributed database management system
Lecture 10 distributed database management system
 
Lecture 01 introduction to database
Lecture 01 introduction to databaseLecture 01 introduction to database
Lecture 01 introduction to database
 
Design computer system group a
Design computer system group aDesign computer system group a
Design computer system group a
 
MOBILE NUMBER PORTABILITY
MOBILE NUMBER PORTABILITYMOBILE NUMBER PORTABILITY
MOBILE NUMBER PORTABILITY
 
Original assignment
Original assignmentOriginal assignment
Original assignment
 
Crossectoraal samenwerken het kan
Crossectoraal samenwerken het kanCrossectoraal samenwerken het kan
Crossectoraal samenwerken het kan
 
Ingles bob marley
Ingles bob marleyIngles bob marley
Ingles bob marley
 
Reading and writing
Reading and writingReading and writing
Reading and writing
 
Ruby Faye
Ruby FayeRuby Faye
Ruby Faye
 
Resumen
ResumenResumen
Resumen
 
Arta & nlp 3
Arta & nlp 3Arta & nlp 3
Arta & nlp 3
 

Similar a Testing lecture after lec 4

C++ Advanced
C++ AdvancedC++ Advanced
C++ AdvancedVivek Das
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to cHattori Sidek
 
Php Crash Course
Php Crash CoursePhp Crash Course
Php Crash Coursemussawir20
 
C chap02
C chap02C chap02
C chap02Kamran
 
Cplusplus
CplusplusCplusplus
Cplusplusdancey
 
Introduction to programming c and data-structures
Introduction to programming c and data-structures Introduction to programming c and data-structures
Introduction to programming c and data-structures Pradipta Mishra
 
Introduction to programming c and data structures
Introduction to programming c and data structuresIntroduction to programming c and data structures
Introduction to programming c and data structuresPradipta Mishra
 
Falcon初印象
Falcon初印象Falcon初印象
Falcon初印象勇浩 赖
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C ProgrammingMOHAMAD NOH AHMAD
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 FocJAYA
 
C programming(Part 1)
C programming(Part 1)C programming(Part 1)
C programming(Part 1)SURBHI SAROHA
 
Practical Meta Programming
Practical Meta ProgrammingPractical Meta Programming
Practical Meta ProgrammingReggie Meisler
 

Similar a Testing lecture after lec 4 (20)

C++ Advanced
C++ AdvancedC++ Advanced
C++ Advanced
 
C++ programming
C++ programmingC++ programming
C++ programming
 
C Programming
C ProgrammingC Programming
C Programming
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
 
Php Crash Course
Php Crash CoursePhp Crash Course
Php Crash Course
 
C Programming
C ProgrammingC Programming
C Programming
 
C chap02
C chap02C chap02
C chap02
 
C chap02
C chap02C chap02
C chap02
 
Cplusplus
CplusplusCplusplus
Cplusplus
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
 
Introduction to programming c and data-structures
Introduction to programming c and data-structures Introduction to programming c and data-structures
Introduction to programming c and data-structures
 
Introduction to programming c and data structures
Introduction to programming c and data structuresIntroduction to programming c and data structures
Introduction to programming c and data structures
 
Savitch ch 08
Savitch ch 08Savitch ch 08
Savitch ch 08
 
Falcon初印象
Falcon初印象Falcon初印象
Falcon初印象
 
Chapter2
Chapter2Chapter2
Chapter2
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
 
Lab # 2
Lab # 2Lab # 2
Lab # 2
 
C programming(Part 1)
C programming(Part 1)C programming(Part 1)
C programming(Part 1)
 
Practical Meta Programming
Practical Meta ProgrammingPractical Meta Programming
Practical Meta Programming
 

Más de emailharmeet

Lecture 07 relational database management system
Lecture 07 relational database management systemLecture 07 relational database management system
Lecture 07 relational database management systememailharmeet
 
Lecture 00 introduction to course
Lecture 00 introduction to courseLecture 00 introduction to course
Lecture 00 introduction to courseemailharmeet
 
Syllabus mca 2 rdbms i
Syllabus mca 2 rdbms iSyllabus mca 2 rdbms i
Syllabus mca 2 rdbms iemailharmeet
 

Más de emailharmeet (7)

Lecture 07 relational database management system
Lecture 07 relational database management systemLecture 07 relational database management system
Lecture 07 relational database management system
 
Revision Lecture
Revision LectureRevision Lecture
Revision Lecture
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Course File c++
Course File c++Course File c++
Course File c++
 
Assignmnet 1
Assignmnet 1Assignmnet 1
Assignmnet 1
 
Lecture 00 introduction to course
Lecture 00 introduction to courseLecture 00 introduction to course
Lecture 00 introduction to course
 
Syllabus mca 2 rdbms i
Syllabus mca 2 rdbms iSyllabus mca 2 rdbms i
Syllabus mca 2 rdbms i
 

Testing lecture after lec 4

  • 2. You can use / / to type a remark : #include <iostream.h> // This library is often used void main () // The program's main routine. { double a; // Declaration of variable a. a = 456; a = a + a * 21.5 / 100; // A calculation. cout << a; // Display the content of a. }
  • 3. Input from keyboard and output to screen can be performed through cout << and cin >> : #include <iostream.h> void main() { int a; // a is an integer variable char s [100]; // s points to a sring of 99 characters cout << "This is a sample program." << endl; cout << endl; // Line feed (end of line) cout << "Type your age : "; cin >> a; cout << "Type your name : "; cin >> s; cout << endl; cout << "Hello " << s << " you're " << a << " old." << endl; cout << endl << endl << "Bye !" << endl; }
  • 4. Variables can be declared everywhere: #include <iostream.h> void main () { double a; cout << "Hello, this is a test program." << endl; cout << "Type parameter a : "; cin >> a; a = (a + 1) / 2; double c; c = a * 5 + 1; cout << "c contains : " << c << endl; inti, j; i = 0; j = i + 1; cout << "j contains : " << j << endl; }
  • 5. A variable can be initialised by a calculation : #include <iostream.h> void main () { double a = 12 * 3.25; double b = a + 1.112; cout << "a contains : " << a << endl; cout << "b contains : " << b << endl; a = a * 2 + b; double c = a + b * a; cout << "c contains : " << c << endl; }
  • 6. Like in C, variables can be encapsulated between hooks : #include <iostream.h> void main() { double a; cout << "Type a number : "; cin >> a; { int a = 1; a = a * 10 + 4; cout << "Local number : " << a << endl; } cout << "You typed : " << a << endl; }
  • 7. C++ allows to declare a variable inside the for loop declaration. It's like if the variable hadbeen declared just before the loop : #include <iostream.h> void main () { for (int i = 0; i < 4; i++) { cout << i << endl; } cout << "i contains : " << i << endl; for (i = 0; i < 4; i++) { for (inti = 0; i < 4; i++) // we're between { // previous for's hooks cout << i; } cout << endl; } }
  • 8. A global variable can be accessed even if another variable with the same name has beendeclared inside the function : #include <iostream.h> double a = 128; void main () { double a = 256; cout << "Local a : " << a << endl; cout << "Global a : " << ::a << endl; }
  • 9. It is possible to make one variable be another : #include <iostream.h> void main () { double a = 3.1415927; double &b = a; // b IS a b = 89; cout << "a contains : " << a << endl; // Displays 89. }
  • 10. (If you are used at pointers and absolutely want to know what happens, simply think double &b = a is translated to double *b = &a and all subsequent b are replaced by *b.) The value of REFERENCE b cannot be changed afther its declaration. For example you cannot write, a few lines further, &b = c expecting now b IS c. It won't work. Everything is said on the declaration line of b. Reference b and variable a are married on that line and nothing will separate them.
  • 11. References can be used to allow a function to modify a calling variable : #include <iostream.h> void change (double &r, double s) { r = 100; s = 200; } void main () { double k, m; k = 3; m = 4; change (k, m); cout << k << ", " << m << endl; // Displays 100, 4. }
  • 12. If you are used at pointers in C and wonder how exactly the program above works, here is howthe C++ compiler translates it (those who are not used at pointers, please skip this ugly piece ofcode) : #include <iostream.h> void change (double *r, double s) { *r = 100; s = 200; } void main () { double k, m; k = 3; m = 4; change (&k, m); cout << k << ", " << m << endl; // Displays 100, 4. } A