Tab 1 1 Name: _____________________________________________________ ______________________________________________________ Batch: _______________ Roll no : ________ Department: __________________________________________ SHRI G.P.M.DEGREE COLLEGE MahatmaGandhiRd,VileParleEast,Mumbai-400057, Tel.:8928387200. CERTIFICATE This is to certify that Mr/Ms _____________________________________ a student of F.Y.B.Sc. Roll No. _______ has completed the required number of practical in the subject of ___________________________________ as prescribed by the UNIVERSITY OF MUMBAI under my super vision during the academic year 2025-2026. Signatories: Subject In-charge (Name &Sign) : _________________ Principal Sign (Name & Sign) :_ ____________________ External Examiner (Name &Sign) : _________________ Date: ___________ ____________ College Stamp INDEX Teacher name: Mrs.Himani Saxena Subject :- Object Oriented Programming with c++ (practicals) Class/SEM : F.Y.BSC.CS/SEM-II(2025-26) Coursecode : Major 1 Sr. No. DATE Experiment Title Page No. Signature 1 Introduction to Classes and Objects 2 Branching and Looping Statements within Class Methods 3 Arrays (One & Two Dimensional) within a Class 4 Scope Resolution Operator and Variable Scope 5 Constructors and Destructors 6 Access Specifiers (Public, Private, Protected) 7 Inheritance (Single and Multilevel) 8 Multiple and Hierarchical Inheritance 9 Function Overloading and Overriding 10 Pointers and File Handling using Classes Experiment No.1: Introduction to Classes Aim: a. Create a simple class with data members and member functions. b. Demonstrate the use of class instances to access data and invoke member functions. Tools & Technologies used: Programming Language: C++ IDE: IDLE (Integrated Development and Learning Environment) Command Line Interface: Terminal or Command Prompt Learning Objectives: 1. Understanding Class Structure: ● Learn the syntax and structure of defining a class in C++, including data members and member functions. 2. Object Creation: ● Understand how to create objects (instances) from a class and recognize the significance of constructors in object instantiation. 3. Data Encapsulation: ● Grasp the concept of encapsulation by using access specifiers (e.g., public, private) to control access to class members. 4. Member Function Implementation: ● Develop skills to implement and invoke member functions that operate on class data, enhancing the functionality of objects. 5. Using Dot Notation: ● Learn to access and modify object attributes using dot notation, reinforcing the relationship between classes and their instances. 6. Code Reusability: ● Recognize the benefits of code reuse through the creation of classes, which can be instantiated multiple times with different data. 7. Practical Application: ● Apply theoretical knowledge by writing simple C++ programs that utilize classes and objects, fostering hands-on programming experience. 8. Debugging and Problem-Solving: ● Enhance debugging skills by identifying and resolving issues related to class definitions, object instantiation, and function calls. Theory: a. Creating a Simple Class in C++ In C++, a class serves as a blueprint for creating objects, encapsulating data and functions that operate on that data. Understanding the theory behind classes and objects is fundamental to mastering object-oriented programming (OOP) in C++. Here are the key concepts: Definition of a Class A class is defined using the class keyword followed by the class name and a block of code enclosed in curly braces. This block contains: ● Data Members: Variables that hold the state or properties of the class. ● Member Functions: Functions that define behaviours or operations that can be performed on the data members. Access specifiers control the visibility of class members: ● Public: Members declared as public can be accessed from outside the class. ● Private: Members declared as private cannot be accessed directly from outside the class; they can only be accessed through public member functions. ● Protected: Members declared as protected can be accessed within the class and by derived classes. Object Creation An object is an instance of a class. Memory is allocated for an object when it is created. Objects allow manipulation of the data defined in the class. b. Demonstrating the Use of Class Instances in C++ Instantiation of Classes Instantiation refers to the process of creating an object from a class. When a class is instantiated, memory is allocated for the new object, and the class constructor is invoked. This process can occur in two main ways: 1. Allocation: Objects can be created on the stack, where memory is automatically managed. When the object goes out of scope, its destructor is called, and memory is freed. 2. Heap Allocation: Objects can also be created on the heap using the new keyword. This requires manual memory management; the programmer must use delete to free memory when it is no longer needed. Accessing Data Members and Member Functions Once an object is instantiated, its data members and member functions can be accessed using the dot operator (.) for stack-allocated objects or the arrow operator (->) for heap-allocated objects. When an object is instantiated, constructors play a crucial role in initializing data members. A constructor is a special member function that is automatically called when an object of a class is created. Conversely, destructors are invoked when an object goes out of scope or Constructors and Destructors are explicitly deleted, allowing for cleanup operations. Code: Output: Learning Outcomes: 1. Understanding Object-Oriented Programming (OOP): ● Gain a fundamental understanding of OOP concepts such as classes, objects, encapsulation, and data abstraction. 2. Class Creation: ● Ability to create simple classes in C++, including defining data members and member functions. 3. Object Instantiation: ● Learn how to instantiate objects from classes and access their data members and methods using the dot operator. 4. Functionality Implementation: ● Implement member functions to perform operations on class data, enhancing code reusability and organization. 5. Debugging Skills: ● Develop skills to identify errors in OOP implementations and debug C++ programs effectively. 6. Practical Application: ● Demonstrate practical skills by writing and executing C++ programs that utilize classes and objects to solve problems. 7. Enhanced Code Structure: ● Understand how organizing code into classes can improve readability, maintainability, and scalability of C++ applications. Course Outcomes: 1. Understanding Object-Oriented Programming (OOP) Concepts: ● Students will be able to describe and apply fundamental OOP principles such as encapsulation, inheritance, and polymorphism 2. Class and Object Creation: ● Students will demonstrate the ability to define and implement classes with data members and member functions, facilitating the creation of objects. 3. Data Member Access and Manipulation: ● Students will effectively access and manipulate data members of class instances using appropriate syntax and techniques. 4. Member Function Implementation: ● Students will implement member functions that operate on class data, enabling them to encapsulate behavior within classes. 5. Memory Management: ● Students will understand the importance of constructors and destructors in managing object lifecycle and memory allocation, particularly in stack vs. heap allocation. 6. Practical Application of Classes: ● Students will demonstrate practical skills by writing C++ programs that utilize classes and objects, showcasing their ability to apply theoretical knowledge in real-world scenarios. 7. Debugging and Problem-Solving Skills : ● Students will develop debugging skills to identify and resolve issues related to class definitions, object instantiation, and function calls. 8. Code Reusability and Modularity: ● Students will recognize how using classes promotes code reusability and modularity, allowing for better organization of code in larger projects. 9. Application of C++ Syntax and Semantics: ● Students will learn the syntax and semantics of C++, enabling them to write efficient and effective code that adheres to best practices 10. Preparation for Advanced Topics: ● Students will be equipped with foundational knowledge necessary for exploring advanced C++ topics such as templates, exception handling, operator overloading, and file I/O operations Conclusion: Viva Questions: 1. What is a Class in C++? 2. What is an Object? 3. How do you define a Class in C++? 4. Can you explain how to implement a simple Stack using Classes in C++? 5. What are the benefits of using Classes in C++? 6. Can you explain what virtual inheritance is? 7. How do you implement polymorphism in C++? For Faculty use: Experiment No.2: Branching and Looping with Classes Aim: a. Implement programs utilizing branching and looping statements within class methods. Tools & Technologies used: Programming Language: C++ IDE: IDLE (Integrated Development and Learning Environment) Command Line Interface: Terminal or Command Prompt Learning Objectives: 1. Understanding Control Structures: ● Gain a foundational understanding of branching statements (such as if, else, switch) and looping statements (like for, while, do-while) used in programming languages to control the flow of execution in applications. 2. Application Development: ● Develop practical skills in creating console applications that effectively utilize a combination of selection (branching) and iteration (looping) statements to meet specified application requirements. 3. Decision Making in Code: ● Learn to evaluate conditions effectively to choose between different types of branching statements, such as when to use if-else, switch-case, or various loop constructs (for, while, foreach) based on the logic needed. 4. Variable Scope Management: ● Understand how to scope variables appropriately within different control structures, ensuring that variable accessibility aligns with the intended logic of the program. 5. Practical Implementation: ● Implement practical examples that demonstrate the use of branching and looping statements in real-world scenarios, such as processing user input, iterating over collections, and making decisions based on conditions. 6. Debugging and Optimization: ● Develop skills in debugging code that involves complex branching and looping logic, optimizing performance by understanding how control structures affect program execution flow. Theory: Control structures are fundamental components in programming that dictate the flow of execution within a program. They allow developers to control how instructions are executed based on specific conditions, making programs dynamic and adaptable. Below is a detailed overview of the theory behind control structures, focusing on their types, functionalities, and significance. Types of Control Structures Control structures can be broadly categorized into three main types: 1. Sequence ● Definition: The sequence control structure executes instructions in a linear order, from top to bottom. Each statement is performed one after another without any decision-making or looping. ● Example: In a simple program, tasks such as variable initialization and function calls are executed sequentially. 2. Selection ● Definition: This structure introduces decision-making capabilities into a program. It allows the execution of different paths based on specific conditions. ● Common Constructs: ● If-Else Statements: Used to execute certain blocks of code based on boolean conditions. ● Switch Statements: Provides a way to execute different parts of code based on the value of a variable. ● Example: A program that checks user input and executes different functions based on whether the input meets certain criteria. 3. Iteration ● Definition: Also known as looping, this control structure enables the repetition of a specific set of instructions until a particular condition is met. ● Common Constructs: 1. For Loops: Used when the number of iterations is known beforehand. 2. While Loops: Continues execution as long as a specified condition remains true. 3. Do-While Loops: Similar to while loops but guarantees at least one execution of the loop body. ● Example: A program that processes items in a list until all items have been handled. Importance of Control Structures Control structures are essential for several reasons: ● Dynamic Behavior: They allow programs to respond to different inputs and conditions dynamically, enabling more complex functionality. ● Efficiency: By using loops, programmers can avoid redundancy in code, making programs more efficient and easier to maintain. ● Complex Decision Making : Nested control structures enable the implementation of intricate logic, allowing for sophisticated decision-making processes within applications. Additional Concepts Nested Control Structures Nesting control structures (e.g., placing loops inside conditional statements) allows for more complex logic and decision-making capabilities within programs. Additional Concepts: 1. Nested Control Structures Nesting control structures (e.g., placing loops inside conditional statements) allows for more complex logic and decision-making capabilities within programs. 2. Flow Control Statements Statements like break and continue provide additional control over loop execution, allowing programmers to exit loops prematurely or skip certain iterations based on specific conditions. Code: Output : Learning Outcomes: 1. Understanding Control Structures: ● Define and differentiate between the three main types of control structures: sequence, selection, and iteration. This includes understanding how these structures dictate the flow of execution in programming 2. Application of Conditional Statements: ● Implement conditional statements (e.g., if, else, switch) within class methods to enable decision-making capabilities in programs. Students will learn to execute different code blocks based on specific conditions 3. Utilization of Looping Constructs: ● Demonstrate proficiency in using looping constructs (for, while, do-while) to repeat actions or process collections of data within class methods. This includes understanding when and how to use each type of loop effectively. 4. Algorithm Design and Problem Solving: ● Apply control structures to design algorithms that solve specific problems, enhancing logical thinking and problem solving skills. Students will learn to create step-by-step instructions that utilize branching and looping effectively. 5. Error Handling and Debugging: ● Identify common programming errors related to control structures (e.g., logic errors, syntax errors) and apply debugging techniques to resolve these issues, ensuring robust program functionality. 6. Nested Control Structures: ● Understand and implement nested control structures to handle complex decision-making scenarios, allowing for more sophisticated program behaviour. 7. Code Readability and Maintenance: ● Emphasize the importance of maintaining proper indentation and syntax when using control structures to enhance code readability and maintainability. 8. Practical Implementation: ● Develop practical coding skills by writing programs that incorporate branching and looping statements in real-world applications, reinforcing theoretical knowledge through hands-on experience. Course Outcomes: 1. Understanding Object-Oriented Programming: ● Differentiate between structured programming and object-oriented programming, demonstrating a clear understanding of the principles of encapsulation, inheritance, and polymorphism. 2. Application of Control Structures: ● Utilize branching statements (e.g., if, else, switch) and looping constructs (e.g., for, while, do-while) effectively within class methods to control program flow based on conditions and iterations. 3. Code Development and Debugging: ● Write, compile, and debug C++ programs that incorporate various control structures, ensuring correct logic and functionality in program execution. 4. Function Overloading and Operator Overloading: ● Implement function overloading and operator overloading techniques to enhance code flexibility and reusability within C++ classes. 5. Class Design and Implementation: ● Design classes that utilize constructors and destructors effectively, managing resources during object creation and destruction. 6. Inheritance and Code Reusability: ● Apply inheritance principles to create derived classes that extend base class functionality, promoting code reuse and modular design. 7. File Handling and Exception Management: ● Implement file handling operations in C++ for reading from and writing to files, as well as managing exceptions to handle errors gracefully during program execution. 8. Template Programming: ● Understand and implement templates in C++ to create generic classes and functions, allowing for type-independent programming. 9. Practical Problem Solving: ● Develop solutions to diverse problems using C++ programming techniques, showcasing the ability to apply theoretical knowledge in practical scenarios. 10. Understanding of Data Structures: ● Gain familiarity with basic data structures (e.g., arrays, linked lists) and their implementation in C++, using appropriate control structures for data manipulation. Conclusion: Viva Questions: 1. What are control flow statements in C++? 2. Can you explain the difference between a for loop and a while loop? 3. What is the purpose of the break statement in loops? 4. How does an if-else statement work? For Faculty use: