Uml
Uml
Emp id:
Q1.
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";
return 0;
}
OUTPUT
Q2.
Code:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
void deployAirbags() {
cout << "Deploying " << airbagCount << " airbags" << endl;
}
void checkSensors() {
// Simulate sensor data
sensorData = rand() % 100 / 10.0;
cout << "Airbag sensor data: " << sensorData << endl;
}
};
void applyABS() {
cout << "Applying ABS control" << endl;
}
void monitorWheelSpeed() {
wheelSpeed = rand() % 100;
cout << "Wheel speed: " << wheelSpeed << " km/h" << endl;
}
};
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;
}
};
ImmobilizerAndAccessControl() : isEngineLocked(true) {}
void lockEngine() {
isEngineLocked = true;
cout << "Engine is locked" << endl;
}
void unlockEngine() {
isEngineLocked = false;
cout << "Engine is unlocked" << endl;
}
void deploySafetyFeatures() {
airbagControl.checkSensors();
airbagControl.deployAirbags();
abs.monitorWheelSpeed();
abs.applyABS();
esc.checkTraction();
esc.maintainStability();
}
int main() {
VehicleSafetySystem myVehicle;
// 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