Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
2K views
203 pages
Oops Book
Uploaded by
pushpak84shinde
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save Oops book For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
2K views
203 pages
Oops Book
Uploaded by
pushpak84shinde
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save Oops book For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save Oops book For Later
You are on page 1
/ 203
Search
Fullscreen
Object Oriented Programming Using C++ SECOND YEAR DIPLOMA (Code : 22316) Reese SRS SN NOMA CCAM RSD SIL0LD) Semester III - Computer Engineering Group / Information Technology Engineering Group(CO/CM/IF/CW) [ smety as per new revised ‘T’ Scheme w.e.f. academic year 2018-2019 Harish G. Narula Formerly, Assistant Professor (Senior), Department of Computer Engineering D. J. Sanghvi College of Engineering, Mumbai Maharashtra, India. NDOLEA Pre t185/- | Price® Price €188/- | SIT ae TechKnowledge Sd Lane (Book Code : MDO133A (New Code : RMDOI4A))u Object Orianted Programming using C++ (MSBTE) Table of Conten Syllabus Tople : Structure of C++ Program , Cow] See cree aed ToT TTT | 10 Structuro of C++ procrar® Chapter 1: Structured Programming with C++ qwaess6,697,W47 14110 1-29 | 1.10.1 Simple C++ Program Syllabus : Principles of Object Oriented Programming 4.102 Dynamic Inialization of Variables. ; ¢ Syllabus Tople : User dofned Data Types Unit Outcomes : Write simplo C++ program for soling the given expression using POP approach. 4.10.3 User Defined Datatype Teplos and Sub-Toples : Procedure Otnted Programming | | 1408: Enumerated Daa 99 = (POP) Verses Objoct Oriented Programming (OOP), Basic | | 1-11 letegrated Development Environment ‘Concepts of Object Oriented Programming and Object Oriented | | ¥ Syllabus Topic: Operators Languages, Applications of OOP, C verses C++, Structure of | | 1.12 Operators (W-17). Cera, Spl C+ poy, Tokers, KeywortVatates,| | 121 Unry Operas (95 S16, 17, WT) Constants, Basic data types, User defined data types, Type | | 1122 Binary Operators. casting, Operators, Expressions, ent Operator || 4423 Tomary Operator 1A Computer.. on 4.124 Assignment Operators 1.2 Programming and Programming Languages Wiae case es eee ve 13 Binary Number System... ‘ Sytabue Tope: Memory Management Operator. ont 19 14 Hoy 1 6/6n Proganmra Lanes —————-*6 | 4426 ony Manage peas 1.5 Procedure Oriented Programming (wes, 16, 517), (W-14, WA5,W-16, 5-17)... 1.10 Preedence and Associaiyof Operator. ¥ Syllabus Topic : Basic’ Cconcpt of Objet Oren 7 Sylabus Tople : Expressions. Programming and Object Oriented Languages... aliconeces 1.8 Basics of Object Orionted Programming (OOP) 4.18 Formatted and Unformatted 10 Functions 22 ‘and OOP Languages ($-14, We14.W-16) mom 18 | 4's 4 poymatted 10 Functions ¥ —_Syabus Topio : Proveckwe Oteried 1.18.2. Unformatted 10 Functions. Programming (POP) Verses Object Oriented 16 C++ 10 Techniques (W-15, S-16, S-17) Programming (OOF), C verses: ore wow TD 147 Manipulators 1.6.1 Procedure Oriented Versus Object Oriented 1.18 Basic Program Examples (W-15, S-17) Programming Language or ‘C’ Language ' . tie mee pormeny versie ¥ Syllabus Topic : Type Casting 4-7 | 1.181 Type Casting... 1-7 | 1.19. Exam Pack (Univesty and Reviow Questions). (6-14, We14, 8-15, $6, 5:17, WHT) nn ¥ Syllabus Tople : Applications of OOP. 1.82 Applications of Object Oriented Programming Chapter 2 : Control Statements 2-4 to 2-26 Language ($-14, $15, 8-16, WA8) _.g | Shaper 2: Control Statements ___2-1 0.2.26, 1.7 Features of C Programming Language 1.8 C++as.a Superset of C Programming Language ¥ Syllabus Topic : Tokens... 19 Tokens of C/C++... 1.9.1 Character Set of C/ C++. 1-7 | | Sytabus : Principles of object Oriented Programming Unit Outcomes : Write POP based C++ program using decision making andloop structure forthe givensiuation. Topics end Sub-Topics : Control Stucturés: Decision making Statements and Loops 7 Syllabus Topie : Control Sructures : Decision ‘making Statements and Loops... 2.1 contol Stuturs : Dacian raking Statements ¢sylabun opie: Base Ola Types 194 Data Typos. Syllabus Topic : Constants and Variables... 195 Constants and Variables. 1.96 Escape Sequences . 197 Operators. 22 se 22.1 Programs Based on for Loop. tr | 222 Nested or Loop... 141 | 23° white and dowhite Loops “41 | 23,1 Programs Based on wtile and do-whle Loop.Qblect Oriontod Programmi 2a aaa a Chapter 5: Classes and Objects 5-1 to 5-30 ‘Syllabus : Classes and Objects: 20 Unit Outcomes 27. Some More Practes Programs. Develop relevant fiond functions to solve the given problem. 2.8 _ Exam Pack (MSBTE and Review Questions) Write C++ program to use array of given objects. ver sl Hee: Function, Arrays and Strings _3-1t03-27 | | Wrte C++ program 10 create the glen object using 5 constructor. Catone en nn eta oes ‘Write program to delete the given object using destructor in va C++ program. ‘Wste POP based C++ program using aay to solve tho gen ‘Toples and Sub-Toples ae (Class and Object: Introduction,“Spectying a Class, Accoss pa nd teenie ‘Spector, Defining Member Functions, Creating Objects and cera Memory Allocation for Objects. oa Static Data Members, ‘Static Member Function, Friend ‘Scop Resolution Oporatr, : 31 Functions. 9:2 Programs Based on Function. 33 - Recursive Functions... ¥ Syllabus Tope : Arrays in C4. 34 Amays(s-17). 3.5 Mutti-dimensional Arrays. ’ 31 | | Array of Objects, Objects as Function Arguments. 3 | | Concepts of Constructors, Types of Constructors. Multiple Constructors in a Class, Constructors with Default Arguments, ‘Object Oriented Programming (W-14, 8-16, W-17), Y Syllabus Topte : Ciass and Object: Introduction. 38 5.1.1 Class and Object: introduction a7 (S14, W-14, Wet6, w.17), 374 Y Syllabus Topic : Access Spec 372 51.2 Access Spectiors . ‘ 373 v 374 513 38 oa ‘Syllabus Topie : Creating Objects. ‘and Memory Y Syllabus Tople : Scope Resolution Operator... location of Objects (W-14, 8-15, W-16, -17). 3.8 Storage Classes and use of Scope Resolution 51.4 Creating Objects and Memory Operator. : S10 Exam Pack (MSBTE and Reviow Questions)... 327 |.” Chapter 4: Structures and Unions 4110 412 fat Syllabus : Principles of Object Oriented Programming 8214 et Outcomes: Usa te stuctre in C++ program for sching 522 the given problem Toples and Sub-Topics : Structures in C++ 523 Y Syllabus Tople : Structures in Cay. a 41 Stuctures (8-14, W-14, W.16,5-17, W-17, 42 Amays of Structure Variable. sa 43° Nested Structures. 531 $4 URINE : Sa2 45 Exam Pack (MSBTE and Review Questions) i 33a Object Orlentod Programming using C++ (MSBTE Table of Contents 7 Syllabus Tople: Constructor with Default Arguments. we 518 34 Constructors with DolauitArgumonts (6-16, w.17, 8:17, 518 4% Syflabus Tope: Destructors 519 5.4 Destructor (S-14, W-16, W-17) 519 % Syllabus Tope : Friend Function. 520 55 Frond Function (14, W-14, S16, We16, WT) ann 5:20 ¥ Syllabus Topic : Static Data Members, Static ‘Momber Function om ¥ Syllabus Tople : Aray of Objects. Static Mombors (W-14, W-16, W-17) 57 Array of Objects (8-14, W-14, W-16, §-17).. 7 Syllabus Tople : Objects as Function ArguMants.. 5-28 Objects as Function Arguments (W-14, S-1¢ 526 9 Exam Pack (MSBTE and Review Question)... 6-1 to 6-22 Unit Outcomes Explain given type of inheritance based on ts characteristic. Implement given type of inhertance in C++ program. Wilte C++ program using vitual baso class. ‘Use constructor in the given derived class. Topics and Sub-Toples Introduction to Inhertance, dofining a dered cass, Visbity Modes and Etfects ‘Types of inherttance ~ Single, muitlvel, mutiple, hierarchical, yb. Constructors In derived ass v cs “ 61 a1 a1 Syllabus Tople : Introduction to Inherttance, Defining Derived Ciass.. 1 Inrttance ($-14, $-16, W-16) . Syllabus Tople : Visibilty Modes and Etfocts Visibility Modes and Etfects (5-14, W-14, $15, W-15, W-16, $16, 17). Syllabus Topic: Single Type of Inhertance. a4 1.2 Single inheritance (W-15, W-16, S17) ‘Syllabus Tople : Constructor In Derived Ciass. 1.2.1 Constructor in Derived Class (S-15, W-15, S-16, W-17). ‘Syllabus Tople : Mult Lovel Type of Inhertance... ‘Mut Level Inhettance (8-14, W-14, 6-15, $16, W-16) Syllabus Tople : Multiple Type of Inherttance... ‘Mutiple Innerttance (6-14, 5-15, $-16, W-16, $17, W-17). 13 14 ————— Syllabus Tople : Hybrid Type of hortane nnn 48 81.5 Hybrid Inhorttance (8-15, 8-16)... 13 6.1.6 Problem In Muliplo and Hybrid Inhertance (W-15)....6-15 ¢ Syllabus Topic : Hierarchical Inhortance o18 6.1.7 Hlorarchicl Innertance (S-14, $15, 8-17) 16 62 Exam Pack (MSBTE and Review Question) nnn 20 ‘Chapter 7 : Pointers & Polymorphism In C++ 7-1 to 7-37 Compile time Polymorphi operator overloading, overtoading of unary and binary ‘operators, Rules for operator overloading. ‘Run time polymorphism : Virtual functions, rules for virtual functions, pure virtual function. Syllabus; Pointers and Polymorphiem In C++ Unit Outcomes: Create C++ programs to perform the ‘operations using pointers. Use function overloading to solve the given problem. Use operator overloading to solve the given problem. Implement run time polymorphism using virtual functions in the given C+ program. Topics and Sub-topics Concepts of Pointer : Pointer dectaration, Pointer ‘operator, address operator, Pointer arithmetic. Pointer to Object : Pointer to Object, this pointer, Pointer to derived class. Virtual Base Class and Abstract Class Introduction of Polymorphism, Types of Polymorphism, : Function overloading, given arithmetic ‘Syllabus Tople : Concept of Pointer: Pointer Dectaration... Points ($-14, $-15, W-15, W-17) ‘Syllabus Topic : Pointer Operator, Address 7A4 7.2 Programs Related to Pointers... 7.2.1 Simple Referencing and De-referencing using 72 722 73 ¥ Syllabus Topic : Pointer Asthmatic. 74 72.3 Pointer Asthmatic: Increment and Decrement Operators Operation on Pointer Variables (W-14, $15, S-16)....7-4 724 — Pointorto Array (W-15, W-17).. ns 7.2.5 Passing Pointers to Functions... 72.6 Cally Value and Call by Reference (W-14, 8-18, WAS, S16, $-17, W-17). ¥ Syllabus Tople : Function Overloading... ve TAO 7.3 Function Overloading or Function Polymorphism 1.Ing C++ (MSBTE) _4 Table of Contents Fo Cog Ne OTE) ener aeraenn esse ote Of Contents, Constructor Ovortoading UNIT V ] (S18, W4, 8-18, was, S16, 5-17) se TAS er neny TOPE Operator Overeating, Cveroedng | og, Overload = Filo Operatio 81t06-13 t Unary and Binary operators, les Operator Chapter: Filo Operations__ at to 13 oa me Serrrernnnnnns 4 | TS a oup 2 File Operation Say epatasea(Ovetadng of Una and Unit Outcomes : Identily relevant class for performing tea Paras) tho given file operation, Write statement to open and eS IRMAG W816, 557, HEAP onsite || Me OER siven fio in Ces, Develop Grr progem to $yabus Topic: nreductono Plymapiem, Perform readiwrite operation front the given fl. Pei caeere pene vr Toples and Sub-Toples : C++ Stream Classes , . Wine Classes for Filo Stream Operations, Opening Files, Sete tte 18 wets, wets, 18,47, wa7)..729 | | Gaston et Fle oa erator Writing to Files, ¥ —Sylabus Tople : VitualFunctons, Puls for Detection of End of File, Filo Modes Virtual Functions, Pure Vitual Functions ~Ta4 | 7 ytabunTople:Cx+ Brees Geveo a 7541 yam Binding using Vital uncon 81 Concaptot Steams and C++ steam Casses.. 4 anaen tine Polgmaism ¥ sylabus Tople Casses for Fie Steam (8-44, WIS, $16, WB, WAT) on 724 Tan : Pa 752 Rus for vita Functons 44, WB) summa? 24 | 14 prromenone a Jaz CiabusTople: PotertoDetWed Cnn 728 | 81.2 Advantages of Steam Cassese 782.1 Polnterto Derived Cass Y —_Sytabus Tople: Fie Modes, Opening Fle, (6-14, w-t5, 8:16, 8-17, 17)... 728 Ciosing Fis sc ¥ syllabus Top 82 File Management Functions and Fe Modes Glass a (©pening end Cosing Fes) 753 Vital Baso Class and Abevacs Oc _ | %_ Siltabus Topic: Reading trom and Witting to Fle, (14, 8:10, 17). 729 | 821 Reading tom and Witingo Fle... ¥—— Sylabus Tople: this Pointr.. 730 | ¥ Syllabus Tople: Detection ot and of Fo 7.6 this Pointer (S-14, W-14, W-15, $-16, $-17,W-17)....7-20 | 822 Detecting End of File Y Syllabus Tople : Pointer to Object. 7.31 | 83 Random and Binary File Handling. 77 Pomerwoed 84 cepongand or Handing Dung Fo (W815, WAS, S16, S47, WT) ocrrnnin HH | gg Examen aaa 78 Bram Pack (MSBTE and Review Questions) 794 | ge Exam pack gute anderen v0 81018 nnn BAZ Lab Index F Statement, ‘Name of the Program Page Nos. ‘Statement 1 Develop minimum 2 programs. using constants, variables, arithmetic expression, Lt operators, exhibiting data type conversion. * Program 1: Write a © / C++ program to accept a number and display its ut square. * Program 2.: Write a program to accept basic salary from the keyboard. | L-t Calculate the gross salary that includes basic salary, 50% DA and 40% HRA. * Program 3: Write @ program to accept a number and display ts equivalent | U2 ASCIl using type casting. ‘Statement 2 Develop a program toimplement decision making statements (if-else, switch). Le * Program 4 : Writo a program to check i the entered number prime number or | L.2 not. * Program 5 : Write a program to check if the entered number Armstrong or Le not. * Program 6: Write @ program to daplay the class according tothe marks scored | Lg by a stu Put and the class is disrr Objoct Oriontod Programmirig using C++ (MSBTE) 5 Statement Name of the Program ‘according to the following range : Marks Class: 70-100__| Distinction 60-69 - | First Closs 50-59 | Second Class 40-49 | Pass Class 039 Fail | a + __ Program 7 : Write a program to display a user entered number in words. Statement 3 | Develop a program to demonstrate control structures (for, while, do-while). La ‘+ Program 8 : Write a program to display first n elements of Fibonacci series. La ‘* Program 9 : Write a program to calculate the value of the following series. Ls Ve eget end ‘* Program 10 : Write a program to count the number of digits in a user entered | LG number. © Program 11 : Write @ program to find the sum and product of all the digits ofa Lg user entered number using the do-while loop. Statement | Develop a program to Implement t-dimension array. 6 © Program 12:: Write a program to sort numbers in ascending order. L6 OR Write a program to implement bubble sorting algorithm for sorting numbers in ascending order. Statement | Develop a program to perform matrix operations using rhulti-dimensional array. Le Program 13 : Write a program to multiply two matrices using a function. Le Statement 6 | Develop programs that implements a class and use it with objects. Lo * Program 14 : Write a program to find area of circle using Object Oriented} L190 Programming such that the class circle must have three member functions namely : (a) read() to accept the radius from the user. (0) computed for calculating the area. (c)_display() for displaying the result, Statement7 | Develop programs that implements a class and create array of objects. ut * Program 15 : Write a program to declare a class ‘staif having data members as | L-t ‘name and department. Accept this data for 10 staffs and display names of staff that are in cm department. Statement 8 | Write a program to implement friend function, Lie * Program 16 : Write 2 program to add two complex numbers using a friend | L-12 function, Statement 9 | Write a program to implement inline function. Lis * Program 17 : Write @ program to find area of circle using Object Oriented | L-13 Programming such thatthe class circle must have three inline functions namely : (2) read{) to accept the radius from the user. (©) compute() for calculating the area, (c)__display() for displaying the result, Statement 10 | Write @ program to implement all types of constructors Lis (constructor overloading) with destructor. * Program 18 : Write a program to find area of circle using Object Oriented Lag Programming, The value of the radius must be accepted from tho user in the ‘main program and pa: sed to the parameterized constructor and the class circleer Object Oriented Programming using C++ (MSBTE) _6 Table of Contents, Statement Page Nos. must have two (2) compute() for calculating the area. (b) display() for displaying the result. * Program 19 : Write a program to find area of circle using Object Oriented La Programming. The value of the radius must be accepted from the user in the ‘main program and passed to the copy constructor and the class circle must have two inline functions namely : (2) compute() for caloulating the area. (©) display() for displaying the resu. + Program 20 : Write a program to demonstrate the destructor. Lis Statement 11 | Write a program for Implementing single inheritance. Las + Program 21 : Write @ program to add two numbers using single inheritance | L-15 ‘such that the base class function must accept the two numbers from the user and the derived class function must add these numbers and display the sum. Statement 12 | Write a program for implementing mull level Inheritance. lar * Program 22 : Write a program to calculate percentage of a student using multi} — L-17 level inheritance. The base class function will accept the marks in three subjects from user. A class will be derived from the above mentioned class that will have 8 function to find the total marks obtained and another class derived from this will have functions to calculate and display the percentage scored. Statement 13 | Write a program for Implementing multiple inheritance. LB * Program 23 : Write a program to define the following relationship using multiple | L-18 inheritance. Statement 14 | Develop minimum | program to demonstrate Pointer to object. L19 * Program 24 : Write a program to declare a class birthday having data members | L-19 day, month and year. Accept this information for § objects using pointer to the array of object ‘Statement 15 | Develop minimum | program to demonstrate Pointer to derived class. L-20 *__ Program 25 : Write a program to demonstrate use of pointer to object. L20 ‘Statement 16 | Write a program to demonstrate operator overloading for Unary operator. Lar ‘* Program 26 : Write a program to negate the values of two variables contained | L.2t inan object. * Program 27 : Write a program to negate the values of two variables contained | t.o4 in an object by overloading the operator unary negate Le. Statement 17 Write a program to demonstrate operator overloading for Binary operator, Lee * Program 28 : Write a program to overload binary operator “+=" to add two| 1-22 complex numbers. ‘Statement 18 | Write a program to demonstrate function overloading, L23 * Program 29 : Write a program to add two numbers using function overtoading | L-23 such that one function adds two integers, second function adds two float humbers and the thid function adds a float number with an integer. ‘Statement 19 | Write a program to read and write data to and from a file. Lea * Program 30 : Write a program to wite and read string, integer and foat fromto | L.24 a [aleTs}Structured Programming with C++ | Syllabus . Principles of Object Oriented Programming > Unit Outcomes Write simple C++ program for solving the given expression using POP approach. > Topics and Sub-Topics = Procedure Oriented Programming (POP) Verses Object Oriented Programming (OOP) | = Basic Concepts of Object Oriented Programming and Object Oriented Languages, Applications of OOP — Cverses C++ , Structure of C++program, Simple C++ program =” Tokens, Keyword, Variables, Constants, Basic data types, User defined data types, Type castin Operators, Expressions = Memory Management Operator. 1 Computer — A computer can be visualized as a system with Inpu/Output (UO) devices, Central Processing Unit (CPU) and the memory = The computer as seen by you can be as illstated in the | interconnected as shown inthe Fig. 1.1.2. This isthe hardware Fig. 1.1 view of a computer. Fig. 1.1.2 : Hardware structure of compoter programmable system. It is a system that can be programmed — As a programmer, the computer can be seen. as a | by the t Koyboard ae Fig. 1.1.1 : Computer 1.2. Programming and Programming Languages = Besides other units, it is made of 2 monitor | (standard display uni), CPU (Central Processing Unit) and | — Programming isto give the machine alist of steps to perform | keyboard (standard input device). ipenarSae (MSBTE) _ the system to which the programming is done is a com ‘han itis called as Computer Programming The program of any system has to be done in the language understood by tht system, ~ A digital system ike computer understands only binary language (which consists only of Os and 1s), also called as ‘machine Language, Bu, programming in machine language is almost impossible for a human being. Hence, the ‘manufacturers of the processor develop a language called as assembly Language. Assembly language is simpler than the machine language, but imaking huge software using this is again very difficuh. Jt includes the fol ‘Ap English language word that specifies the operation to be performed and ‘The Operands, which are the data on which the peration isto be performed. Which was there namely ‘0° and‘, ~All numbers and characters ae tobe Presented using *Q° op “V'only. Structured Programming with C++ SOT Ce ‘The conversion from binary to decimal and decimal to binary ‘can be done as shown below with examples. Decimal to binary : ‘The steps to be followed for converting a decimal number to a binary number are : © Divide the decimal number by 2. © Note down the quotient and remainder as shown in the example below. © Repeat the above procedure till the quotient is zero, © The last remainder is the MSB (Most Significant Bit i.e. the bit with highest weight) and the first remainder is the LSB (Least Significant Bit). Eg Oro = (Pz ‘means the number 5 in decimal (base 10) number ‘System. Base 10 means 10 different representations 0 10 9, Or (hr means the number in binary (base 2) number system, Base 2 means 2 different representations O and 1, 2|s Quotient 2/2 1+-Remainder’ 2h1 0 0 1) =G0n, Fig-131 ~ Binary to decimal: The steps to be followed for converting a nary number to a decimal number are Ee.11100), = POM soy ony ~ 1648444040208, ~ This is how your decimal data comp data in Sore 5, butt stores 1 teem You Peal operations that are performovject ovoniod Programming using C++ (MSBTE) 1-3 Structured Programming with C++ 1. AND: The outputs 1 if and only if A AND B (A & B being als the inputs are 1. alia A(INPUT) BUNPUT) YOUTPUT) 1 o 0 oO ° ° 1 0 Note: We can prefix 0's to a number in binary as in 1 A 5 decimal. Here, (014), Is written to make it 3 digit 1 Now,5&3 2 OR: The output is 1 if and only if A OR B (A & B being the inputs) 1 aon, AGNPUT, boneur | _yourrun cor o 0 ° 000), “ z z Note: Wis bitwise AND operator i. it works on each bit z o 1 as shown in the above example. u 1 1 (OOD, = 0x2+0x2' 41x? 3. NOT : The output is NOT A ( A being the input) ie. = Do eee OS Oo = Ow AQINPUT) ‘Y(QUTPUT) 2 BAND 10; 0 1 i 5 2}13 4, EXOR : The output is 1 if and only if EXCLUSIVELY A 2le 4 ORB( A&B being the inputs) are 1. 2{3 0 | a3 =«10n, ACNPUT) B(INPUT) Y(OUTPUT) 2ii 4 o 0 ec oi. o 1 1 1 o 1 1 1 o zoe) ‘Some examples of performing these operations on the binary 215 0 data are given below 2}2 1 | (0 =C010), 1, SAND3: 2)1 0 In‘C’ programming this is written as $ & 3. 04 2\s Now; 13 and 10 2/2 1 f @po=(on, (100, 2{1 0 &(1010),. o1 (1000,Joct Oriontod Programming using C++ (MSBTE) (1000), = 12940 27+0%2' +02" = (B)ip (D&M = By 2 70R6: 1n°C* programming, this is written as 716. 2]7 2)a4 2/1 1 | Mp=ain, on 2/6 2/3 0 2/1 1 | ©p=d10, O41 Now: 7 OR 6 an, 110, arp, (UD, = xP et xaterae = Mp Mol Oe = My 4. SOR2: =o, Oey | @o= (010), 14 Structured Progr Now, 5OR 2 aon, 110, ain, (MD, = 1x2 41x2'41%2° Ow Mo Go! Dio 5. 6EXOR3: In, this is written as 6 63 2/6 2/13 0 n=(110), vos 1 + @p= Om, o1 | Now: 6EXOR 3 aon, *@1y, Gon, (on, = 1x240x2' 4159" = Oy Ow Oy = Sy © Nors: In, this is writen as ~3 2]3 241 | 1 T pee, 0011 11100 Now; ~3igCbject Oviontod Progiamming using C++ (MSBTE) 15 vustured Programming with C++ The data may be of more than 2 bits and hence you will get the output depending on the size of data, [wow 1) 2) In computer binary language you will get this value as (~ 4)4o. 3) Hence if you say ~(10);o, you will get ~ (14) and s0 on. 14 History of C/C++ Programming Languages = C programming language was developed by Dennis Ritchie at the Bell Laboratories of AT & T. He developed a complier that can convert the HLL namely C to the machine language that Can be understood by the processor or the computer. But his compiler could understand only if certain rules were followed while writing the program. ~ We need to understand and know these rues to program our computers,using this programming language. C was the most popular programming language. Some other languages had become popular after some time of evolution of C. This was because these other programming languages were object oriented i.e. more significance was siven to object. . ~ While ‘C’ was a procedure oriented language i.e. more significance was given to the procedure to perform a task. = CH which is an object oriented programming language was then developed again at Bell Laboratories by Bjame Stroustrup. Eater, this language was called as C with classes, but was later renamed as C+ in 1983. = Object oriented and procedure oriented concepts of a programming language will be gradually seen in this book. Some of these concepts will be cleared in this chapter itself while some will come as you reach towards the end of this book. 5 Procedure Oriented Programming D> (W-14, W-15,W-16, -17) 0.15.1 Write any two characteristics of procedure oriented programming. (Ret. Sec. 1.5) (We14, 2 Marks) Q.1.5.2 List any four features of POP. (Ret. Seo. 1.5) (W-15, 4 Marks)| 0.1.53 In procedure orlentod programming all data are shated by all functions, Is this statement TRUE? Justify your answer, (Ref, See. 1.6) (W-16, 4 Marks) What are the features of procedure oriented programming? (Ref. Sec. 1.5) (S-17, 4 Marks) 0.15.4 = A procedure oriented programming language is one in which procedure ie. method or functions are given more significance. Here, one function calls another. — There can be global variables and local variables to cach function Fig 1.5.1 shows how a procedure oriented programming operation. — In this type of languages the task is divided into smaller tasks fr sub tasks called as procedures or functions or methods. ‘Any function can be called at any instant. = There are global and local variables as seen in the Fig. 1.5.1 ‘The global variables can be accessed by all the functions, while the local variables are local to the corresponding function, =A procedure oriented programming language follows top bottom approach, ~ Top bottom approach refers to approaching to a problem as a big task or as a whole. Then dividing this task into small instructions or operations. Hence, intially the task is broken into small tasks and then these smaller tasks are written in detail, Global data | + taaintaneton | toca data Fundton Fig. 1.5.1 : Structure of a procedure orienied Programming language= The disadvantage of such type of programming is that i is difficult to trace which functions are. using a data and also error correction is difficult G — C programming language is an example of procedure oriented language. =— SS Syllabus Topic : Basic Concepts of Object Oriented Programming and Object Oriented Languages 1.6 Basics of Object Oriented Programming (OOP) and OOP Languages D> ($-14, w-14, w-16) @.1.6.1 Describe any four basic concepts of OOP. (Ret. Sec. 1.6) (8-14, 4 Marks) Q.1.6.2 List any four object oriented languages. (Ret. Sec. 1.6) (W-14, W-16, 2 Marks)| ~ Object oriented programming as the name says gives more significance to the objects which has data and functions builf around it. — The data of the object can be accessed by the functions associated with it. The functions of one object can access the data of another object through the functions ofthat object. Object oriented programming uses bottom vp approach Wherein the smaller tasks are first dealt in detail and gradually creating the entire huge system. Object A Object B [a] Fig. 1.6.1 : Structure of an Object Oriented Programming (ZF ovject oriented Programming using C++ (MSBTE) 1-6 Structured Programming with Cr+ Fig. 1.6.1 shows the structure of a object oriented programming language. CH, Python, Ruby, C# and Java are examples of object oriented programming languages. ‘There are few important terms related to Object Oriented Programming that we need to understand. First the concept of, ‘objects and classes and then the specialties of OOP viz. Data Abstraction, Encapsulation, Inheritance, Polymorphism, etc. Let us understand them one by one. Class. 2. Object Data abstraction 4, Data encapsulation Inheritance 6. Potyntorphism Its a type or a category of things. It is similar toa structure ‘with the difference that it can also have functions besides data items. A structure, we have seen, can have only data variables but a class can have data members as well as function members. 2 Object It is an instance or example of a class. You can imagine it to be similar to a variable of class like we havé a variable of a structure, 3. Data abstraction Data abstraction is ike defining or abstracting the object according to the required parameters. For example; if there is 8 class for circle we need to just define the radius of the object of ths class. We néed not bother about anything else of that object. 4. Data encapsulation ‘The data of an object is hidden from other objects. This is called as encapsulation. Encapsulation is achieved by putting data and functions associated with it into a class. 5. Inheritance ° ‘The mechanism of deriving the properties of one class into ‘nother class is known as inheritance. We will see in detail about this concept in a special chapter dedicated on Inheritance.Structured Programming with Cr+ Foviect Orionted Programming using C++ (MSBTE) 1-7 > 6 Polymorphism Poly refers to multiple and morph refers to different forms. Hence, polymorphism means multiple forms of the same thing. This topic will also be covered in detail in the later chapters ‘Syllabus Topic : Procedure Oriented Programming (POP) Verses Object Oriented Programming (OOP), Cverses Cr+ ES Procedure Oriented Versus Object Oriented Programming Language or ‘C’ Language versus ‘C++’ Language D (S-14, W-14, $-15, S-16, S-17, W-17) 1.6.1 @.4.6.3. Differentiate between POP and OOP (any four points) (Ref.sec.1.6.1) (S-14, W-14, $-15, S-16, S-17, W-17, 4 Marks) Sr.| Procedure Oriented Object Oriented No| Programming (POP) | Programming (OOP) like like
(8-14, 5-15, 5-16, W-16) Q.1.6.4 Enlist he applications of ©P. (Ref. Sec.1.6.2) (S-14, $-15, S-16, W-16, 4 Marks) @0P finds wide applications in the IT industry. OOP models, the real world problems quite preciecely and hence it is more used today than the procedure oriented programming languages. The areas for application of OOP include : Real-time systems Simulation and modelling Object-oriented databases Hypertext, hypermedia and expertext ‘Aland expert systems "Neural networks and parallel programming Decision support and office automation systems CIMICAMICAD systems Features of C Programming Language WZ. C programming language as already discussed has one major feature of being a structured programming language and hence iti very easy forthe programmer. Its a procedure oriented language and hence has all features discussed in section 1.5. programming language has become popular because of its ‘major features like reliable, simple and easy to use. 1.8 + C++ as a Superset of C Programming Language (C+ was earlier called as C with classes, since itis a superset of C with addition of classes. C++ supports all features of C with few exceptions that will be discussed in the further chapters. C++ is an object oriented programming language with most of the programming rules same as that of C. ‘The object oriented features of C++ will be deal within the chapters 5 and 6.Syllabus Topic : Tokens: Structured Programmirg with C+ ‘Table 1.9.2 : Spectal Symbols and their names ” Symbol | Name of Symbol | Symbol | Name of Symbol 1.9 Tokens of C/C++ Comme A Q.1.9.1 Explain the tokens of C/C++ Period or dot S| Asterisk (Ret. Ses.1.9) Gtarke) : | Semicoton = _| Minws Sign Before going for programming, let us se a very important Cola + Sign thing required for programming ic. the tokens of a >gramming langua; 2 | Question Mark < | Opening Angle pes . a (Less than sign) ~The C/C++ programs are made up of different things termed astokens. 1 | Bxclamation > | Closing Angle e (Greater than sien) ~The different tokens of C/C++ are its = i & © character set ‘ 1 ipe ( Left Parenthesis: © keywords ‘ Forward Slash d Right Parenthesis © identifiers is \ Back Slash. t Left Square Bracket © constants and variables ee + | single Quotes 1 | Right square Bracket © operators — We will see these tokens in the subsequent sub-sections. eae Oe 4 aaa) ~_| Titae ht Brace 1.9.1 Character Set of C/C++ IES | iets Beas - = _| Underscore + | Hash ~The character set of any programming language indicates the diferent characters the program can contain. Character set ||» — | Care s | Dotter includes all the alphabets, digits and special symbols %__| Percentage ‘supported by the processor. — When we will be writing C/ C++ programs, all these will be found in our program, Table 1.9.1 gives a list of CICH ‘character set. Table 1.9.1 +: Character Set of C/C++ Characters List included 1. | Alphabets (Upper case and lower case) ABC. abe 2_| Digits (oumbers) 012.09) 3. | Special symbots (al those | <> ( }() 1], seen on a Keyboard, T=%RH@I\~*$_- ‘nothing besides that) (The names used for these symbols are given in the table 1.9.2) Other special characters | Blank Space, Tab, Carriage Retum (Enter Key) Each of these special symbols may have some significance which will be discussed in the forthcoming chapters. Sn Syllabus Topic : Keywords 1.8.2 Keywords @.4.9.2. What are keywords? List any 5 keywords are used in C/C++. (Ret, Sec.1.9.2) (4 Marks)| — These are some special words that have a predefined meaning for the C / C++ compiler, Hence, these words cannot be used as identifiers (identifiers ae discussed in section 1.9.3). ~ These are a set of words which are reserved for the certain ‘operations and hence are also sometimes referred as reserved words, ~All Keywords are in lower case.= The heywonts uyed in CCH areas given below. Stncturel Programming with Cr+ asin default] oat ‘operator stint | anion amo delete _| for sinvet | unsigned bea ao fiend | proscted | switch _ | using bool doubt | goto public template | virtual case dynamic | if register this void catch. [else | inline | reinterreteast | throw _| volatile char——_| enum _| int reura true wehar_t class | explicit_| tong short y while const__| export | mutable _| signed typedef const_cast | extern | namespace | sizeof rypeid continue | false [new static typename = These keywords will be used indifferent places in programming. Their significance and use will be studied wherever requ forthcoming chapters. = These keywords include all those keywords also as declared by ANSI (American National Standards published the standards to be used in C programming language. 1.9.3 Identifiers dentifers are names given to different wser defined things like variables, constants, functions, clases, objects structures, unions, etc. While making these identifies we need to follow some rules. These rules are stated below : 1. The identifier can consist of alphabets, digits and a special symbol ie,“ (underscore). 2. An identifier cannot start wth a digit It can stat either with an alphabet or underscore. 4. cannot contain any special symbol except underscore Blank spaces ae also not allowed. 4. teannor be a keyword. 5. is case sensitive ie. an alphabet capital in one identifier with same name in another identifier with that alphabet small case will be considered diferent (for more details see examples in this section). 6. Bare, there was limit ofthe length ofthe identifier to be 32 characters, but now this limit is removed. Hence, an identifier canbe as longa required and minimum of one character. Example 1 A list of valid and invalid identifiers is given below with reasons wherever required. ined in the fs Institute) C. This institute has 1. simple_interest: Valid char: Invalid, because itis a keyword friends: Invalid, because starts with a digit 2 3 4. Stents: Vals 5. Simple interes: Invalid, because blank spaces are not allowed 6 Bfriends: Invalid, because no special symbol except llowed, underscore 7. _ void: Invalid, because keyword not allowed. Void: Valid, case sensitive. Syllabus Topic : Basic Data Types: 1.9.4 Data Types Q.1.9.3 List data types in C/C++ (Ret. Sec.1.9.4) (4 Marks) = The data type decides the type of data and the memory locations required for storing that type of data in the memory. = The data types of C / C++ can be divided into three types: Primitive, Derived and User defined datatypes. = The different primitive types of data that can be used in C/C++ are integer, character, fraction type numbers, et. = Table 1.9.3 shows the different primitive data types and the memory space required for storing them.Objoct Orionted Programming using C++ (MSBTE Structured Pro Table 1.9.3 : Data types Se.No| Data type ‘Type of data tobe stored Range Space required in : memory (bytes) | char I character in ASC form —_| ~ 12710 128 1 2 _| signed char I character in ASCH form | - 12710 128 1 | 3.__| unsigned char Lcharacterin ASCUform | 010255 : 4. |i Integer nos. 32768 1032767 2 5. _| signed int Integer nos. = 32768 t0 32767 2 6 | unsigned int Integer nos. 010 65535 2 7._| shom int Inveger nos. = 32768 0 32767 2 8. | longi Integer nos. ~ 2147483648 to 2147483647 4 9._| signed shonin | tmeger nos. = 32768 10 32767 2 10,__| signed tong int | tnteger nos. ~ 2147483668 to 2147483647 4 11, | uasigned short int _ | Integer nos. 01065535 2 12,__| unsigned tong int | Integer nos. 00 4294967296 4 13._| Moat Fraction nos. 34e™* to 34e8 4 14. | double Fraction nos. Lew 1.70% 8 15.__| tong double Fraction nos. 34e"™ to te”? 10 Example 1.92: 8. Area of a circle: lat type data must be used, as area is Some examples of data to be stored are listed below with the datatypes that will be best suited for them 1. Age in years: int type data must be used, as years isan integer value, 2. Rate of interest: float data must be used, as rate of interest is a fraction type value. 3, Alphabet : char type of data isto be used, asa character is to be stored. 4, Principal amount: float type data must be used, as principal is in rupee and paisa. ‘5. Runs made by a batsman: int type data must be used, as no. of runs will always be integer. Factorial of a number: int type data must be used, as the factorial is always an integer. Radius ofa circle: float type data must be used, as radius wil mostly be a fraction number. radius? X 3.14, which histo be fraction number, 9. User input as “Y" or ‘N': char type data must be used, as there is only a character to be taken from the user as yes or no. Boolean type of data may also be used for this. Note: the arithmetic operations can be done even on char type of data. Tis is because the processor stores ASCII (American Standard Code for Information Interchange) to store the characters, ~The ASCII value for capital “A” is 65, ‘Bis 66, °C" is 67 and 0 on. While the ASCH values for small alphabets are 97 for 8", 98 for ‘b’, 99 for ‘e* and s0 on. ~The user defined data types are structure, union, class and enumeration. The derived data types are array, function, pointer and reference. ‘The derived and user defined datatypes will be studied inthe subsequent chapters wherever itis needed,‘Object Oriented Programming using C++ (MSE _——— Syllabus Topic : Constants and Varlables Constants and Variables 1.9.5 .1.9.4 Dofino torms constants and variables (Rot. Sec. 1.9.5) (2Marks) = Constants are values given to the identifiers that do not change their values throughout the execution of the program. = Constants can be defined either by writing the keyword const before the data type or by using fdefine, = Constants are used to declare the values that remain constant, for eg. value of pi. = The use of constants in program will be discussed later wherever required. = Variables are values given to identifiers that can change their values during the execution of the program. Example 1.9.3: ‘A variable can be defined with the data type as shown in the ‘examples below : 1. For declaring age as an integer type data the syntax (grammar or method of writing) is int age; 2. For declaring rate of interest as float data type the syntax is: float rate; . 3. For declaring a character data type element the syntax is: char x; 1.9.6 Escape Sequences Escape sequence is a character followed by a backslash () = They are used especially to perform some special operations like going to new line, providing a horizontal tab, vertical tab ee. ~ The following is ist of escape sequences. 1. Ww Newline MC Horizontal Tab W. Vertical Tab Nb Backspace \r Carriage Retum \F Form feed Wa Ausible Alert bell NV Backslash Structured Pr 9. MP Question mark 10. ¥ Single uote 11, \* Double quote 1.9.7 Operators = Operators are different special symbols used for indicating an ‘operation to be performed. = The operators will be dealt in detail in section 1.12, Nene eee eS Syllabus Topic : Structure of C++ Program , Simple C++ Program 1.10 Structure of C++ program D> (WA5, S-16,5-17, W-17) Q.1,10.1 With suitable diagram describes structure of C++ program. (Ref. Sec. 1.10 and Prog.1.10.1) (W-15, 4 Marks)| Q. 1.10.2. Write structure of C++ program. (Ref. Sec. 1.10 and Prog. 1.10.1). (S-16, 4 Marks) Q.1.10.3 Explain the structure of C++ program: with ‘suitable example. + (Ref. Sec. 1.10 and Prog.1.10.1) (8-17, 4 Marks) Q.1.10.4 Explain the structure of C++ program. (Ret. Sec. 1.10 and Prog. 1.10.1) (W-17, 4 Marks) — To begin with a very simple program in C, to display the stting “Hello Friend” on the standard output device i.e, the ‘monitor of a computer. — We will then understand the meaning of each word writen in the program and also how to execute this program. 1.10.1 Simple C++ Program » Program 1.10.1 : Write is a simple program to display a statement “Hello Friend”. {This isa simple program to display a statement 11 “Hello Friend” #include
#include
wt Object Oriontod Programming using Gi+ (MSBTE) 1-12 Structured Programming vith C++ void 1 { in) cout< <"Hello Friend’; getehQ; } Output : Hello Friend. Explanation of the above program : ~The first line that stars with “i, indicates that this is a ‘comment line. The comments are written ia a program for future reference of a programmer. — The comments are neglected by the compiler (compiler is a Software tool that converts the C 7 CH+ program to the ‘machine language). j- In comments you can write anything, it may be helpful to lunderstand your program by somebody else or by yourssif after you see the program after a long period. — Any statement that begins-with the ‘#” sign is meant forthe Pre-processor (pre-processor is a tool that works on the rogram before the compiler, discussed in section 1.11). = The next statement includeciostream ho, is tes the Preprocessor to include a header file name iostream. withthe program written by the user, — Our programs will definitely have some data to be taken from the user and to display some data on the monitor, The ‘cin’ and ‘cout’ are the statements to handle the input and output operations respectively. — The meaning of these words and the process required to be performed for taking the input and displaying the output is ‘mentioned in the header fle namely iostream.h. = In this program we have used the statement cout, hence we hhave included this header file in our program. - Any program of C / C++ should have a main function (Gunction is a set of statements to perform a given task). In the statement void main (), the word “void” indicates that this function is not going to return any data to its caller function, ‘The word “main” is identifier which identifies the function ‘The brackets at the end of this statement, parameters can be passed to this function. We will see more about the retum type of a function and its parameters in @ place where chapter 7. ~The curly braces ({ and }) indicate the stat and end of the function. The “(* indicates beginning of function, white 1” indicates end of the function. = “cout” statement is used to display a data on the standard ‘output device i. the monitor. The “<<” associated with the cout statement,is called as the insertion operator. — The statements given on the tight ofthe insertion operator are
‘ifinclude
0 void ms { imti=5j=4,k; cout<<"Produet is:"<
..}; For example an enum of the week days can be as shown below: enum WeekDays (Sunday, Monday, Tuesday, Wednesday, ‘Thursday, Friday, Saturday, Sunday): = The syntax of declaring a variable of enum is as shown below: cenum_name enum_variable; For example if we want to create a variable of above declared enum of weekdays, WeekDays today; = To asssign a value to a variable of enum, the symtax is as shown below: cenum_variable = valve; For example if the value "Sunday" is to be assigned to the above created enum_variable we need to write, today = Sunday: program example fo thes #inelude
sme can be as given below : void. main() { clrscer()s [Ef ovjnet onenied Programming wsing Ges (MSBTE) 1-19 Ssrurtrod Programing wits Gos enum WeekDayn (Sunday, Monday, Tuesday, Wednes WeekDays today; today = Sunday; if (today == Sunday || today cout << "Holiday's else cout << "Go to work."; turday 5 lay, Thursday, Friday, § Saturday) etch; + Output : Holiday 1.11. Integrated Development Environment (IDE) = IDE is a toolkit to write and execute a program. The most ‘widely used IDE with the C / C++ programs is the Turbo C DE. — This IDE contains of five tools Preprocessor, Compiler, Linker and Loader. namely : Editor, = Editor: It is used to type and edit the program. ~ Preprocessor : It is responsible for performing certain ‘operations before the compiling, like including header files, declaring constant, etc It always begins with the ‘#” sign. For e.g. fincludeciostream.h> ftdefine pi 3.14; = Compiler : It is used to convert the C / C+ program to machine language. As the processor cannot understand the Tanguage of C / C++, we need to convert it into a machine ‘understandable language ie. machine language. = Linker : tis responsible for linking (connecting) the different functions in a program. We may write multiple functions in the program or conditional/loop operations in our program. “These kinds of operations are to be handled by the linker. = Loader : It loads the binary file from the memory and gets is ‘executed by the processor. The binary file that the loader loads is the machiné language program understood by the processor. = The above program 1.10.1 in section 1.10 can be executed using the following steps: 1. Double click TC.exe to get the editor window.PPoviect oventea Program 2. Type the program in the ei 3. Save the program as cpp for eg, proglOL.cpp. 4. Compe the program by pressing Alt + F9 ie. press the Altand F9 key together. 5. Execute the program by pressing Cul + F9 6 Sce the output on the screen and press enter to come back to editor window. —— +_Syllabus Topic : Operators 1.12 @perators > wa @.1.12.1 Explain different operator used in CH, (Ret. Sec. 1.12) (W-17, 4 Marks)| ~The operators are one of the tokens of C/C++. There are different types of operators classified based on their functions. Many of these operators although listed here, but will be understood in the subsequent chapters as and when we use them. So you may just go through the operators and understand them later while programming. = The data on which the operation is performed are called as operands. = If an operator requires one operand, it is called as Unary ‘operator. If an operator requires two operands, then itis called 1s Binary operator and if it requires three operands, itis called as Temary operator. 4.12.1, Unary Operators D> (w-15, $-16, $-17, W-17) @.1.12.2 How address of (8) operator is used in pointers, explain with example. (Ret. Sec. 1.12.1(4)) (W-15, 2 Marks)| @. 1.12.3: Explain pointer operator and address operator with example. (Ref. Seo. 1.12.1) @. 1.124 Give significance of ‘8’ and“ operators. (Ref. Sec. 1.12.1(4 & 5)) (S-17, 2 Marks)| | scope resolution operator ? (W-17, 2 Marks) (8-16, 2 Marks)} @.1.12.5 What Is use 0! (Pot. See. 1.12.1(6)) turod Programming with C++ @.1.12.6 Stato scope rosolution operator and momory management operator in C++. (Reet. Sec. 1.12.1 and 1.12.6) (5-16, $-17, 4 Marks) 1 Unary minus (-): = The symbol shown in the bracket is used as unary minus operator. = Tt retums the negative value of the variable to which i preceded. = Foreg. if x=3andy=6 then ye. — willl make the value of y as ~3. > 2 Casting Operator (()): 1. It is many-a times required to convert one data type to another ©The casting operator is used for type conversion i. it can be used to convert a data of one type to another data ype. © Foreg.ifwehave int x=3; float y=5.Oriented Programmin then the statement, x=(int) y; will result in the value of x as 5. © The above method of casting is used in C. In C+, the casting is to be done in a slightly different manner ie. we need to mention x = int (y). © We will se the use of this operator in the programming 3. Lagical Not operator (1) = The symbol shown in the brackets i. the exclamation mark is, used as a logical not operator. It is used to check certain conditions ina condition statement. It performs the logical not of the result obtained from the expression omits right = Foreg. —iftx=l then will result with y having the value 0. ‘We will sce some more logical not operator based expressions and program followed by this section. % 4. Address of operator (&) : ‘This operator returns the address of the variable associated with it, It will be studied more deeply in the chapter on Pointers. = Foreg. if we write yodx; then the memory address allocated to the variable x will be copied into the variable y. For this the variable y must be 2 pointer variable. > 5. indirection operator or value of operator ( = This operator retums the value of the data at the given address. This operator will also be studied in more details in the chapter on pointers. % will give the value of the data stored at the address given by y - Foreg. > 6 Scope Resolution operator It resolves the scope of a variable tobe inside the Function or ‘outside the function. This operator will also be studied in a later chapter, For eg. if an external variable x is to be accessed then the same can be accessed using the scope resolution operator by the statement, y=x; 15 >. Structured Programming with C++ ‘Size of operator ‘This operator is used to know the size ofa variable as required to store its value in memory. It can also be used to find the size ofa data type. [As seen in the section 1.9.4, the space required to store different data type is different ranging from 1 byte to 1Obyees. Fore. the statement sizcoftint) ‘will etum the value 2, as int requires 2 bytes. Anothere.g: iat xy char a; xssizeof(a); yrsizzoffoa); then x will have 1, and y will have 4 8. Bitwise not operator (~) “This operator is used to perform bitwise NOT operation as discussed in the section 1.3. We have also seen some examples of NOT operations. The bitwise NOT operator can be used to pesform binary ‘NOT operation. This operation can be performed by using the operator given in brackets Le. Foreg. If x=3, then y=~x; will esult in y having a value of + 9. Increment Operator (+4) ~ It returns the value of the variable added with one and stores the result inthe variable itself. Foreg. ifx=5, then iH; will make the value of x equal to 6. This "x++;" (also called as post increment operator) can also be written as “+-+x:" (also called a pre increment operator) It can also be used to store the result in another variable. But in this case the post increment and pre increment statements will have different behavior as explained below with examples. [In post increment case, foreg. if x=5, then yaxtts ‘will make the value of y equal to 5 and x equal to 6.EP ovject orentor Programming using C++ (MSBTE) 1-16 ‘Structured Programming with C+. if various AS the name says post increment fist gives the previous | — These operator are further classified into varo pes ale and en incre namely the Arithmetic operators, Logical operators, Bitwise Value and then increments ‘operators and Relational operators n pre increment case, foreg. if x=5, aanrarar i % We will se these operators one by one inthis section ren yarn: (06 an 6. ‘will make the value of y equal to 6 and x equal to nny One A the name says pre increment, it fist increments and then ives the incremented value, TAibrmts ara ‘More such examples will be seen with programs. 1) Bitwise operators 10. Decrement Operator(-~) Il) Logical operators 'T retums the value of the variable subtracted with one and Stores the result inthe variable itself, IV) Relational operators Fores. ifxe then x Fig. C.1.2;: Binary operators will make the value of x equal to 4, * (also called as post decrement operator) can also "(also called as pre decrement operator). ean also be used to store the result in another vatiable But inthis case the post decrement and pre decrement statements will have different behavior as explained below with examples, be writen as: ‘willmake the value of y equal to 5 and x equal to 4, As the name says post decrement, it first gives the previous value and then decrements, {n pre decrement case, foreg. if x25, More such examples will be seen with Programs, 1.12.2 Binary Operators Q. 1.12.7 Explain bitwise operators, (Ret. Sec. 1.12.21) Q. 1.12.8 Explain logical operators (Ret. Sec. 1.12.2(u)) ~ Operators that require WO operands ate cated as binary (Arithmetic operators ‘This set includes the basic arithmetic operators to perform basic arithmetic operations like addition, imutupication and division. There are five operstors in this set. They ar: 2. to find the product 1 % (0 find the quotient after division (0 find the remainder after division 4. + tofind the sum 5. + ‘0 find the difference One important thing to be noted here is that the ‘Stam only the quotient, while the operator 8 MOD operator) rewuns the remainder after divisi °T” operator {also called ion, ‘The sign of the remainder is al Iways the same as that of the dividend, MOD operator is pos doesn't work on float © only forint or char type of data, tt and double type of data, ~ _ Forexample ofeach ofthese operators Lo 2ereg 2. For int type of data, 5/3 For Moat type of data, 5/3 = 1.67 3. 5%3-0, 4 24204 5. operators.(FT coc rents Pregranms ° using Ce (MSBTE) 1:17 Structured Programming with C++ (11) Bitwise operators “These operation: work bitwise ona daa “They perform differen operations on bits ofa data like AND, (OR, EXOR and NOT. These operations work in the manner as explained in section 1.3. ‘The operators are listed below : 1. = toperform bitwise NOT operation. 2. & to perform bitwise AND operation. 3. to perform bitwise OR operation. 4. to perform bitwise EXOR operation. 5. <€ to perform bitwise left sift operation. 6. >> toperform bitwise right shift operation. ‘These operators are use to perform bitwise binary operations on the data Ih wo tw ation, ntesestin pastes tr instal for performing atthmetic operations; similarly AND, OR, NOT are basic bitwise operations on the binary data. “The result ofthese operations can be ondestood from the following examples and referring the section 1.3 of binary operations : 1. 5&3=1 (nw =@ 1 0 tb Gow =@ 0 1 tb @ 0 0 Ff Dio 2 1219213 (Dp = 0 % wp = 0 0 Dr ato 3. 8410=2 @nv = 0 0 (0 = OF @o1 4, o@ 1 1 tb @ 0 0 Op (According to C /C+4/Java, wherein it will ake more no, of bits and hence -8 will be the result as also discussed in section 1.3). Hence; in general the ~x is always equal to -@+D. 5. W
3=1 ‘Assuming the data to be char ie. 8 bit data (139 = 000101)» ‘After shifting left once (00000101), ‘After shifting eft forthe second time (0000001 0 ‘Afer shifting forthe thd time (00000000) Note: When shifting to right, each of the bit is shifted right, The first bit is inserted as and the last bit is lost > (AD) Logical operators = Logical operators follow the same truth table as for the bitwise operators as seen in section 1.3; but they are used to check conditions instead of performing operations on a data, ~The logical operators are AND and OR. The symbols used for these operators in C are && and I respectively. — Forexample a statement y>5&& y <10; will result in “true” ic. 1 if the value of y is greater than 5 AND less than 10, else it will result in false Le. 0. = Another example a statement y>sil y ‘will result in “true” ie. 1 if the value of y is greater than 5 OR equal to 2, els it will result in false ue. 0. = Logical operators will be understood in more details with the ‘expressions and program examples followed by this section. > AV) Relational operators ~The relational operators are used to test the relation between two variables or a variable and constant. = The operators like *<' (less than) and ‘>’ (greater than) used in the above examples are relational operators. We have seen the example also of the "==" (equality operator) inthe above logical operators.Bon ct Oriented Programming using C++ (MSBTE) 1-16 1.12.4 Assignment Operators ~ _Allist ofall the relational operator 1, == used to check ifthe two things are equal. is given below: used to check ifthe two things are not equal. 3. used to check ifthe first data is less than the second 4. > used to check ifthe first data is greater than the second 5. <= used to check if the first data is less than or equal to the second one. 6. >= used to check if the first data is greater than or equal to the second one. The examples ofthese relational operators are as shown with the logical operators above, 1.12.3. Ternary Operator — Am operator that requires three operands is called as a ternary ‘operator. ~ There is only one ternary operator in C / C+. This operator is used to check a condition and accordingly do one of the two things based on the condition being true or false. ~The syntax (way of writing) ofthis operator is as given below: (Condition) ?
:
; — Hence; as shown in the syntax, first the co n is to be written in brackets followed by a question matk (2). Then the ‘operation that is to be performed if condition is true and then @ colon (:) followed by the operation to be performed if the condition is false. ‘This statement will put the value of x into z if the given Condition ie. x > y is true. Else; the value of y willbe put into 2. Hence, the value of the greater variable be pat into 2, — A Slightly complicated use of this operator is to find the greatest of three numbers as shown in the example BbOy)MGo>2)Px:2))4(G>2)?y:2), ‘This statement will give the largest of x, y and 2 into the variable g Structured Programming with C++ ‘These operators are used to assign the value of the expres (or variable on the right of the assignment operator 10 the variable on itslef ‘The simple Fig. C3 : Assignment Operators ‘The different assignment operators are as listed below : FP 1 =: This operator assigns the value of the expression (F variable on its right to the variable on its left. Foreg. yaxt2; FP % set This operator adds the variable on its left and ‘ight and the result is put into the vasiable on its eft. Fore.g. y+=n; is same as y=yax; xa ‘This operator subtracts the variable on its right from the variable on itslef and the result is put into the variable on its let. Fore. aS yey-x; is same4. *=: This operator multiplies the variable on its left and right and the result, fo the variable on its lef. Fore.g. y* 5/2: This operator divides the variable on its right from the variable on its left and the result is put into the variable on its left. For e.g. yeylns ‘This operator finds the remainder by dividing the variable on its right from the variable on its left ‘and the result is put into the variable on its left. For e.g. y5=x; is same as y=y%x; This operator ANDs the variables on its left and into the variable on its right and the result is pu left. For eg, y8e=x; is same as y=y&ex: ‘This operator ORs the Variables om its left and right and the result is put into the variable on its left. For e.g. ylox; is same as y=ylx; This operator EXORs the variables nits left and right and the result is put into the variable on its left. For e.g. y*=x; is same as Y=Y"X; ‘This operator shifts in left direction the variable on is left for the numberof times indicated by the 2 Wc: variable or value on right and the result is put into the variable on its left. For e.g. y<<=s; is same as eI: % M1.>>=1 This operator shifts in right direction the variable on its left for the number of times indicated by the variable or value on right andthe results put into the variable on its left. For e.g. y>>=X; is same as Jeyrx: 1.12.5 Selection Operators ~ These operators are used to select certain element of a set of clements, Here, we will make a list ofthese operators and see the detailed use of these operators when we study the ‘corresponding topic where these operators are required. Fig, C.1.4: Selection operators ‘This operator is used to select an element of ‘Array. We will understand more about this in the chapter on Array. 2 1o: “This is called as period operator and is used to select an element of a structure, union of class. This will be studied in detail in the chapter on structure and union. ‘This is used to select an element of a structure, union of class pointed by a pointer. This will be studied in detail int the chapter on structure and union. This is called as a function call operator and is used t0 call or select a function. This will be studied in detail inthe chapter on function, ‘The comma (.) operator is used to separate the different values etc, SS Syllabus Topic : Memory Management Operator 1.12.6 Memory Management Operators > (W-15,S-16,S-17) @.1.12.9 List two. memory management operators available in C++ and state its use in one line, (Ret. Sec. 1.12.6) (W-15, 2 Marks) State scope resolution operator and memory management operator in C++. * (Ret. Sec.1.12.1 and 1.12.6) (5-16, S-17, 4 Marks) @. 4.12.10a ~The new openutor is used in C+ for allocating memory || precedence Operation | Assocatvity Sami te C poping ngnge ve wed | Fm .lomwpe aotoin malloc) function for the same. The dfeences between " | my minus the new operator and the malo) function relisted in the Tae Lins ++ | Incrment pear i operator Table 1424 Decrement op a ! Logical NOT Sr. new operator ‘mailoc() function - Bitwise NOT a . Pointer value of 1. | itis an operator Iris fnetion operator, 2. | It returns the exact data | It returns the void type data & eee type which is to be type casted to ‘operator the required datatype. . Size ofa vatiabie or S221 atatype 3. | tt calls the constrictor | docs not call de oe ‘and can also be used to | constructor 0 Type cast operat define the primitive data A omnia iene types 1 | Divide and get quotient The delete operator is used in C+ for deallocating memory % | Divide and get dynamically allocated by new pean, romaine ~The programs based onthe new and delete operon wil te || x + [a Let ih seen in chapters Sand 7. = _| Subvact 1.13 Precedence and Associativity of : Slag | bet t Operators 6 < Less than Left to right ~The precedence ofthe operators means the sequeice in which el | aerenae , the operators willbe peated on incase of multiple operon ina sera i. ch pea it eee | ean ena hich operator wil be executed le, - - - ~ The asociatvty of oper refers tothe drecton in which || 7 | tem eae the operation wil be performed incase of equal precedence ‘Operators i.e. if multiple additions are there in a statement then . 4 | Bivise AND Loft right it will be performed from left to right, We will see more about | [9% “ Bitwise EXOR Left to right this in the examples followed by this section, 10. \ Bitwise OR Lett right — The precedence and associativity table is as given in Table 1.13.1 Syllabus Topic : Expressions ‘Table 1.13.1 : Precedence and Associativity of operators 1.14 Expressions | [Precedence | Operators Operation ‘Associativty ee | | 1 0 Function call ‘Left to right | yoo ‘Array element select > | siuecrer Camvies We wl ako see some examples wherin an exprecen one ‘tobe writen in C/ Cr+, so how are they writs | a (Determine he value ofthe folowing expressions select an‘Object Oriented Programming using C++ (MSBTE) 1 aed = 7%3 = 1 (since the remainder after dividing 7 by 3 is 1) 2 ale = 714 = 1 (since the quotient after dividing 7 by 4 is 1) 3. atble = 7193/4 = 21 / 4 (since; the associativity of arithmetic ‘operations is left o right first operation is *) = 5 (since; quotient is 5) 4. at (%b) = 746 %3) = 71 (since; bracket opening isto be done first, and remainder of 4 divided by 3 is 1) =7 5. 2*b+3* (ac) = 2*343*(7-4) = 6+39@) = 6 +9( since precedence of multiply is more than add, first multiplication is done) 15 6 atemb = 194%3 = 28%3 =1 7. atb-e = 743-4 =6 Suppose the following statements are writen: int ied, j=6; float x=05, y=0.1; char a='a', bets Find the values of the following expressions 1. G*i-2*)%Q*a-b) = Q7~ 12) % @* 97 ~ 98) ...(since; the ASCH values stored in char type variables is 97 for a & 98 for b) Structured Programming with C++ = (15) % (96) 15 + G9+(4° 63))% (145-2 26/5) +(4* (6-3))%(946-2) woeo 2*(1) + G*(3))%(13) 2 +(12)% 13 = 14 3, (x>y) && (10) && G>3) = 1&& 1 && 1 ..... if condition is true its result is 1 eke itis 0) = 4. (
0) 1G>3) (0&& 1) NC) NC) el 5. 99 = 0. (since; condition given is false, the value of a is 97 as discussed in section 1.13) since; i is pre increment it will return the value after incrementing ie. 10) (ince; the condition given is true ic. after performing NOT operation the value bécomes 0) (Ul) Write the C assignment expressions forthe following : 1. Ais greater than B and greater than C (A>B)&& (A>) 2. Aiseither less than B or greater than C (A
©) 3. Side is equal to square root of (a? + b? + 2ab) Side = pow ((a*a+ b*b+2*a*b),0.5)Object Orientod Programmi Note: 1. All tho operations including that of, ‘multiplication Is to be specified; no operation {s impliad. For 0.g. we cannot write x = ab, Instead we nood to write x= a* b. 2. Only the round brackets ie. () are allowed in expressions, Other brackets have different meaning in the © / C++ programming languages. 3. pow(xy) Is an available function that can be used to perform x? operation. x and y are the variables to be given in the brackets as shown in above example, zz . _ (Gey ae Rty42 a= x tyt2*Q/y)szty/xty sey abt yim aae 5. xe A, = Cb+pow((b*b-4*a%e),05)yi2%a): %y = (-b-pow((b*b-4*a%c),05)2*a); 1 6 tsi ae a+1 (4 (k+a)/2); 1.15 Formatted and Unformatted lO Functions — _Inbuilt 10 functions are available in C for displaying data on the standard output device ie. monitor and accepting the input from the standard input device ic. keyboard. ‘These 10 functions are classified as foimatied and unformatted functions based on the formatting permitted.or ‘not. These are discussed in more details in the following sub sections. 1.15.1 Formatted 10 Functions ‘There are two formatted 10 functicias in C namely printf() to ‘display a data on monitor and scanf() to accept data from keyboard. 1. printf) Syntax. + prin{(‘Format or expressions) string”, list of variables using C++ (MSBTE) __1. 2 Structurod Programming with C+4 ‘The format string can contain the followin (a) Character set (A-Z, a-2, 0-9, all special symbols on the keyboard) (b) Blank spaces (©) Escape sequences (as discussed in section 1.9.6) (@) Field width ‘The width of a value can be fixed by specifying the field ‘width, Examples of such case are given below. (©) Format specifiers Format specifiers specify the format of the variable data ‘whose value is to be displayed. The format specifiers for different types of data is given in the table 1.15.1 ‘Table 1.15.1 : Format specifiers sr. | Data type No. a Sedor%i__| For integer type of data 2 Sf For float type of data 3. fe For char type of data 4. sot For double type of data 5. set For long double type of data 7 Examples : 1. print(“The number of buildings is %d",by; ‘This statement will print the output with the format specifier replaced with the value of b, 2, printi(The simple interest is "i; This statement wil prin the output where the format specifier ‘ef will be replaced with the float type value of the variable si. Print{("The simple interest is %5.2F"si; ‘The format specifier in this statement is accompanied with a Field width i, 5.2 (%$.20, which indicates five digits before the fraction point and 2 digits after the fraction point. This Statement will display the output wherein the value of si will be displayed with five digits before the fraction point and ‘only two digits after the fraction point 2 seanfo, Syntax: scanfYormat Sting", address of vatiables): Here,‘Object Oriented Programming using C++ (MSBTE) “The address of the variable is obtained with the help of the address of operator (&). Examples: 1. scanf("Rd"&x); “Tis statement is used to accept aint ype value from user in the variable x 2. seanid Sed SE" ey fe); ‘This statement is used to accept two int type data into variables x and y. It also accepts a float type data into the variable. 1.15.2 Unformatted 10 Functions = The unformatted 10 functions do not have any format Specifier. They are mostly used to accept and display only one character or a string (string is a set of characters to make a ‘word or sentence). Fig. C.L5 : Unformatted [0 Functions = The different unformatted 10 functions are listed below; 1. getehO + This function is used accept one character from the user. fgetche( : This function is used accept one character from the user and echo it (display it on the screen). getchar( : This function is used to accept one character from the user and echo it (display it on the screen) and also wait after that for the user to press the enter key. a2 gets) + This function is used to accept a string from the user, We will see in details of this when studying the chapter on strings. ‘Structured Programming with C++ ay ‘These functions are used to di character on the monitor, putchar(). > 5.puteho: ‘This function is used to display a string on the monitor. > 6 puts: 4.16 C++10 Techniqu D> (WA5,5-16, 5-17) Q. 1.16.1 Distinguish between ios member functions and manipulators. (Ref. Sec, 1.16 and 1.17) (6 Marks)| Q. 1.16.2 Describe syntax ‘of ‘cin’ and ‘cout’ with example. (Ret. Sec. 1.16 and Prog. 1.18.1) (W-15, 4 Marks)| @.1.16.3 Explain insertion and extraction operators. (Rel. Sec. 1.16) (6-16, 4 Marks)} Q. 1.16.4 Which are the input-output operator in CH? Give suitable example. (Ref. Sec. 1.16 and Prog. 1.18.1), (S-17, 2 Marks)| = The cin and cout are available in iostream.h. The different 1O functions seen in section 1.15 are of C programming Janguage. The C+ techniques of accepting input from keyboard is with the help of cin and displaying outpat is with the help of cout. = Thecinis always associated with an extraction operator (>>). ‘This operator extracts the input from the standard input device {ie the Keyboard and gives it to the variable on the right of it. = Fores. cin>>x; will extract the input from the keyboard and the user entered value will be putin tothe variable x. The user has to press the enter key after the user has entered the input. = Multiple extraction operators can be concatenated in a single statement and hence, multiple values taken from the user and siven to different variables. For eg. cim>>x>>Y: = The cout statement is used for displaying an output on the monitor. It is always associated with the insertion operator. We have already seen the use of this statement in the program 1.10.1. = The concatenation of insertion operators make it possible to combine multiple things and display on the monitor. If a particular statement is written in double quotes then it indicates that is to be displayed as itis.using C++ (MSBTE) ‘While i itis not written in double quotes then it must be the ‘ame ofa variable whose value isto be displayed, 1.17 Manipulators .1.17.4 Wirita short note on : Manipulators. (Ret. Sec. 1.17) (8 Marks) (2.1.17.2 Distinguish between ios member functions and ‘manipulators. (Ret. Sec. 1.16 and 1.17) (5 Marks)] Manipulators are used to perform certain special operations "ke moving the cursor to new line, fixing the width ofa data Yale ete. These are used to specify certain formats of the Cutput to be displayed when using the cout statement, ‘The different manipulators used in C+ are e ‘Setprecision( and setfill). These mani the header file "iomanip.h, ndl, setw0), ipulators are available in ‘The manipulator ends similar tothe escape sequence“ ‘is. used to bring the cursor to the next line, — Example: cout<<"Hello“
(w5,s.17, > Program 1.18.1 : Write aC / C++ program to accepta ‘umber and display its square. #include
#include
void main () 4 elrser); ‘int x, y5° cout<<"Enter a numbers"; cin>>x; yoxts; Coul<<"The square of "
= Using the fist cout statement the user is asked to provide a | #include
umber whose square isto be found void main 0 = The cin operator is'used to accept the input from the user. The | { statement cin is asociated with the extraction operator (>>), | __elrsr() which indicates that jhe cin statement extracts the input from | float rateOflnterest, years, principal, simplelnteres; cout<<"Enter the principal amount, rate of interest and no. of years: cin> > principal > >rateOfinterest>> years; simplelnterest = principal * rateOflaterest*yeare / 100; ‘cout<<"The simple interest is "<
Program 1.18.2 : Write a C / C++ program to accept | Output: two numbers and display its product. atc the principal omount Fate of interest and no. of #include
. ‘years:1000, #include
95 void main 0) 40 f ‘The simple interest is 950 clrser(); Explanation : [All the variables are taken as float as these parameters are normally with fraction part included like principal has rupees and paisa; rate of interest is fraction etc. 4: Write a program to accept basic int x, y,25 ‘cout < <"Enter two number: cin>>x>>y5 ® > Program 1. ‘cout <<"The product is "< <2 salary from the keyboard. Calculate the gross salary getch(); that includes basic salary, 50% DA and 40% HRA. } #include
Or . #include
utput : mee void main Q Enter two number:3 { ie : elrser(; ‘The product is 12Structured Programming with Cy, 126 Explanation : coul<<"Enter use temp variable i ariel For swaping two numbers we need 10 mp ee cin> >basie; and store one of the values in that temp variable. The other value jg o ‘en 40"basie/10; tobe then copied as shown in the program above. da = 50*basic/100; sess=basie-tdat ras Cout<<"The total salary is "<-
Program 1.185 : integers. #include
#include
: Write @ program to swap two void main () { celrser); int a, b, temp; cout<<"Enter two numbers:"; cin>>a>>b; tery ab b=temp: cout <<"After swapping the values are a="<
>a; i b=ac
‘#include
void main () { elrser(); int nl; float n2, result; Sout <"Entt oe integer and one lat type number cin>>nl>>n2; result=n1xg Object Oriented Programming using C++ (MSS. 4-27 Structured Programming with C+, cout <<"The provhuct is 2"<
Program 1.18.8 : Write a program to accept a float number and display the integer part using type casting operator. #include
#include
void main () { lrser(); int a oat b; ‘cout <<"Enter# float number: cin> >by int)b; ‘cout<<"The integer part of the number is:"<
Program 1.18.9 : Write a program to accept a number and display Ite equivalent ASCII using type casting. #include
void main 0) { celrser(); int a; cout< <"Enter a number:"; getch(); t Output ‘Enter « number:65 ‘This is ASCII value of: A Explanation : ‘This program also uses type casting operator to go to a lower datatype size. 1.19 Exam Pack (MSBTE and Review Questions) at List any four features of POP. (Refer Section 1.5) (W-15, 4 Marks) @.2 Write any two characteristics of procedure oriented programming. (Refer Section 1.5) (W-14, 2 Marks) @.3 In procedure oriented programming all data aro ‘shared by all functions. Is this statement TRUE? Justify your answer. (Refer Section 1.5) (W-16, 4 Marks) ‘Ans. : No. The global data is only shared with all the functions Q.4 What are the features of procedure oriented programming ? (Refer Section 1.5) (S-17, 4 Marks) © syllabus Topic : Basle Concepts of Object Oriented Programming and Object Oriented Languages @.5 Describe any four basic concepts of OOP. (Refer Section 1.6) (8-14, 4 Marke)(Refer Section 1.6) (W-14, W-16, 2 Marke) ‘Syllabus Topic : Procedure Oriented Programming (POP) Verses Object Oriented Programming (OOP),C verses C++. Q.7 Differentiate between POP and OOP: (any four points) (Refer Section 1.16) (S-14, W-14, $-15, $-16, $-17, W-17, 4 Marks) ‘7 Syllabus Topic : Applications of OOP Q.8 Enlist the applications of OOP. (Refer Section 1.6.2) (S-14, S-15, W-16, 4 Marks) 7 Syllabus Topic : Tokens 2.9 Explain the tokens of C/C++ (Refer Section 1.9) (6 Marks) ‘7 Syllabus Tople : Keywords 2.10 What are keywords. List any 5 keywords are used in CiC++ (Refer Section 1.9.2) (4 Marks) ‘Syllabus Tople : Basic Data Types Q.11 List data types in C/C++ (Reter Section 1.9.4) (4 Marks) ‘% Syllabus Topic : Constants and Variables 2.12 Define term constants and variables (Reter Section 1.9.5) (2 Marks) ‘@ Syllabus Topic : Structure of C+ Program, ‘Simple C++ Program @.13 Explain the structure of C++ program. (Reter Section 1.10) (W-17, 4 Marks) 2.14 Explain the structure of C++ program with suitable example. (Reter Section 1.10 and Refer Program 1.10.1) (S-17, 4 Marks) With suitable diagram describe structure of C++ program. (Reter Section 1.10 and Refer Program 1.10.1) (W-5, 4 Marke) Write structure of C++ program. (Refer Program 1.10.1) Q.16 (S-16, 2 Marke) 28 Structured Programming with +4 What do you mean by dynamic Initialization of varlable 7 How is it achieved 7 (Refer Section 1.10.2) (5 Marks) Syllabus Topic : User defined Data Types a.17 2.18 Write a short note on: Enumerated Data type. (Refer Section 1.10.3.1) (5 Marks) '& Syllabus Topic : Operators 2.19 Explain different operator used in C++. (Refer Section 1.12) (W-17, 4 Marks) @.20 Give significance of '&’ and “* operators. (Refer Section 1.12.1(4&5)) _(S-17, 2 Marks) @.21 Explain pointer operator and address operator with example, (Refer Section 1.12.1) (8-16, 2 Marke) @.22 How address of (&) operator is used in pointers, explain with example. (Refer Section 1.12.1) (W-15, 2 Marka) @. 23° What is use of scope resolution operator ? (Refer Section 1.12.1(6)) (W.17, 2 Marks) 2.24 State scope resolution operator and memory ‘management operator in C++, (Refer Sections 1.12.1 and 1.12.6) (S16, S-17,4 Marks) 1.25 Explain bitwise operators, (Refer Section 1.12.2(1) (6 Marke) @.26 Explain logical operators, (Refer Section 1.12.21) (6 Marks) Select the correct answer : (Reter Section 1.12.1) (2 Marks) int a =29, b= 10; float ¢; C= (float) (afb); The correct value of cis @ 29 fi) 2 Gy 3 (¥) compitar dependent, Ans. : (il)2 Since; the operation is performed with af, which are both integers, the result is integer only. The result when converted to float remains float
You might also like
C++ Complete
PDF
No ratings yet
C++ Complete
41 pages
2024 Model Answer Paper
PDF
No ratings yet
2024 Model Answer Paper
20 pages
K Scheme OOP Unit Test-1 Question Bank
PDF
No ratings yet
K Scheme OOP Unit Test-1 Question Bank
12 pages
Object Oriented Programming C++ Solved Manual
PDF
No ratings yet
Object Oriented Programming C++ Solved Manual
161 pages
CPP IMP Questions by Vishal Sir
PDF
No ratings yet
CPP IMP Questions by Vishal Sir
108 pages
DMS Question Paper Winter 2024
PDF
No ratings yet
DMS Question Paper Winter 2024
3 pages
CPP Unit-1
PDF
50% (2)
CPP Unit-1
73 pages
Important Instructions To Examiners:: Correct 2M
PDF
No ratings yet
Important Instructions To Examiners:: Correct 2M
23 pages
Java Programming
PDF
100% (1)
Java Programming
8 pages
22CS101-Problem Solving Using C++ Unit II
PDF
No ratings yet
22CS101-Problem Solving Using C++ Unit II
87 pages
Winter 23
PDF
No ratings yet
Winter 23
25 pages
Oop Chapter 1
PDF
100% (2)
Oop Chapter 1
4 pages
Sy Sem III 22316 QP Model Answers Oop
PDF
No ratings yet
Sy Sem III 22316 QP Model Answers Oop
78 pages
Software Engineering - Techncial Publication
PDF
No ratings yet
Software Engineering - Techncial Publication
120 pages
Object Oriented Programming (OOPs) or C++ Sample Paper of MSBTE For Third Semester Computer Engineering Diploma (80 Marks)
PDF
90% (10)
Object Oriented Programming (OOPs) or C++ Sample Paper of MSBTE For Third Semester Computer Engineering Diploma (80 Marks)
3 pages
Model Answer Winter 2019
PDF
No ratings yet
Model Answer Winter 2019
22 pages
S-24
PDF
No ratings yet
S-24
23 pages
DMS 22319 Notes PDF
PDF
100% (1)
DMS 22319 Notes PDF
160 pages
Oop Chapter 2
PDF
No ratings yet
Oop Chapter 2
8 pages
2018 Winter Model Answer Paper
PDF
No ratings yet
2018 Winter Model Answer Paper
25 pages
Advanced Java Model Answer Paper
PDF
No ratings yet
Advanced Java Model Answer Paper
19 pages
22316-2023-Winter-Question-Paper (Msbte Study Resources)
PDF
No ratings yet
22316-2023-Winter-Question-Paper (Msbte Study Resources)
3 pages
OOP 2025 26 Course File
PDF
No ratings yet
OOP 2025 26 Course File
13 pages
DTM w22 22323
PDF
No ratings yet
DTM w22 22323
18 pages
1120231-CO - OOPS All MSBTE Board Paper With Solution
PDF
No ratings yet
1120231-CO - OOPS All MSBTE Board Paper With Solution
72 pages
22593-2023-Winter-Question-Paper (Msbte Study Resources)
PDF
No ratings yet
22593-2023-Winter-Question-Paper (Msbte Study Resources)
2 pages
Msbte w22 22103
PDF
100% (1)
Msbte w22 22103
21 pages
2016 Winter Model Answer Paper
PDF
No ratings yet
2016 Winter Model Answer Paper
31 pages
Addressing Modes of 80386
PDF
No ratings yet
Addressing Modes of 80386
3 pages
MIC Notes (22415)
PDF
100% (1)
MIC Notes (22415)
60 pages
Today's Content: Program Development Steps
PDF
100% (1)
Today's Content: Program Development Steps
7 pages
Data Structure
PDF
No ratings yet
Data Structure
6 pages
2017 Summer Model Answer Paper
PDF
No ratings yet
2017 Summer Model Answer Paper
29 pages
Unit 4
PDF
No ratings yet
Unit 4
96 pages
2022 Winter Model Answer Paper (Msbte Study Resources)
PDF
No ratings yet
2022 Winter Model Answer Paper (Msbte Study Resources)
20 pages
2019 Summer Model Answer Paper (Msbte Study Resources)
PDF
No ratings yet
2019 Summer Model Answer Paper (Msbte Study Resources)
27 pages
Dsu Map W22
PDF
No ratings yet
Dsu Map W22
25 pages
OOP VIMP Question - Super 25 - V2V
PDF
No ratings yet
OOP VIMP Question - Super 25 - V2V
2 pages
Java Summer 24
PDF
No ratings yet
Java Summer 24
31 pages
DTE Notes
PDF
No ratings yet
DTE Notes
130 pages
M3 Solved Question Paper (2019 Pattern)
PDF
No ratings yet
M3 Solved Question Paper (2019 Pattern)
4 pages
Dsu Imp
PDF
No ratings yet
Dsu Imp
9 pages
Dte (22320)
PDF
No ratings yet
Dte (22320)
71 pages
CGR Model Answer Paper Summer 2023
PDF
No ratings yet
CGR Model Answer Paper Summer 2023
28 pages
C - Notes (Data Planet)
PDF
No ratings yet
C - Notes (Data Planet)
142 pages
3 Hours / 70 Marks: Seat No
PDF
No ratings yet
3 Hours / 70 Marks: Seat No
88 pages
17431-2019-Winter-Model-Answer-Paper (Msbte Study Resources)
PDF
No ratings yet
17431-2019-Winter-Model-Answer-Paper (Msbte Study Resources)
33 pages
2019 Summer Model Answer Paper (Msbte Study Resources)
PDF
No ratings yet
2019 Summer Model Answer Paper (Msbte Study Resources)
17 pages
2022 Summer Model Answer Paper (Msbte Study Resources)
PDF
No ratings yet
2022 Summer Model Answer Paper (Msbte Study Resources)
16 pages
DTM - PT-2 (Updated) Question Bank
PDF
No ratings yet
DTM - PT-2 (Updated) Question Bank
11 pages
OOP Practical 15
PDF
100% (1)
OOP Practical 15
7 pages
C++ QP
PDF
No ratings yet
C++ QP
7 pages
22323-2019-Winter-Model-Answer-Paper (Msbte Study Resources)
PDF
No ratings yet
22323-2019-Winter-Model-Answer-Paper (Msbte Study Resources)
21 pages
Model Answer Winter 2015
PDF
No ratings yet
Model Answer Winter 2015
38 pages
2018 Winter Model Answer Paper
PDF
No ratings yet
2018 Winter Model Answer Paper
20 pages
Fds Assignment 3
PDF
No ratings yet
Fds Assignment 3
2 pages
22412
PDF
No ratings yet
22412
24 pages
Department of Computer Science and Engineering Question Bank
PDF
No ratings yet
Department of Computer Science and Engineering Question Bank
9 pages
MSBTE JAVA 9113 Question Paper
PDF
No ratings yet
MSBTE JAVA 9113 Question Paper
10 pages
Object Oriented Paradigm: C++ Programming Language by Bjarne Stroustrup, 4 Edition
PDF
No ratings yet
Object Oriented Paradigm: C++ Programming Language by Bjarne Stroustrup, 4 Edition
2 pages
Adobe Scan 10-Jan-2024
PDF
No ratings yet
Adobe Scan 10-Jan-2024
68 pages
SIM Superset
PDF
No ratings yet
SIM Superset
28 pages
Android Workshop
PDF
No ratings yet
Android Workshop
26 pages
Chapter-4 Cookies LO1
PDF
No ratings yet
Chapter-4 Cookies LO1
33 pages
Chapter-4 Cookies LO2
PDF
No ratings yet
Chapter-4 Cookies LO2
21 pages
DTE Assignment 3,4
PDF
No ratings yet
DTE Assignment 3,4
14 pages