
- •Coursework thesis
- •Task for coursework
- •Abstract
- •List of abbreviations
- •Introduction
- •Domain analysis
- •Designing the system
- •Interface classes iSerializible, iEmissionable and iCloneable
- •Class for transport information
- •Bus, Plane, Train classes
- •Data storing. Transport schedule class
- •Array of pointers. Container class.
- •User Interface Design
- •Software implementation
- •Clock and Time classes.
- •Coordinates structure implementation
- •StationInfo structure implementation
- •IEmissionable, iSerializable and iCloneable implementation
- •TransportInfo class implementation
- •Bus, Plane, Train class implementation
- •TransportSchedule class implementation
- •Conclusions
- •References
- •Appendix a File Time.H
- •File Time.Cpp
- •File Clocks.H
- •File Clocks.Cpp
- •File iSerializable.H
- •File iEmissionable.H
- •File iCloneable.H
- •File stdafx.H
- •File stdafx.Cpp
- •CoordinatesData.Json
- •File transports.Csv
- •File Coordinates.Cpp
- •File main.Cpp
- •File Route.Cpp
- •File Route.H
- •File StationInfo. Cpp
- •File StationInfo.H
- •File TransportSchedule.H
- •File TransportSchedule.Cpp
- •File PtrArray.Cpp
- •File TransportInfo.Cpp
- •File TransportInfo.H
- •File Bus.H
- •File Bus.Cpp
- •File Plane.H
- •File Plane.Cpp
- •File Train.H
- •File Train.Cpp
- •Appendix b
File Plane.H
#pragma once
#include "Train.h"
class Plane :
public TransportInfo
{
private:
std::string flightNumber;
double fuelConsumptionPerKm;
public:
Plane();
Plane(const int ID, StationInfo const& departure, StationInfo const& destination, double fee,
double fuelConsumptionPerKm, std::string_view flightNumber);
// Inherited via TransportInfo
TransportTypes getType() const override;
void serialize(std::ofstream& out) const override;
void deserialize(std::stringstream& ss) override;
double calculateFuelConsumption(double distance) const override;
double calculateEmissions(double distance) const override;
TransportInfo* clone() const override;
friend std::istream& operator>>(std::istream& in, Plane& other);
friend std::ostream& operator<<(std::ostream& out, Plane const& other);
};
File Plane.Cpp
#include "Plane.h"
Plane::Plane()
:TransportInfo(), fuelConsumptionPerKm(), flightNumber()
{
emissionFactor = 12.2;
}
Plane::Plane(const int ID, StationInfo const& departure, StationInfo const& destination, double fee,
double fuelConsumptionPerKm, std::string_view flightNumber)
: TransportInfo(ID, departure, destination, fee),
fuelConsumptionPerKm(fuelConsumptionPerKm), flightNumber(flightNumber)
{
}
TransportTypes Plane::getType() const
{
return E_Plane;
}
void Plane::serialize(std::ofstream& out) const
{
out << static_cast<TransportInfo const&>(*this) << ','
<< this->fuelConsumptionPerKm << ',' << this->flightNumber << '\n';
}
void Plane::deserialize(std::stringstream& ss)
{
ss >> static_cast<TransportInfo&>(*this);
std::string item;
std::getline(ss, item, ',');
this->fuelConsumptionPerKm = std::stod(item);
std::getline(ss, item, ',');
this->flightNumber = item;
}
double Plane::calculateFuelConsumption(double distance) const
{
return distance * this->fuelConsumptionPerKm;
}
double Plane::calculateEmissions(double distance) const
{
return calculateFuelConsumption(distance) * this->emissionFactor
* 1.12;//As aircrafts emit more pollutions at higher altitudes
}
TransportInfo* Plane::clone() const
{
return new Plane(*this);
}
std::istream& operator>>(std::istream& in, Plane& other)
{
in >> static_cast<TransportInfo&>(other);
std::cout << "Enter the plane's flight number: ";
validateInput(other.flightNumber, in);
std::cout << "Enter the plane's fuel consumption per kilometer: ";
validateInput(other.fuelConsumptionPerKm, in);
return in;
}
std::ostream& operator<<(std::ostream& out, Plane const& other)
{
out << static_cast<TransportInfo const&>(other)
<< "\nFlight number: " << other.flightNumber <<
"\n---------------------------------\n";
return out;
}