githubEdit

CSE224 / C++ Lab

Syllabus

Resources

chevron-rightEXPT 1 - Classes & Objectshashtag

Write a program that uses a class where the member functions are defined inside a class.

#include <iostream>
using namespace std;

// Define the class
class Calculator {
public:
    // Member function to add two numbers
    int add(int a, int b) {
        return a + b;
    }

    // Member function to subtract two numbers
    int subtract(int a, int b) {
        return a - b;
    }

    // Member function to multiply two numbers
    int multiply(int a, int b) {
        return a * b;
    }

    // Member function to divide two numbers
    double divide(int a, int b) {
        if (b != 0) {
            return static_cast<double>(a) / b;
        } else {
            cout << "Error: Division by zero!" << endl;
            return 0;
        }
    }
};

int main() {
    Calculator calc;

    // Get input from the user
    int num1, num2;
    cout << "Enter two numbers: ";
    cin >> num1 >> num2;

    // Perform operations
    cout << "Addition: " << calc.add(num1, num2) << endl;
    cout << "Subtraction: " << calc.subtract(num1, num2) << endl;
    cout << "Multiplication: " << calc.multiply(num1, num2) << endl;
    cout << "Division: " << calc.divide(num1, num2) << endl;

    return 0;
}
chevron-rightEXPT 2 - Classes & Objectshashtag

Write a program that uses a class where the member functions are defined outside a class.

#include <iostream>
using namespace std;

// Define the class
class Calculator {
public:
    // Member functions declared inside the class
    int add(int a, int b);
    int subtract(int a, int b);
    int multiply(int a, int b);
    double divide(int a, int b);
};

// Define the member functions outside the class
int Calculator::add(int a, int b) {
    return a + b;
}

int Calculator::subtract(int a, int b) {
    return a - b;
}

int Calculator::multiply(int a, int b) {
    return a * b;
}

double Calculator::divide(int a, int b) {
    if (b != 0) {
        return static_cast<double>(a) / b;
    } else {
        cout << "Error: Division by zero!" << endl;
        return 0;
    }
}

int main() {
    Calculator calc;

    // Get input from the user
    int num1, num2;
    cout << "Enter two numbers: ";
    cin >> num1 >> num2;

    // Perform operations
    cout << "Addition: " << calc.add(num1, num2) << endl;
    cout << "Subtraction: " << calc.subtract(num1, num2) << endl;
    cout << "Multiplication: " << calc.multiply(num1, num2) << endl;
    cout << "Division: " << calc.divide(num1, num2) << endl;

    return 0;
}
chevron-rightEXPT 3 - Classes & Objectshashtag

Write a Program to Demonstrate Inline functions.

#include <iostream>
using namespace std;

// Define a class to demonstrate inline functions
class MathOperations {
public:
    // Inline function to calculate the square of a number
    inline int square(int num) {
        return num * num;
    }

    // Inline function to calculate the cube of a number
    inline int cube(int num) {
        return num * num * num;
    }
};

int main() {
    MathOperations math;

    // Get input from the user
    int number;
    cout << "Enter a number: ";
    cin >> number;

    // Demonstrate the use of inline functions
    cout << "Square of " << number << " is: " << math.square(number) << endl;
    cout << "Cube of " << number << " is: " << math.cube(number) << endl;

    return 0;
}
chevron-rightEXPT 4 - Classes & Objectshashtag

Write a Program to Demonstrate Friend function, classes and this pointer.

chevron-rightEXPT 5 - Constructor & Destructorhashtag

Write a program to demonstrate the use of zero argument and parameterized constructors.

chevron-rightEXPT 6 - Operator Overloadinghashtag

Write a program to demonstrate the overloading of increment and decrement operators.

chevron-rightEXPT 7 - Inheritancehashtag

Write a program to demonstrate the single inheritance.

chevron-rightEXPT 8 - Inheritancehashtag

Write a program to demonstrate the multiple inheritance.

chevron-rightEXPT 9 - Inheritancehashtag

Write a Program to demonstrate use of protected members, public & private protected classes, multilevel inheritance etc.

chevron-rightEXPT 10 - Polymorphismhashtag

Write a program to demonstrate the runtime polymorphism.

chevron-rightEXPT 11 - Exception Handlinghashtag

Write a program to demonstrate the exception handling.

chevron-rightEXPT 12 - Templates & Generic Programminghashtag

Write a program to demonstrate the use of function template.

chevron-rightEXPT 13 - Templates & Generic Programminghashtag

Write a program to demonstrate the use of class template.

chevron-rightEXPT 14 - File Handlinghashtag

Write a Program to Show how file management is done in C++.

Assignment Questions

[⤓] [PDF] Assignment-CSE224-Btecharrow-up-right


Get Credited for sharing your Knowledge Source with your Peers

Last updated