{"id":21148347,"url":"https://github.com/abidhasanrafi/oop-lab-assignment","last_synced_at":"2026-04-24T18:34:03.271Z","repository":{"id":256056093,"uuid":"854217014","full_name":"AbidHasanRafi/OOP-Lab-Assignment","owner":"AbidHasanRafi","description":"This repository contains code and solutions for the Object-Oriented Programming (OOP) lab assignments of the CSE 262 course.","archived":false,"fork":false,"pushed_at":"2024-09-08T18:19:01.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-31T06:54:14.193Z","etag":null,"topics":["cpp","java"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AbidHasanRafi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-08T17:24:34.000Z","updated_at":"2024-09-08T18:20:19.000Z","dependencies_parsed_at":"2024-09-08T19:27:08.500Z","dependency_job_id":"96cb964b-1967-43f0-badf-678184f985d4","html_url":"https://github.com/AbidHasanRafi/OOP-Lab-Assignment","commit_stats":null,"previous_names":["abidhasanrafi/oop-lab-assignment"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AbidHasanRafi/OOP-Lab-Assignment","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AbidHasanRafi%2FOOP-Lab-Assignment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AbidHasanRafi%2FOOP-Lab-Assignment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AbidHasanRafi%2FOOP-Lab-Assignment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AbidHasanRafi%2FOOP-Lab-Assignment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AbidHasanRafi","download_url":"https://codeload.github.com/AbidHasanRafi/OOP-Lab-Assignment/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AbidHasanRafi%2FOOP-Lab-Assignment/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32236731,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T13:21:15.438Z","status":"ssl_error","status_checked_at":"2026-04-24T13:21:15.005Z","response_time":64,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","java"],"created_at":"2024-11-20T09:24:29.470Z","updated_at":"2026-04-24T18:34:03.242Z","avatar_url":"https://github.com/AbidHasanRafi.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OOP Lab Assignment (CSE 262 - Object Oriented Programming Sessional)\n\n---\n\n#### Course Instructor: [Pankaj Bhowmik](https://hstu.ac.bd/teacher/pankaj)\n\nEach student should solve all the problems individually (group works will not be accepted). Plagiarism (copy and paste) is strictly prohibited.\n\n## Instructions:\n\nYou need to design an algorithm, flow chart and finally do implementation of the following problems using C++ programming language. Besides, write a report addressing the given instructions. You may use comments for each line/block in your program and show at least one sample test case (I/O) for your program. No static initialization will be allowed.\n\n## Task: Review and solve the lab works (not limited to):\n\n- [C++ Basics \u0026 Arithmetic Operations](#c-basics--arithmetic-operations)\n- [Conditional Statements](#control-flowconditional-ifelse-switchcase)\n- [Loop](#loop-forwhile)\n- [Recursion](#recursion)\n- [C++ Concepts](#c-concepts-not-limited-to)\n- [Java Basics](#java-basics)\n\n## C++ Basics \u0026 Arithmetic Operations\n\n1. Print your Name, SID and CGPA.\n2. Add two integer numbers.\n3. Subtract two integer numbers.\n4. Multiply two integer numbers.\n5. Divide two integer numbers.\n6. Determine the largest number among two integers.\n7. Find the area of a rectangle.\n8. Calculate the average of two numbers.\n9. Write a C++ program that illustrates the use (s) of reference variable.\n10. Write a C++ program that illustrates the use (s) of pointer data type.\n\n### Solutions:\n\n1. Print your Name, SID and CGPA.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nint main() {\n    string name;\n    int sid;\n    float cgpa;\n\n    cout \u003c\u003c \"Enter Name: \";\n    getline(cin, name);\n    cout \u003c\u003c \"Enter SID: \";\n    cin \u003e\u003e sid;\n    cout \u003c\u003c \"Enter CGPA: \";\n    cin \u003e\u003e cgpa;\n\n    cout \u003c\u003c \"Name: \" \u003c\u003c name \u003c\u003c \"\\nSID: \" \u003c\u003c sid \u003c\u003c \"\\nCGPA: \" \u003c\u003c cgpa \u003c\u003c endl;\n    return 0;\n}\n```\n\n2. Add two integer numbers.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nint main() {\n    int a, b;\n    cin \u003e\u003e a \u003e\u003e b;\n    cout \u003c\u003c \"Sum: \" \u003c\u003c a + b \u003c\u003c endl;\n    return 0;\n}\n```\n\n3. Subtract two integer numbers.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nint main() {\n    int a, b;\n    cin \u003e\u003e a \u003e\u003e b;\n    cout \u003c\u003c \"Difference: \" \u003c\u003c a - b \u003c\u003c endl;\n    return 0;\n}\n```\n\n4. Multiply two integer numbers.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nint main() {\n    int a, b;\n    cin \u003e\u003e a \u003e\u003e b;\n    cout \u003c\u003c \"Product: \" \u003c\u003c a * b \u003c\u003c endl;\n    return 0;\n}\n```\n\n5. Divide two integer numbers.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nint main() {\n    int a, b;\n    cin \u003e\u003e a \u003e\u003e b;\n    cout \u003c\u003c \"Quotient: \" \u003c\u003c a / b \u003c\u003c endl;\n    return 0;\n}\n```\n\n6. Determine the largest number among two integers.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nint main() {\n    int a, b;\n    cin \u003e\u003e a \u003e\u003e b;\n    cout \u003c\u003c \"Larger number: \" \u003c\u003c (a \u003e b ? a : b) \u003c\u003c endl;\n    return 0;\n}\n```\n\n7. Find the area of a rectangle.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nint main() {\n    int length, width;\n    cin \u003e\u003e length \u003e\u003e width;\n    cout \u003c\u003c \"Area of rectangle: \" \u003c\u003c length * width \u003c\u003c endl;\n    return 0;\n}\n```\n\n8. Calculate the average of two numbers.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nint main() {\n    float a, b;\n    cin \u003e\u003e a \u003e\u003e b;\n    cout \u003c\u003c \"Average: \" \u003c\u003c (a + b) / 2 \u003c\u003c endl;\n    return 0;\n}\n```\n\n9. Write a C++ program that illustrates the use (s) of reference variable.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nint main() {\n    int x = 10;\n    int \u0026ref = x;\n    ref = 20;\n\n    cout \u003c\u003c \"x: \" \u003c\u003c x \u003c\u003c endl;\n    cout \u003c\u003c \"ref: \" \u003c\u003c ref \u003c\u003c endl;\n\n    return 0;\n}\n```\n\n10. Write a C++ program that illustrates the use (s) of pointer data type.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nint main() {\n    int x = 10;\n    int *ptr = \u0026x;\n    *ptr = 20;\n\n    cout \u003c\u003c \"x: \" \u003c\u003c x \u003c\u003c endl;\n    cout \u003c\u003c \"Pointer points to: \" \u003c\u003c *ptr \u003c\u003c endl;\n\n    return 0;\n}\n```\n\n## Control flow/Conditional: (if...else, switch...case)\n\n1. Check if an integer number is positive or negative.\n2. Check if an integer number is even or odd.\n3. Check if an integer number is prime or not.\n4. Program to check whether a person is eligible to vote or not.\n5. Program to find the largest number of the three.\n6. Write a C++ program to check whether a number is divisible by 5.\n7. Write a C++ program to check Leap Year.\n8. Write a C++ program showing the use of switch case.\n\n### Solutions:\n\n1. Check if an integer number is positive or negative.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nint main() {\n    int num;\n    cin \u003e\u003e num;\n    if (num \u003e 0)\n        cout \u003c\u003c \"Positive\" \u003c\u003c endl;\n    else if (num \u003c 0)\n        cout \u003c\u003c \"Negative\" \u003c\u003c endl;\n    else\n        cout \u003c\u003c \"Zero\" \u003c\u003c endl;\n    return 0;\n}\n```\n\n2. Check if an integer number is even or odd.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nint main() {\n    int num;\n    cin \u003e\u003e num;\n    if (num % 2 == 0)\n        cout \u003c\u003c \"Even\" \u003c\u003c endl;\n    else\n        cout \u003c\u003c \"Odd\" \u003c\u003c endl;\n    return 0;\n}\n```\n\n3. Check if an integer number is prime or not.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nint main() {\n    int num;\n    cin \u003e\u003e num;\n    bool isPrime = true;\n\n    if (num \u003c= 1)\n        isPrime = false;\n    else {\n        for (int i = 2; i * i \u003c= num; ++i) {\n            if (num % i == 0) {\n                isPrime = false;\n                break;\n            }\n        }\n    }\n\n    if (isPrime)\n        cout \u003c\u003c \"Prime\" \u003c\u003c endl;\n    else\n        cout \u003c\u003c \"Not Prime\" \u003c\u003c endl;\n\n    return 0;\n}\n```\n\n4. Program to check whether a person is eligible to vote or not.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nint main() {\n    int age;\n    cin \u003e\u003e age;\n    if (age \u003e= 18)\n        cout \u003c\u003c \"Eligible to Vote\" \u003c\u003c endl;\n    else\n        cout \u003c\u003c \"Not Eligible to Vote\" \u003c\u003c endl;\n    return 0;\n}\n```\n\n5. Program to find the largest number of the three.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nint main() {\n    int a, b, c;\n    cin \u003e\u003e a \u003e\u003e b \u003e\u003e c;\n    if (a \u003e= b \u0026\u0026 a \u003e= c)\n        cout \u003c\u003c \"Largest number: \" \u003c\u003c a \u003c\u003c endl;\n    else if (b \u003e= a \u0026\u0026 b \u003e= c)\n        cout \u003c\u003c \"Largest number: \" \u003c\u003c b \u003c\u003c endl;\n    else\n        cout \u003c\u003c \"Largest number: \" \u003c\u003c c \u003c\u003c endl;\n    return 0;\n}\n```\n\n6. Write a C++ program to check whether a number is divisible by 5.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nint main() {\n    int num;\n    cin \u003e\u003e num;\n    if (num % 5 == 0)\n        cout \u003c\u003c \"Divisible by 5\" \u003c\u003c endl;\n    else\n        cout \u003c\u003c \"Not Divisible by 5\" \u003c\u003c endl;\n    return 0;\n}\n```\n\n7. Write a C++ program to check Leap Year.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nint main() {\n    int year;\n    cin \u003e\u003e year;\n    if ((year % 4 == 0 \u0026\u0026 year % 100 != 0) || (year % 400 == 0))\n        cout \u003c\u003c \"Leap Year\" \u003c\u003c endl;\n    else\n        cout \u003c\u003c \"Not a Leap Year\" \u003c\u003c endl;\n    return 0;\n}\n```\n\n8. Write a C++ program showing the use of switch case.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nint main() {\n    int day;\n    cin \u003e\u003e day;\n\n    switch (day) {\n        case 1: cout \u003c\u003c \"Monday\" \u003c\u003c endl; break;\n        case 2: cout \u003c\u003c \"Tuesday\" \u003c\u003c endl; break;\n        case 3: cout \u003c\u003c \"Wednesday\" \u003c\u003c endl; break;\n        case 4: cout \u003c\u003c \"Thursday\" \u003c\u003c endl; break;\n        case 5: cout \u003c\u003c \"Friday\" \u003c\u003c endl; break;\n        case 6: cout \u003c\u003c \"Saturday\" \u003c\u003c endl; break;\n        case 7: cout \u003c\u003c \"Sunday\" \u003c\u003c endl; break;\n        default: cout \u003c\u003c \"Invalid day\" \u003c\u003c endl; break;\n    }\n    return 0;\n}\n```\n\n## Loop: (for/while)\n\n1. Display the first 10 natural numbers.\n2. Calculate the sum of n integer numbers using loop.\n3. Print even/odd numbers from n natural numbers.\n4. Program to calculate the sum of even/odd numbers from n natural numbers.\n5. Calculate factorial of an integer number n using loop.\n6. Apply break and continue conditions in a loop.\n\n### Solutions:\n\n1. Display the first 10 natural numbers.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nint main() {\n    for (int i = 1; i \u003c= 10; ++i) {\n        cout \u003c\u003c i \u003c\u003c \" \";\n    }\n    cout \u003c\u003c endl;\n    return 0;\n}\n```\n\n2. Calculate the sum of n integer numbers using loop.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nint main() {\n    int n, sum = 0;\n    cin \u003e\u003e n;\n    for (int i = 1; i \u003c= n; ++i) {\n        sum += i;\n    }\n    cout \u003c\u003c \"Sum: \" \u003c\u003c sum \u003c\u003c endl;\n    return 0;\n}\n```\n\n3. Print even/odd numbers from n natural numbers.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nint main() {\n    int n;\n    cin \u003e\u003e n;\n    cout \u003c\u003c \"Even numbers: \";\n    for (int i = 1; i \u003c= n; ++i) {\n        if (i % 2 == 0) {\n            cout \u003c\u003c i \u003c\u003c \" \";\n        }\n    }\n    cout \u003c\u003c endl;\n\n    cout \u003c\u003c \"Odd numbers: \";\n    for (int i = 1; i \u003c= n; ++i) {\n        if (i % 2 != 0) {\n            cout \u003c\u003c i \u003c\u003c \" \";\n        }\n    }\n    cout \u003c\u003c endl;\n    return 0;\n}\n```\n\n4. Program to calculate the sum of even/odd numbers from n natural numbers.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nint main() {\n    int n, sumEven = 0, sumOdd = 0;\n    cin \u003e\u003e n;\n\n    for (int i = 1; i \u003c= n; ++i) {\n        if (i % 2 == 0) {\n            sumEven += i;\n        } else {\n            sumOdd += i;\n        }\n    }\n    cout \u003c\u003c \"Sum of even numbers: \" \u003c\u003c sumEven \u003c\u003c endl;\n    cout \u003c\u003c \"Sum of odd numbers: \" \u003c\u003c sumOdd \u003c\u003c endl;\n    return 0;\n}\n```\n\n5. Calculate factorial of an integer number n using loop.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nint main() {\n    int n, factorial = 1;\n    cin \u003e\u003e n;\n\n    for (int i = 1; i \u003c= n; ++i) {\n        factorial *= i;\n    }\n\n    cout \u003c\u003c \"Factorial: \" \u003c\u003c factorial \u003c\u003c endl;\n    return 0;\n}\n```\n\n6. Apply break and continue conditions in a loop.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nint main() {\n    for (int i = 1; i \u003c= 10; ++i) {\n        if (i == 5) {\n            continue;\n        }\n        if (i == 8) {\n            break;\n        }\n        cout \u003c\u003c i \u003c\u003c \" \";\n    }\n    cout \u003c\u003c endl;\n    return 0;\n}\n```\n\n## Recursion\n\n1. Calculate factorial of an integer number.\n2. Solve the tower of Hanoi problem.\n3. Find the Fibonacci sequence in a given range.\n4. Program to find the power of a number.\n\n### Solutions:\n\n1. Calculate factorial of an integer number.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nint factorial(int n) {\n    if (n \u003c= 1)\n        return 1;\n    return n * factorial(n - 1);\n}\n\nint main() {\n    int n;\n    cin \u003e\u003e n;\n    cout \u003c\u003c \"Factorial: \" \u003c\u003c factorial(n) \u003c\u003c endl;\n    return 0;\n}\n```\n\n2. Solve the tower of Hanoi problem.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nvoid towerOfHanoi(int n, char from, char to, char aux) {\n    if (n == 1) {\n        cout \u003c\u003c \"Move disk 1 from \" \u003c\u003c from \u003c\u003c \" to \" \u003c\u003c to \u003c\u003c endl;\n        return;\n    }\n    towerOfHanoi(n - 1, from, aux, to);\n    cout \u003c\u003c \"Move disk \" \u003c\u003c n \u003c\u003c \" from \" \u003c\u003c from \u003c\u003c \" to \" \u003c\u003c to \u003c\u003c endl;\n    towerOfHanoi(n - 1, aux, to, from);\n}\n\nint main() {\n    int n;\n    cin \u003e\u003e n;\n    towerOfHanoi(n, 'A', 'C', 'B');\n    return 0;\n}\n```\n\n3. Find the Fibonacci sequence in a given range.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nint fibonacci(int n) {\n    if (n \u003c= 1)\n        return n;\n    return fibonacci(n - 1) + fibonacci(n - 2);\n}\n\nint main() {\n    int range;\n    cin \u003e\u003e range;\n    for (int i = 0; i \u003c range; ++i) {\n        cout \u003c\u003c fibonacci(i) \u003c\u003c \" \";\n    }\n    cout \u003c\u003c endl;\n    return 0;\n}\n```\n\n4. Program to find the power of a number.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nint power(int base, int exp) {\n    if (exp == 0)\n        return 1;\n    return base * power(base, exp - 1);\n}\n\nint main() {\n    int base, exp;\n    cin \u003e\u003e base \u003e\u003e exp;\n    cout \u003c\u003c \"Power: \" \u003c\u003c power(base, exp) \u003c\u003c endl;\n    return 0;\n}\n```\n\n## C++ Concepts (not limited to)\n\n1. Write a C++ program that performs the basic I/O using the concepts of class and objects.\n2. Write a C++ program that handles the students' records using the concepts of class and objects.\n3. Write a C++ program that performs basic arithmetic operations using the concepts of class and objects.\n4. Write a C++ program that calculates the CGPA for students using the concepts of class and objects.\n5. Write a C++ program that illustrates function prototyping using the concepts of class and objects.\n6. Write a C++ program that shows function overloading using the concepts of class and objects.\n7. Write a C++ program that uses friend function using the concepts of class and objects.\n8. Write a C++ program that shows the use(s) of different access specifiers using the concepts of data hiding.\n9. Write a C++ program that illustrates the concepts of constructor and destructor.\n10. Write a C++ program that shows constructor overloading concept.\n11. Write a C++ program that illustrates the concepts of different inheritance(s) using class and objects.\n12. Write a C++ program that exemplifies the use(s) of abstract class using the concepts of inheritance.\n13. Write a C++ program that illustrates the concepts of run-time polymorphism using class and objects.\n14. Write a C++ program that illustrates the concepts of compile-time polymorphism using class and objects.\n15. Write a C++ program exemplifying the concept of exception handling.\n\n### Solutions:\n\n1. Write a C++ program that performs the basic I/O using the concepts of class and objects.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nclass Person {\npublic:\n    void input() {\n        cout \u003c\u003c \"Enter name: \";\n        cin \u003e\u003e name;\n        cout \u003c\u003c \"Enter age: \";\n        cin \u003e\u003e age;\n    }\n\n    void display() {\n        cout \u003c\u003c \"Name: \" \u003c\u003c name \u003c\u003c \"\\nAge: \" \u003c\u003c age \u003c\u003c endl;\n    }\n\nprivate:\n    string name;\n    int age;\n};\n\nint main() {\n    Person p;\n    p.input();\n    p.display();\n    return 0;\n}\n```\n\n2. Write a C++ program that handles the students' records using the concepts of class and objects.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nclass Student {\npublic:\n    void input() {\n        cout \u003c\u003c \"Enter student name: \";\n        cin \u003e\u003e name;\n        cout \u003c\u003c \"Enter student roll number: \";\n        cin \u003e\u003e rollNumber;\n    }\n\n    void display() {\n        cout \u003c\u003c \"Name: \" \u003c\u003c name \u003c\u003c \"\\nRoll Number: \" \u003c\u003c rollNumber \u003c\u003c endl;\n    }\n\nprivate:\n    string name;\n    int rollNumber;\n};\n\nint main() {\n    Student s;\n    s.input();\n    s.display();\n    return 0;\n}\n```\n\n3. Write a C++ program that performs basic arithmetic operations using the concepts of class and objects.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nclass Arithmetic {\npublic:\n    void setValues(int a, int b) {\n        x = a;\n        y = b;\n    }\n\n    void add() {\n        cout \u003c\u003c \"Sum: \" \u003c\u003c x + y \u003c\u003c endl;\n    }\n\n    void subtract() {\n        cout \u003c\u003c \"Difference: \" \u003c\u003c x - y \u003c\u003c endl;\n    }\n\n    void multiply() {\n        cout \u003c\u003c \"Product: \" \u003c\u003c x * y \u003c\u003c endl;\n    }\n\n    void divide() {\n        if (y != 0)\n            cout \u003c\u003c \"Quotient: \" \u003c\u003c x / y \u003c\u003c endl;\n        else\n            cout \u003c\u003c \"Division by zero error\" \u003c\u003c endl;\n    }\n\nprivate:\n    int x, y;\n};\n\nint main() {\n    Arithmetic a;\n    a.setValues(10, 5);\n    a.add();\n    a.subtract();\n    a.multiply();\n    a.divide();\n    return 0;\n}\n```\n\n4. Write a C++ program that calculates the CGPA for students using the concepts of class and objects.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nclass Student {\npublic:\n    void inputGrades() {\n        cout \u003c\u003c \"Enter the number of subjects: \";\n        int numSubjects;\n        cin \u003e\u003e numSubjects;\n        grades = new float[numSubjects];\n        totalSubjects = numSubjects;\n        float total = 0;\n        for (int i = 0; i \u003c numSubjects; ++i) {\n            cout \u003c\u003c \"Enter grade for subject \" \u003c\u003c i + 1 \u003c\u003c \": \";\n            cin \u003e\u003e grades[i];\n            total += grades[i];\n        }\n        cgpa = total / numSubjects;\n    }\n\n    void displayCGPA() {\n        cout \u003c\u003c \"CGPA: \" \u003c\u003c cgpa \u003c\u003c endl;\n    }\n\n    ~Student() {\n        delete[] grades;\n    }\n\nprivate:\n    float *grades;\n    int totalSubjects;\n    float cgpa;\n};\n\nint main() {\n    Student s;\n    s.inputGrades();\n    s.displayCGPA();\n    return 0;\n}\n```\n\n5. Write a C++ program that illustrates function prototyping using the concepts of class and objects.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nclass Math {\npublic:\n    int add(int, int);\n    int subtract(int, int);\n};\n\nint Math::add(int a, int b) {\n    return a + b;\n}\n\nint Math::subtract(int a, int b) {\n    return a - b;\n}\n\nint main() {\n    Math m;\n    cout \u003c\u003c \"Sum: \" \u003c\u003c m.add(10, 5) \u003c\u003c endl;\n    cout \u003c\u003c \"Difference: \" \u003c\u003c m.subtract(10, 5) \u003c\u003c endl;\n    return 0;\n}\n```\n\n6. Write a C++ program that shows function overloading using the concepts of class and objects.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nclass Display {\npublic:\n    void show(int i) {\n        cout \u003c\u003c \"Integer: \" \u003c\u003c i \u003c\u003c endl;\n    }\n\n    void show(double d) {\n        cout \u003c\u003c \"Double: \" \u003c\u003c d \u003c\u003c endl;\n    }\n\n    void show(string s) {\n        cout \u003c\u003c \"String: \" \u003c\u003c s \u003c\u003c endl;\n    }\n};\n\nint main() {\n    Display d;\n    d.show(10);\n    d.show(15.5);\n    d.show(\"Hello\");\n    return 0;\n}\n```\n\n7. Write a C++ program that uses friend function using the concepts of class and objects.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nclass Box {\npublic:\n    Box(int l, int w) : length(l), width(w) {}\n    friend void displayArea(Box b);\n\nprivate:\n    int length;\n    int width;\n};\n\nvoid displayArea(Box b) {\n    cout \u003c\u003c \"Area: \" \u003c\u003c b.length * b.width \u003c\u003c endl;\n}\n\nint main() {\n    Box b(10, 5);\n    displayArea(b);\n    return 0;\n}\n```\n\n8. Write a C++ program that shows the use(s) of different access specifiers using the concepts of data hiding.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nclass MyClass {\npublic:\n    int publicVar;\n    void publicMethod() {\n        cout \u003c\u003c \"Public Method\" \u003c\u003c endl;\n    }\n\nprivate:\n    int privateVar;\n    void privateMethod() {\n        cout \u003c\u003c \"Private Method\" \u003c\u003c endl;\n    }\n\nprotected:\n    int protectedVar;\n    void protectedMethod() {\n        cout \u003c\u003c \"Protected Method\" \u003c\u003c endl;\n    }\n};\n\nint main() {\n    MyClass obj;\n    obj.publicVar = 10;\n    obj.publicMethod();\n\n    return 0;\n}\n```\n\n9. Write a C++ program that illustrates the concepts of constructor and destructor.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nclass MyClass {\npublic:\n    MyClass() {\n        cout \u003c\u003c \"Constructor called\" \u003c\u003c endl;\n    }\n\n    ~MyClass() {\n        cout \u003c\u003c \"Destructor called\" \u003c\u003c endl;\n    }\n};\n\nint main() {\n    MyClass obj;\n    return 0;\n}\n```\n\n10. Write a C++ program that shows constructor overloading concept.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nclass MyClass {\npublic:\n    MyClass() {\n        cout \u003c\u003c \"Default Constructor\" \u003c\u003c endl;\n    }\n\n    MyClass(int a) {\n        cout \u003c\u003c \"Parameterized Constructor with value: \" \u003c\u003c a \u003c\u003c endl;\n    }\n};\n\nint main() {\n    MyClass obj1;\n    MyClass obj2(10);\n    return 0;\n}\n```\n\n11. Write a C++ program that illustrates the concepts of different inheritance(s) using class and objects.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nclass Base {\npublic:\n    void baseMethod() {\n        cout \u003c\u003c \"Base class method\" \u003c\u003c endl;\n    }\n};\n\nclass Derived : public Base {\npublic:\n    void derivedMethod() {\n        cout \u003c\u003c \"Derived class method\" \u003c\u003c endl;\n    }\n};\n\nclass ProtectedDerived : protected Base {\npublic:\n    void protectedDerivedMethod() {\n        cout \u003c\u003c \"Protected Derived class method\" \u003c\u003c endl;\n    }\n};\n\nclass PrivateDerived : private Base {\npublic:\n    void privateDerivedMethod() {\n        cout \u003c\u003c \"Private Derived class method\" \u003c\u003c endl;\n    }\n};\n\nint main() {\n    Derived d;\n    d.baseMethod();\n    d.derivedMethod();\n\n    ProtectedDerived pd;\n    pd.protectedDerivedMethod();\n\n    PrivateDerived pvt;\n    pvt.privateDerivedMethod();\n\n    return 0;\n}\n```\n\n12. Write a C++ program that exemplifies the use(s) of abstract class using the concepts of inheritance.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nclass AbstractBase {\npublic:\n    virtual void show() = 0;\n};\n\nclass Derived : public AbstractBase {\npublic:\n    void show() override {\n        cout \u003c\u003c \"Derived class implementation of abstract method\" \u003c\u003c endl;\n    }\n};\n\nint main() {\n    Derived d;\n    d.show();\n    return 0;\n}\n```\n\n13. Write a C++ program that illustrates the concepts of run-time polymorphism using class and objects.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nclass Base {\npublic:\n    virtual void display() {\n        cout \u003c\u003c \"Base class display\" \u003c\u003c endl;\n    }\n};\n\nclass Derived : public Base {\npublic:\n    void display() override {\n        cout \u003c\u003c \"Derived class display\" \u003c\u003c endl;\n    }\n};\n\nint main() {\n    Base *bptr;\n    Derived d;\n    bptr = \u0026d;\n    bptr-\u003edisplay();\n    return 0;\n}\n```\n\n14. Write a C++ program that illustrates the concepts of compile-time polymorphism using class and objects.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nclass Print {\npublic:\n    void show(int i) {\n        cout \u003c\u003c \"Integer: \" \u003c\u003c i \u003c\u003c endl;\n    }\n\n    void show(double d) {\n        cout \u003c\u003c \"Double: \" \u003c\u003c d \u003c\u003c endl;\n    }\n\n    void show(string s) {\n        cout \u003c\u003c \"String: \" \u003c\u003c s \u003c\u003c endl;\n    }\n};\n\nint main() {\n    Print p;\n    p.show(10);\n    p.show(15.5);\n    p.show(\"Hello\");\n    return 0;\n}\n```\n\n15. Write a C++ program exemplifying the concept of exception handling.\n\n```cpp\n#include \u003ciostream\u003e\nusing namespace std;\n\nint main() {\n    int a, b;\n    cout \u003c\u003c \"Enter two integers: \";\n    cin \u003e\u003e a \u003e\u003e b;\n\n    try {\n        if (b == 0) {\n            throw \"Division by zero!\";\n        }\n        cout \u003c\u003c \"Result: \" \u003c\u003c a / b \u003c\u003c endl;\n    } catch (const char* msg) {\n        cerr \u003c\u003c \"Error: \" \u003c\u003c msg \u003c\u003c endl;\n    }\n\n    return 0;\n}\n```\n\n## Java Basics\n\n1. Write a java program that performs the basic I/O operations.\n2. Write a java program that performs the basic arithmetic operations.\n3. Write a java program that performs the basic conditional (if...else) operations.\n\n### Solutions:\n\n1. Write a java program that performs the basic I/O operations.\n\n```java\nimport java.util.Scanner;\n\npublic class BasicIO {\n    public static void main(String[] args) {\n        Scanner scanner = new Scanner(System.in);\n\n        System.out.print(\"Enter your name: \");\n        String name = scanner.nextLine();\n\n        System.out.print(\"Enter your age: \");\n        int age = scanner.nextInt();\n\n        System.out.println(\"Name: \" + name);\n        System.out.println(\"Age: \" + age);\n\n        scanner.close();\n    }\n}\n```\n\n2. Write a java program that performs the basic arithmetic operations.\n\n```java\nimport java.util.Scanner;\n\npublic class BasicArithmetic {\n    public static void main(String[] args) {\n        Scanner scanner = new Scanner(System.in);\n\n        System.out.print(\"Enter first number: \");\n        int num1 = scanner.nextInt();\n\n        System.out.print(\"Enter second number: \");\n        int num2 = scanner.nextInt();\n\n        System.out.println(\"Sum: \" + (num1 + num2));\n        System.out.println(\"Difference: \" + (num1 - num2));\n        System.out.println(\"Product: \" + (num1 * num2));\n        System.out.println(\"Quotient: \" + (num1 / num2));\n\n        scanner.close();\n    }\n}\n```\n\n3. Write a java program that performs the basic conditional (if...else) operations.\n\n```java\nimport java.util.Scanner;\n\npublic class BasicConditional {\n    public static void main(String[] args) {\n        Scanner scanner = new Scanner(System.in);\n\n        System.out.print(\"Enter a number: \");\n        int number = scanner.nextInt();\n\n        if (number \u003e 0) {\n            System.out.println(\"The number is positive.\");\n        } else if (number \u003c 0) {\n            System.out.println(\"The number is negative.\");\n        } else {\n            System.out.println(\"The number is zero.\");\n        }\n\n        scanner.close();\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabidhasanrafi%2Foop-lab-assignment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabidhasanrafi%2Foop-lab-assignment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabidhasanrafi%2Foop-lab-assignment/lists"}