Решение на упр.02 задача 1 от Владимир Барев
Резултати
- 4 точки от тестове
- 0 бонус точки
- 4 точки общо
- 0 успешни тест(а)
- 0 неуспешни тест(а)
Код
/*
#[derive (Debug)]
#[derive (Clone)]
struct SensorData {
temperature: f64,
radiation_level: u32
}
#[derive (Debug)]
#[derive (Clone)]
struct Probe {
name: String,
battery_percentage: u8,
last_reading: SensorData,
status: String
}
fn create_sensor_data(temperature: f64, radiation_level: u32) -> SensorData {
SensorData {
temperature,
radiation_level
}
}
fn create_probe(name: &str, battery_percentage: u8, sensor_data: SensorData) -> Probe {
Probe {
name: name.to_string(),
battery_percentage,
last_reading: sensor_data,
status: String::from("Active")
}
}
fn diagnostic_check(probe: &Probe) {
if probe.battery_percentage < 20 {
println!("Warning: {} has low battery!", probe.name);
} else {
println!("{:?}", probe);
}
}
fn recharge_probe(probe: &mut Probe, amount: u8) {
if probe.battery_percentage + amount > 100 {
probe.battery_percentage = 100;
} else {
probe.battery_percentage += amount;
}
}
fn update_status(probe: &mut Probe, new_status: &str) {
probe.status = new_status.to_string();
}
fn analyze_critical_sensor(sensor: SensorData) {
if sensor.temperature > 100.0 || sensor.radiation_level > 100 {
println!("Critical sensor reading detected: {:?}", sensor);
}
}
fn main() {
println!("Hello, world!");
let sensor_data = create_sensor_data(75.0, 50);
let mut probe1 = create_probe("Voyager 1", 15, sensor_data.clone());
diagnostic_check(&probe1);
recharge_probe(&mut probe1, 90);
update_status(&mut probe1, "Exploring");
diagnostic_check(&probe1);
let reading:SensorData = probe1.last_reading;
analyze_critical_sensor(reading);
// diagnostic_check(&probe1);
}
*/
