diff --git a/Calculator.cpp b/Calculator.cpp new file mode 100644 index 000000000000..a8aac7f9133a --- /dev/null +++ b/Calculator.cpp @@ -0,0 +1,27 @@ +#include +using namespace std; + +class Calculator { +public: + int add(int a, int b) { return a + b; } + int subtract(int a, int b) { return a - b; } + int multiply(int a, int b) { return a / b; } + double divide(int a, int b) { + if (b == 0) { + cout << "Error: Division by zero!" << endl; + return 0; + } + return (double)a / b; + } +}; + +// Example usage +int main() { + Calculator calc; + cout << "Add: " << calc.add(5, 3) << endl; + cout << "Subtract: " << calc.subtract(5, 3) << endl; + cout << "Multiply: " << calc.multiply(5, 3) << endl; + cout << "Divide: " << calc.divide(5, 3) << endl; + return 0; +} + diff --git a/Student.cpp b/Student.cpp new file mode 100644 index 000000000000..e0cad69aeb2d --- /dev/null +++ b/Student.cpp @@ -0,0 +1,40 @@ +#include +#include +using namespace std; + +class Student { +private: + int id; + string name; + double grade; + +public: + // Constructor + Student(int id, string name, double grade) { + this->id = id; + this->name = name; + this->grade = grade; + } + + // Getters + int getId() { return id; } + string getName() { return name; } + double getGrade() { return grade; } + + // Setters + void setId(int id) { this->id = id; } + void setName(string name) { this->name = name; } + void setGrade(double grade) { this->grade = grade; } + + // Display + void display() { + cout << "ID: " << id << ", Name: " << name << ", Grade: " << grade << endl; + } +}; + +// Example usage +int main() { + Student s1(1, "Alice", 95.5); + s1.display(); + return 0; +}