saving . . . saved i want to know where to submit my assignmets has been deleted. i want to know where to submit my assignmets has been hidden .
i want to know where to submit my assignmets
Title
Question
where and when should i submit my assignments??

Advanced-Cpp Classes-And-Objects 07-08 min 50-60 sec 29-08-25, 11:16 a.m. Maithili@123

Answers:

#include <iostream>
using namespace std;

int main() {
    float radius, perimeter;
    const float pi = 3.14159;

    cout << "Enter the radius of the circle: ";
    cin >> radius;

    perimeter = 2 * pi * radius;

    cout << "The perimeter (circumference) of the circle is: " << perimeter;

    return 0;
}
22-03-26, 11:44 a.m. bhagyashri_4430


#include <iostream>
using namespace std;

class Division {
private:
    float num1, num2;
public:
    // Constructor
    Division(float a, float b) {
        num1 = a;
        num2 = b;
    }
    // Function to perform division
    void divide() {
        if (num2 == 0) {
            cout << "Error: Division by zero is not allowed." << endl;
        } else {
            float result = num1 / num2;
            cout << "Result of division: " << result << endl;
        }
    }
};
int main() {
    float a, b;

    cout << "Enter two numbers: ";
    cin >> a >> b;

    // Creating object and calling constructor
    Division d(a, b);

    // Calling divide function
    d.divide();

    return 0;
}
22-03-26, 11:50 a.m. bhagyashri_4430


#include <iostream>
using namespace std;

class Counter {
public:
    static int value;  // static variable

    // Function to decrement the variable
    void decrement() {
        value--;
    }

    // Function to display value
    void display() {
        cout << "Value: " << value << endl;
    }
};

// Initialize static variable
int Counter::value = 10;

int main() {
    Counter obj1, obj2;

    obj1.display();   // Initial value
    obj1.decrement(); // Decrement
    obj2.display();   // Updated value (shared)

    return 0;
}
22-03-26, 11:52 a.m. bhagyashri_4430


#include <iostream>
using namespace std;
class Shape {
public:
    // Square
    void area(float side) {
        cout << "Area of Square: " << side * side << endl;
    }
    void perimeter(float side, int) {  // dummy int for overloading
        cout << "Perimeter of Square: " << 4 * side << endl;
    }
    // Rectangle
    void area(float length, float breadth) {
        cout << "Area of Rectangle: " << length * breadth << endl;
    }
    void perimeter(float length, float breadth, int) {
        cout << "Perimeter of Rectangle: " << 2 * (length + breadth) << endl;
    }
    // Circle
    void area(double radius) {
        cout << "Area of Circle: " << 3.14159 * radius * radius << endl;
    }
    void perimeter(double radius, char) {  // dummy char for overloading
        cout << "Perimeter of Circle: " << 2 * 3.14159 * radius << endl;
    }
};
int main() {
    Shape s;
    // Square
    s.area(5);
    s.perimeter(5, 0);
    // Rectangle
    s.area(4, 6);
    s.perimeter(4, 6, 0);
    // Circle
    s.area(3.0);
    s.perimeter(3.0, 'a');
    return 0;
}
22-03-26, 11:57 a.m. bhagyashri_4430


#include <iostream>
using namespace std;

class Rectangle {
private:
    float length, breadth;

public:
    // Function to input values
    void getData() {
        cout << "Enter length and breadth: ";
        cin >> length >> breadth;
    }

    // Function to calculate area
    void area() {
        cout << "Area of rectangle: " << length * breadth << endl;
    }

    // Function to calculate perimeter
    void perimeter() {
        cout << "Perimeter of rectangle: " << 2 * (length + breadth) << endl;
    }
};

int main() {
    Rectangle r;

    r.getData();
    r.area();
    r.perimeter();

    return 0;
}
22-03-26, noon bhagyashri_4430



#include <iostream>
using namespace std;

class Area {
public:
    // Square
    void calculateArea(float side) {
        cout << "Area of Square: " << side * side << endl;
    }

    // Rectangle
    void calculateArea(float length, float breadth) {
        cout << "Area of Rectangle: " << length * breadth << endl;
    }

