0% found this document useful (0 votes)
4 views11 pages

Uml

The document describes a class diagram and corresponding C++ code for a car system, detailing various components like Car, Gearbox, Engine, and safety systems such as Airbag Control Module and ABS. It outlines the relationships between classes and their functionalities, including methods for car movement and safety feature deployment. The code demonstrates object creation and interaction within the car system, showcasing how different components work together.

Uploaded by

sonuverma7606
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views11 pages

Uml

The document describes a class diagram and corresponding C++ code for a car system, detailing various components like Car, Gearbox, Engine, and safety systems such as Airbag Control Module and ABS. It outlines the relationships between classes and their functionalities, including methods for car movement and safety feature deployment. The code demonstrates object creation and interaction within the car system, showcasing how different components work together.

Uploaded by

sonuverma7606
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Name:

Emp id:

Q1.

The class diagram you've shared represents different components of a car


system, showing relationships between various classes such as Car, Gearbox,
Engine.

1. Car: The main class that holds all other components (Gearbox, Engine,
Body, Brake, Suspension, and Wheel).
2. Gearbox: Manages gear shifting and contains a type (GearboxType).
3. Engine: Handles starting, accelerating, and braking the car.
4. Body: Contains the number of doors.
5. Brake: Identifies the type of brake.
6. Suspension: Represents suspension properties.
7. Wheel: Associated with Tire and has properties like diameter.

Code:
#include <iostream>
#include <string>
using namespace std;

// GearboxType Class
class GearboxType {
public:
string name;
string remarks;
};

// Gearbox Class
class Gearbox {
public:
float gearRatio;
int currentGear;
void shiftUp() {
cout << "Shifting up" << endl;
currentGear++;
}

void shiftDown() {
cout << "Shifting down" << endl;
currentGear--;
}

GearboxType gearboxType;
};

// Engine Class
class Engine {
public:
float capacity;
int numberOfCylinders;

void start() {
cout << "Engine started" << endl;
}

void brake() {
cout << "Engine braking" << endl;
}

void accelerate() {
cout << "Engine accelerating" << endl;
}
};
// Body Class
class Body {
public:
int numberOfDoors;
};

// Brake Class
class Brake {
public:
string type;
};

// Suspension Class
class Suspension {
public:
float springRate;
};

// Tire Class
class Tire {
public:
float width;
float airPressure;
};

// Wheel Class
class Wheel {
public:
float diameter;
Tire tire;
};

// Car Class
class Car {
public:
string registrationNum;
int year;
string ownerName;

void moveForward() {
cout << "Car moving forward" << endl;
}

void moveBackward() {
cout << "Car moving backward" << endl;
}

void turnRight() {
cout << "Car turning right" << endl;
}

void turnLeft() {
cout << "Car turning left" << endl;
}

Gearbox gearbox;
Engine engine;
Body body;
Brake brake;
Suspension suspension;
Wheel wheels[4]; // A car has 4 wheels
};

int main() {
// Creating a car object
Car myCar;
myCar.registrationNum = "ABC123";
myCar.year = 2022;
myCar.ownerName = "John Doe";

// Setting up the car's properties


myCar.gearbox.gearRatio = 5.0;
myCar.engine.capacity = 2.0;
myCar.body.numberOfDoors = 4;
myCar.wheels[0].diameter = 16.5;

// Simulating car functions


myCar.engine.start();
myCar.moveForward();
myCar.gearbox.shiftUp();
myCar.turnLeft();
myCar.moveBackward();
myCar.engine.brake();

return 0;
}

OUTPUT
Q2.

Code:
#include <iostream>
#include <vector>
#include <string>
using namespace std;

// Airbag Control Module Class


class AirbagControlModule {
public:
int airbagCount;
float sensorData;

AirbagControlModule(int count) : airbagCount(count), sensorData(0.0) {}

void deployAirbags() {
cout << "Deploying " << airbagCount << " airbags" << endl;
}

void checkSensors() {
// Simulate sensor data
sensorData = rand() % 100 / 10.0;
cout << "Airbag sensor data: " << sensorData << endl;
}
};

// ABS (Anti-lock Braking System) Class


class ABS {
public:
float wheelSpeed;
float brakePressure;

ABS() : wheelSpeed(0.0), brakePressure(0.0) {}

void applyABS() {
cout << "Applying ABS control" << endl;
}

void monitorWheelSpeed() {
wheelSpeed = rand() % 100;
cout << "Wheel speed: " << wheelSpeed << " km/h" << endl;
}
};

// ESC (Electronic Stability Control) Class


class ESC {
public:
float yawRate;
float lateralAcceleration;

ESC() : yawRate(0.0), lateralAcceleration(0.0) {}

void maintainStability() {
cout << "Maintaining vehicle stability" << endl;
}

void checkTraction() {
yawRate = rand() % 20 / 2.0;
lateralAcceleration = rand() % 10 / 1.5;
cout << "Yaw rate: " << yawRate << ", Lateral Acceleration: " <<
lateralAcceleration << endl;
}
};

// Immobilizer and Access Control System Class


class ImmobilizerAndAccessControl {
public:
bool isEngineLocked;
vector<string> authorizedKeys;

ImmobilizerAndAccessControl() : isEngineLocked(true) {}

void lockEngine() {
isEngineLocked = true;
cout << "Engine is locked" << endl;
}

void unlockEngine() {
isEngineLocked = false;
cout << "Engine is unlocked" << endl;
}

bool verifyKey(string key) {


for (const string& authKey : authorizedKeys) {
if (authKey == key) {
return true;
}
}
return false;
}

void addAuthorizedKey(string key) {


authorizedKeys.push_back(key);
}
};

// Vehicle Safety System Class


class VehicleSafetySystem {
public:
AirbagControlModule airbagControl;
ABS abs;
ESC esc;
ImmobilizerAndAccessControl immobilizer;

VehicleSafetySystem() : airbagControl(6) {} // Example: 6 airbags

void deploySafetyFeatures() {
airbagControl.checkSensors();
airbagControl.deployAirbags();
abs.monitorWheelSpeed();
abs.applyABS();
esc.checkTraction();
esc.maintainStability();
}

void controlImmobilizer(string key) {


if (immobilizer.verifyKey(key)) {
immobilizer.unlockEngine();
} else {
immobilizer.lockEngine();
}
}
};

int main() {
VehicleSafetySystem myVehicle;

// Simulate safety features


myVehicle.deploySafetyFeatures();

// Immobilizer test
myVehicle.immobilizer.addAuthorizedKey("key123");
string key = "key123";
myVehicle.controlImmobilizer(key); // This should unlock the engine

key = "wrong_key";
myVehicle.controlImmobilizer(key); // This should lock the engine

return 0;
}
OUTPUT

You might also like