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)
23 views
C++ Questions For Practical
Practical
Uploaded by
rahulrajput5260
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save c++ questions for practical For Later
Download
Save
Save c++ questions for practical For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
23 views
C++ Questions For Practical
Practical
Uploaded by
rahulrajput5260
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save c++ questions for practical For Later
Carousel Previous
Carousel Next
Save
Save c++ questions for practical For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 12
Search
Fullscreen
‘Object Oriented Programming Concept Using C++ 2 Marks Questions & Answers L. List out the characteristics of FOP. 1. Large programs are divided into smaller programs known as functions. 2, Most of the functions share global data 3, Functions transform data from one form to another. 4, It employs top-down approach. 2. List out the characteristics of OOP. 1, Programs are divided into objects. 2. Data is hidden. 3. Objects communicate with each other, by sending messages and receiving responses. 4, It follows bottom-up approach. 3. List down the basic concepts of OOP. 1, Objects 2. Classes 3, Data abstraction and encapsulation 4. Inheritance 5. Polymorphism 6. Dynamic binding T. Message passing 4. Define an object. Objects are the basic run time entities in an object oriented system. They may represent a person, a place or any item that a program has to handle. 5. Define Object Oriented Programming. OOP is a method of implementation in which programs are organized as co-operative collection of objects, each of which represents an instance of some class and whose classes are all members of a hierarchy of classes united through the property called Inheritance. 6. Define a class. A.class is a collection of objects with similar attributes and operations. Eg. Class ~ Account It will create an object savings_account belonging to the class Account. 7. Define Encay - ‘The wrapping up of data and functions into a single unit is known as encapsulation. The data is kept safe from external interference and misuse. 8, Define Data hiding? The isolation of data from direct access by the program is called as data hiding or information hiding.1. Define class? A class is a way to bind data and its associated functions together. It allows the data to be hidden if necessary. 2. What are the parts of class specification? The class specification has two parts 1. Class declaration — To describe the type and scope of its members2. Class function definition — To describe how the class functions are implemented. 3. Write the syntax of class declaration class classname & Private: Variable declaration; Function declaration; Public: Variable declaration; Function declaration; u 4. Where will you define a member function? ‘Member functions can be defined in two places, 1. Outside the class definition. 2. Inside the class definition. 5, Give the syntax for member function definition outside the class. Return type class name:: function name (argument name declaration) {function body } 6. List the characteristics of member function. 1, Member function can access the private data of class. 2. A member function can call another member function directly without using the dot operator. 7. Define nesting of member function. ‘A member function can be called by using its name inside anather member function of the same class. This is known as nesting of member functions. 8, List the properties of static members. A data member of a class can be qualified as static properties. 1 It is always initialized to zero when the first abject of its class is created. 2. Itis visible only within the class. 9. Write the properties of static member function. 1. A static function can have access to only other static members declared in the same class. 2. A static member function can be called using the class name (Instead of objects) as follows: class name:: function name; 10. Define constructor? ‘A constructor is a special member function whose task is to initialize the object of its class, Its called constructor because it constructs the value of data members of the class.11. What are the characteristics of constructor? 1. Constructors should be declared in public section. 2. They are involved automatically when the objects are created, 3. They do not have return types. 4. They can not be inherited. 12. Define parameterized constructor. Arguments can be passed to the constructor function when the objects are created. The constructors that can take arguments are called as parameterized constructor. 13, What is an implicit constructor? ‘C++ compiler has an implicit constructor which creates objects even though it was not defined in the class. 14, What is the use of copy constructor? Copy constructor is used to declare and initialize an object from another object. E.g. Class name object2 (object); Will define the object2 and at the same time initialize it the values of object. 15. What do you mean by dynamic construction? Allocation of memory to objects at the time of their contraction Is known as dynamic contraction of objects. 16. What is the use of destructor? It is used to destroy the objects that have been created by a constructor. It releases the memory space for future use. 17. What are the characteristics of destructor? 1. A destructor is a member function whose name is the same as the class name but it is preceded by a tilde 2. It neither takes any argument nor returns any value. 3. It will be invoked implicitly by the compiler to cleanup the storage. 18. Define operator overloading? The process of making an operator to exhibit different behaviors in different instances is known as operator overloading. 19, Define function overloading? Performing different types of task using single function name is referred as function overloading, 20. Define Virtual function. ‘When the form of a member function is changed at run time, that member function Is referred to as virtual function.1What are the characteristics of procedure oriented programming language? 1. Large programs are divided into smaller programs known as functions Most of the functions share global data Data move openly around the system from function to function Functions transform data from one form to another Uses top-down approach in program design. Concentration is on doing things( algorithms) essen 2.What are the features of object-oriented programming languages? Programs are divided into objects Data structures designed such that they characterize the objects. Functions that operate on the data of an object are tied together in the data structure Data is hidden and cannot be accessed by external functions Objects may communicate with each other through functions New data and functions can be easily added whenever necessary IT follows bottom-up approach in program design Concentration is on data rather than procedure ee 3.Define Object Oriented Programming It is an approach that provides a way of modularizing programs by creating partitioned memory area for both data and functions that can be used as templates for creating copies of such modules on demand. 4. What is meant by an object? Objects are the basic run-time entities in an object-oriented system. ‘They may represent a person, a place, , a table of data or any item that the program must handle They may also represent user defined data such as vectors, time and lists. ‘When a program is executed, the objects interact by sending message to one another. Each object contains data and code to manipulate the data. Objects can interact without knowing having to know details of each other's data or code. 5. What is meant by Classes? 1. A class is a collection of objects of same type. 2. Once the class has been defined , we can create any numer of objects belonging to that class. 3. Each object is associated with the data of type class with which they are created. {Whit i eant by Kncapsitei? The wrapping up of data and functions into a single unit (called class) is known as encapsulation Data encapsulation is the most striking feature of a class. # The data is not accessible to the outside world and only those functions which are wrapped in the class can access it. ‘+ These functions provide the interface between the object’s data and the program + This insulation of the data from direct access by the program is called data hiding.5. What is a class ? It is an extension to the structure data type. A class can have both variables and functions as members What is the difference between structure and a class ? The only difference between a structure and a class in C++ is that , by default , the members of a class are private, while , by default the members of a structure are public. What is the specification for a class ? * Class declaration * Class function definitions ° What are data members and member functions? The variables declared inside the class are known as data members and the functions are known as member functions. The data members are usually private and member functions as public. Give a simple class example. class item { int number; float cost;public: void getdata(int a, float b); void putdata(void) ; ‘ Here class name is item Data : number, cost Functions: getdata(), putdataQ) 6. What are objects ? ‘The class variables are called objects. With objects we can access the public members using dot operator 7. Howisa member function of a class is defined? It can be defined either inside or outside the class 8. Cir tee ree eed Several different classes can use the same function name. the membership label will resolve their scope ‘© Member functions can access the private data of the class. Anon member function cannot do so + A member function can call another function directly ,without using dot operator 9. When a function is defined inside a class ? ‘+ it is treated as a inline function ‘© only small functions are defined inside the class definition 10. What is nesting of member functions ? Amember function can be called by using its name inside another member function of the same class, is known as member function 11. How the space is allocated for the objects? ‘The memory space is allocated when they are declared . space for the member variables is allocated separately for each object, but no separate space is allocated for the member functions 12, When do we declare a member of a class static? ‘When it is used to maintain values common to the entire class, The static member variables defined ‘outside the class 13. What is a friend function? ‘The functions that are declared with the keyword friend are known as friend functions. A function ‘can be declared as a friend in any number of classes, it has full access rights to the private members of the class. 14. What are the properties of a friend function ? ~ A friend function is not in the scope of the class to which it has been declared as friend. + Itcan be invoked like a normal function without the help of any object. + Unlike member functions it cannot access the member names directly and has to use an object name and dot membership with each member name,15. What is the difference between friend function and member function ? ‘The only difference between a friend function and member function is that, the friend function requires the argument to be explicitly passed to the function and processes them explicitly, whereas, the member function considers the first argument implicitly. 16. What is an inline function ? Inline functions are those whose function body is inserted in place of the function call statement during the compilation process. With the inline code the program will not incur any context switching overhead. 17. What is a recursive function ? ‘A function that contains a function call to itself or a function call to a second function which eventually calls the first function is known as recursive functions. 18. What are the special characteristics of friend function ? 4. Can be invoked like a normal function, with the help of the object. 2. Ithas the objects as arguments 3, It is not in the scope of the class to which is has been declared has friend 19, What is const member function ? If'a member function does not alter any data in the class, then we declare it as const member function, The keyword const is appended to the function prototype. 20. What is a constructor ? It is a special member function whose task is to initialize the objects of its class. It is, special because its name is the same name as the class name. 21. How do we invoke constructor function? It is invoked whenever an object of an associated class is created. It is called constructor because it constructs the values of data members of the class. 22. List some special properties of constructor functions. . They should be declared in the public section ‘They are invoked automatically when the objects are created ‘They do not have return types, therefore they cannot return values They cannot be inherited ‘They can have default arguments Cannot refer to addresses PRseNne 23. What is parameterized constructor ? It is nothing but passing arguments to the constructor function when the objects are created. The constructor can take arguments are called parameterized constructor. 24, What is copy constructor ? The constructor that creates a new class object from an existing object of the same class. 25. What is dynamic initialization of objects ? ‘The initial value of an object provided at the run time. The advantage is that we can provide various initialization formats ,using overloaded constructors.26. What is dynamic constructor ? Allocation of memory to objects at the time of their construction is known as dynamic construction of objects. The memory is allocated with the help of new operator. 27. What is a destructor? It is used to destroy the objects that have been created by a constructor, when they no longer required. 1.What is operator overloading? Operator overloading is a compile-time polymorphism in which the operator is overloaded to provide the special meaning to the user-defined data type. Operator overloading is used to overload or redefines most of the operators available in C++. For example, C++ provides the ability to add the variables of the user-defined data type that is applied to the built-in data types. 2.List the Operator that cannot be overloaded. Operator that cannot be overloaded are as follows: © Scope resolution operator (::) © Size operator (sizeof) ‘© Class member access operator (.) © Pointer to member operator (.*) © Ternary (or) Conditional operator(?:) 3. What is the purpose of using operator function? Write its syntax. To define an additional task to an operator, we must specify what it means in relation to the class to which the operator is applied. This is done by Operator function , which describes the task. Operator functions are either member functions or friend functions. The general form is return type classname :: operator op(arglist ) £ function body y where return type is the type of value returned by specified operation. Op-operator being overloaded. The op is preceded by a keyword operator. operator op is the function name. 4, How will you overload Unary & Binary operator using member functions? When unary operators are overloaded using member functions it takes no explicit arguments and return no explicit values. ‘When binary operators are overloaded using member functions, it takes one explicit argument. Also the left hand side operand must be an object of the relevant class. 5. How will you overload Unary and Binary operator using Friend functions? When unary operators are overloaded using friend function, it takes one reference argument (object of the relevantclass) When binary operators are overloaded using friend function, it takes two explicit arguments. 6, How an overloaded operator can be invoked using Friend functions? In case of unary operators, overloaded operator can be invoked as Operator op (x); In case of binary operators, overloaded operator can be invoked as. Operator op (x, y) 7. List out the operators that cannot be overloaded using Friend function. Operator that cannot be overloaded by friend function are as follows: © Assignment operator = © Function call operator () © Subscripting operator |} © Class member access operator -> 5. What are process of operator overloading? 1, Create a class that defines the data type that is to be used in the overloading operation. 2. Declare the operator function operator op() in the public part of the class. It may be either a member function or a friend function. 3, Define the operator function to implement the required operations. 6. What are the rules for overloading operators? 0 Existing operators can only be overloaded, but the new operators cannot be overloaded. co The overloaded operator contains atleast one operand of the user-defined data type. © We cannot use friend function to overload certain operators. However, the member function can be used to overload those operators. © When unary operators are overloaded through a member function take no explicit arguments, but, if they are overloaded by a friend function, takes one argument. © When binary operators are overloaded through a member function takes one explicit argument, and if they are overloaded through a friend function takes two explicit arguments. pms enccss shan ccceetl hia ate mac aimacen esi ge uncer tin
You might also like
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Mark Manson
4/5 (6129)
Principles: Life and Work
From Everand
Principles: Life and Work
Ray Dalio
4/5 (627)
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Brené Brown
4/5 (1148)
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
Chris Voss
4.5/5 (935)
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Jeannette Walls
4/5 (8215)
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Angela Duckworth
4/5 (631)
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
Jesmyn Ward
4/5 (1253)
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Stephen Chbosky
4/5 (8365)
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Phil Knight
4.5/5 (860)
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Carmen Maria Machado
4/5 (877)
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Ben Horowitz
4.5/5 (361)
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Margot Lee Shetterly
4/5 (954)
Steve Jobs
From Everand
Steve Jobs
Walter Isaacson
4/5 (2923)
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
Ashlee Vance
4.5/5 (484)
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
Siddhartha Mukherjee
4.5/5 (277)
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Fredrik Backman
4.5/5 (4972)
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Frank McCourt
4.5/5 (444)
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
Colm Toibin
3.5/5 (2061)
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Garth Stein
4/5 (4281)
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
Sarah M. Broom
4/5 (100)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Meik Wiking
3.5/5 (447)
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Thomas L. Friedman
3.5/5 (2283)
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Gilbert King
4.5/5 (278)
Yes Please
From Everand
Yes Please
Amy Poehler
4/5 (1987)
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Roxane Gay
4/5 (1068)
The Outsider: A Novel
From Everand
The Outsider: A Novel
Stephen King
4/5 (1993)
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
Ruth Ware
3.5/5 (2641)
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
Betty Smith
4.5/5 (1936)
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
Viet Thanh Nguyen
4.5/5 (125)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Dave Eggers
3.5/5 (692)
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Doris Kearns Goodwin
4.5/5 (1912)
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Hilary Mantel
4/5 (4074)
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Naomi Klein
4/5 (75)
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Bob Woodward
3.5/5 (830)
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
Jennifer Egan
3.5/5 (901)
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Jay Sekulow
3.5/5 (143)
John Adams
From Everand
John Adams
David McCullough
4.5/5 (2544)
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
M L Stedman
4.5/5 (790)
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
George Packer
4/5 (45)
Little Women
From Everand
Little Women
Louisa May Alcott
4/5 (105)
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel
John le Carré
3.5/5 (109)