    // Circle
    void calculateArea(double radius) {
        cout << "Area of Circle: " << 3.14159 * radius * radius << endl;
    }
};

int main() {
    Area a;

    a.calculateArea(5);        // Square
    a.calculateArea(4, 6);     // Rectangle
    a.calculateArea(3.0);      // Circle

    return 0;
}

22-03-26, 12:02 p.m. bhagyashri_4430


#include <iostream>
using namespace std;
// Base class
class Shape {
public:
    virtual void perimeter() {
        cout << "Calculating perimeter..." << endl;
    }
};
// Derived class for Rectangle
class Rectangle : public Shape {
private:
    float length, breadth;
public:
    Rectangle(float l, float b) {
        length = l;
        breadth = b;
    }
    void perimeter() {
        cout << "Perimeter of Rectangle: " << 2 * (length + breadth) << endl;
    }
};
// Derived class for Square
class Square : public Shape {
private:
    float side;
public:
    Square(float s) {
        side = s;
    }
    void perimeter() {
        cout << "Perimeter of Square: " << 4 * side << endl;
    }
};
// Derived class for Triangle
class Triangle : public Shape {
private:
    float a, b, c;
public:
    Triangle(float x, float y, float z) {
        a = x;
        b = y;
        c = z;
    }
    void perimeter() {
        cout << "Perimeter of Triangle: " << a + b + c << endl;
    }
};
int main() {
    Shape* s;

    Rectangle r(4, 5);
    Square sq(3);
    Triangle t(3, 4, 5);

    s = &r;
    s->perimeter();

    s = &sq;
    s->perimeter();

    s = &t;
    s->perimeter();

    return 0;
}
22-03-26, 12:05 p.m. bhagyashri_4430


#include <iostream>
using namespace std;

// Abstract base class
class Student {
protected:
    string name;
    int roll_no;

public:
    // Pure virtual function
    virtual void Info() = 0;
};

// Derived class Marks
class Marks : public Student {
protected:
    float m1, m2, m3;

public:
    void Info() {
        cout << "Enter Name: ";
        cin >> name;
        cout << "Enter Roll Number: ";
        cin >> roll_no;

        cout << "Enter marks of 3 subjects: ";
        cin >> m1 >> m2 >> m3;
    }

    float getMarksTotal() {
        return m1 + m2 + m3;
    }
};

// Derived class Sports
class Sports : public Student {
protected:
    float sportsMarks;

public:
    void Info() {
        cout << "Enter Sports Marks: ";
        cin >> sportsMarks;
    }

    float getSportsMarks() {
        return sportsMarks;
    }
};

// Derived class Result (Multiple Inheritance)
class Result : public Marks, public Sports {
public:
    void display() {
        float total = getMarksTotal() + getSportsMarks();

        cout << "\n--- Student Result ---" << endl;
        cout << "Name: " << name << endl;
        cout << "Roll Number: " << roll_no << endl;
        cout << "Total Marks: " << total << endl;
    }
};

int main() {
    Result r;

    r.Marks::Info();   // Input name, roll no, subject marks
    r.Sports::Info();  // Input sports marks

    r.display();

    return 0;
}
22-03-26, 12:08 p.m. bhagyashri_4430


#include <iostream>
using namespace std;

int main() {
    int num;

    cout << "Enter a number: ";
    cin >> num;

    int square = num * num;
    int cube = num * num * num;

    cout << "Square of the number: " << square << endl;
    cout << "Cube of the number: " << cube << endl;

    return 0;
}
22-03-26, 12:09 p.m. bhagyashri_4430


#include <iostream>
#include <stdexcept>  // For standard exceptions
using namespace std;

int main() {
    int age;

    cout << "Enter employee age: ";
    cin >> age;

    try {
        if (age < 15) {
            throw runtime_error("Age is less than 15. Invalid age!");
        }
        cout << "Employee age: " << age << endl;
    }
    catch (runtime_error &e) {
        cout << "Exception caught: " << e.what() << endl;
    }

    return 0;
}
22-03-26, 12:11 p.m. bhagyashri_4430


Log-in to answer to this question.