Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Calculator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <iostream>
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;
}

40 changes: 40 additions & 0 deletions Student.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <iostream>
#include <string>
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;
}