0% found this document useful (0 votes)
11 views

Object Oriented Programming Assignment-Sheikh Hasiba -202411068011 (1)

IPE

Uploaded by

khratul320
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Object Oriented Programming Assignment-Sheikh Hasiba -202411068011 (1)

IPE

Uploaded by

khratul320
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

UML :1-Loan

Uml Code 1

#include <bits/stdc++.h>

using namespace std;

class Loan {

private:

double annualInterestRate;

int numberOfYears;

double loanAmount;

string loanDate;

public:

// A subroutine designed to create an object in a particular class.

Loan() : annualInterestRate(0), numberOfYears(0), loanAmount(0), loanDate("") {}

// Set values for loan

void setValue(double rate, int years, double amount) {

annualInterestRate = rate;

numberOfYears = years;

loanAmount = amount;

// Get methods

double getAnnualInterestRate() const {


return annualInterestRate;

int getNumberOfYears() const {

return numberOfYears;

double getLoanAmount() const {

return loanAmount;

string getLoanDate() const {

return loanDate;

// Set methods

void setAnnualInterestRate(double rate) {

annualInterestRate = rate;

void setNumberOfYears(int years) {

numberOfYears = years;

void setLoanAmount(double amount) {

loanAmount = amount;

void setLoanDate(string date) {

loanDate = date;

// Function to calculate monthly payment


double getMonthlyPayment() const {

double monthlyInterestRate = annualInterestRate / 12 / 100;

int numberOfMonths = numberOfYears * 12;

return loanAmount * monthlyInterestRate / (1 - pow(1 + monthlyInterestRate, -numberOfMonths));

// Function to calculate total payment

double getTotalPayment() const {

return getMonthlyPayment() * numberOfYears * 12;

};

int main() {

Loan myLoan;

myLoan.setValue(5.0, 10, 10000); // 5% interest, 10 years, $10,000 loan

cout << "Loan Details:" << endl;

cout << "Annual Interest Rate: " << myLoan.getAnnualInterestRate() << "%" << endl;

cout << "Number of Years: " << myLoan.getNumberOfYears() << endl;

cout << "Loan Amount: $" << myLoan.getLoanAmount() << endl;

cout << "Monthly Payment: $" << myLoan.getMonthlyPayment() << endl;

cout << "Total Payment: $" << myLoan.getTotalPayment() << endl;

return 0; }

UML:2-BMI

Uml Code 2
#include <bits/stdc++.h>

using namespace std;

class BMI {

private:

string name;

int age;

double weight; // in kilograms

double height; // in meters

public:

// Constructor

BMI() : name(""), age(0), weight(0), height(0) {}

// Set values for BMI

void setValue(string personName, int personAge, double personWeight, double personHeight) {

name = personName;

age = personAge;

weight = personWeight;

height = personHeight;

// Function to calculate BMI

double getBMI() const {


return weight / (height * height); // BMI = weight (kg) / height^2 (m^2)

// Function to get the status based on BMI

string getStatus() const {

double bmi = getBMI();

if (bmi < 18.5)

return "Underweight";

else if (bmi < 24.9)

return "Normal weight";

else if (bmi < 29.9)

return "Overweight";

else

return "Obese";

};

int main() {

BMI person;

person.setValue("John Doe", 25, 70.0, 1.75); // Name, Age, Weight (kg), Height (m)

cout << "BMI Details for " << person.getStatus() << ":" << endl;

cout << "BMI: " << person.getBMI() << endl;

cout << "Status: " << person.getStatus() << endl;


return 0;

UML:3-GeometricObject

Uml 3

#include <bits/stdc++.h>

using namespace std;

class GeometricObject {

private:

string color;

bool filled;

string dateCreated;

public:

// A Subroutine Designed to create an object in a particular class.

GeometricObject() : color("white"), filled(false), dateCreated("2024-10-25") {}

// Set values for color and filled status

void setValue(string objColor, bool isFilled) {

color = objColor;

filled = isFilled;

// Get color

string getColor() const {

return color;

// Check if the object is filled


bool isFilled() const {

return filled;

// Get the creation date

string getDateCreated() const {

return dateCreated;

// Set color

void setColor(string newColor) {

color = newColor;

// Set filled status

void setFilled(bool fillStatus) {

filled = fillStatus;

// Placeholder functions for area and perimeter

virtual double getArea() const {

return 0.0;

virtual double getPerimeter() const {

return 0.0;

};

// Derived class for Rectangle

class Rectangle : public GeometricObject {


private:

double width;

double height;

public:

// Constructor for Rectangle

Rectangle(double w, double h) : width(w), height(h) {}

// Override getArea() method for Rectangle

double getArea() const override {

return width * height;

// Override getPerimeter() method for Rectangle

double getPerimeter() const override {

return 2 * (width + height);

};

// Derived class for Circle

class Circle : public GeometricObject {

private:

double radius;

public:

// Constructor for Circle

Circle(double r) : radius(r) {}

// Override getArea() method for Circle

double getArea() const override {

return M_PI * radius * radius;


}

// Override getPerimeter() method for Circle

double getPerimeter() const override {

return 2 * M_PI * radius;

};

int main() {

// lets take width = 5, height = 10

Rectangle rect(5.0, 10.0);

rect.setValue("red", true);

cout << "Rectangle Details:" << endl;

cout << "Color: " << rect.getColor() << endl;

cout << "Filled: " << (rect.isFilled() ? "Yes" : "No") << endl;

cout << "Area: " << rect.getArea() << endl;

cout << "Perimeter: " << rect.getPerimeter() << endl;

cout << endl;

// Circle with radius = 7

Circle circle(7.0);

circle.setValue("blue", false);

cout << "Circle Details:" << endl;

cout << "Color: " << circle.getColor() << endl;

cout << "Filled: " << (circle.isFilled() ? "Yes" : "No") << endl;

cout << "Area: " << circle.getArea() << endl;

cout << "Perimeter: " << circle.getPerimeter() << endl;

return 0;
}

UML:4-Circle

UML 4

#include <bits/stdc++.h>

using namespace std;

class Circle {

private:

double radius;

public:

// Default constructor

Circle() : radius(0.0) {}

// Constructor with radius parameter

Circle(double r) : radius(r) {}

// Constructor with radius, color, and filled parameters

Circle(double r, string color, bool filled) : radius(r) {

// Color and filled are just placeholders; no need to store them for simplicity

// Getter for radius

double getRadius() const {


return radius;

// Setter for radius

void setRadius(double r) {

radius = r;

// Getter for diameter

double getDiameter() const {

return 2 * radius;

};

int main() {

Circle c1; // Default circle

Circle c2(5.0); // Circle with radius 5.0

Circle c3(7.0, "red", true); // Circle with radius 7.0, color red, filled

cout << "Radius of c2: " << c2.getRadius() << endl;

cout << "Diameter of c2: " << c2.getDiameter() << endl;

return 0;

UML-5-Rectangle
UML 5

#include <bits/stdc++.h>

using namespace std;

class Rectangle {

private:

double width;

double height;

public:

// Default constructor

Rectangle() : width(0.0), height(0.0) {}

// Constructor with width and height parameters

Rectangle(double w, double h) : width(w), height(h) {}

// Constructor with width, height, color, and filled parameters

Rectangle(double w, double h, string color, bool filled) : width(w), height(h) {

// Color and filled are placeholders; not stored for simplicity

// Getter for width

double getWidth() const {


return width;

// Setter for width

void setWidth(double w) {

width = w;

// Getter for height

double getHeight() const {

return height;

// Setter for height

void setHeight(double h) {

height = h;

};

int main() {

Rectangle r1; // Default rectangle

Rectangle r2(5.0, 10.0); // Rectangle with width 5.0 and height 10.0

Rectangle r3(7.0, 12.0, "blue", true); // Rectangle with width 7.0, height 12.0, color blue, filled

cout << "Width of r2: " << r2.getWidth() << endl;


cout << "Height of r2: " << r2.getHeight() << endl;

return 0;

You might also like