udemy-cpp excercise 1 solution

master
Tibor Bizjak 2023-07-13 18:59:42 +02:00
parent a95842850d
commit 53a06aa213
3 changed files with 85 additions and 0 deletions

View File

@ -4,3 +4,45 @@
#include "AdConstants.h"
#include "AdFunctions.h"
namespace Ad
{
namespace Utils
{
constexpr float kph_to_mps(const float kph)
{
return 0.2778 * kph;
}
} // namespace Ad::Utils
namespace Data
{
Types::Vehicle init_ego_vehicle()
{
Types::Vehicle ev =
{.id = Constants::EGO_VEHICLE_ID,
.lane = Types::Lane::Center,
.speed_mps = Utils::kph_to_mps(135),
.rel_distance_m = 0,
};
return ev;
}
} // namespace Ad::Data
namespace Visualize
{
void print_vehicle(const Types::Vehicle vehicle)
{
std::cout << "Vehicle " << vehicle.id << '\n';
std::cout << "speed : " << vehicle.speed_mps << " m/s\n";
std::cout << "distance : " << vehicle.rel_distance_m << " m\n";
}
} // namespace Ad::Visualize
} // namespace Ad

View File

@ -1,3 +1,22 @@
#pragma once
#include "AdTypes.h"
namespace Ad
{
namespace Utils
{
constexpr float kph_to_mps(const float kph);
} // namespace Ad::Utils
namespace Data
{
Types::Vehicle init_ego_vehicle();
} // namespace Ad::Data
namespace Visualize
{
void print_vehicle(const Types::Vehicle vehicle);
} // namespace Ad::Visualize
} // namespace Ad

View File

@ -3,3 +3,27 @@
#include <cstdint>
#include "AdConstants.h"
namespace Ad
{
namespace Types
{
enum class Lane
{
Unknown,
Left,
Center,
Right,
};
struct Vehicle
{
std::int32_t id;
Lane lane;
double speed_mps;
double rel_distance_m;
};
} // namespace Types
} // namespace Ad