Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please provide C++ code. Define a class with name Bus with following members: private Boolean attribute named local_transport , whether the bus runs on local
Please provide C++ code.
- Define a class with name Bus with following members:
- private Boolean attribute named local_transport, whether the bus runs on local transport or not, i.e. long-distance transport.
- private floating point number named km as an attribute for the number of kilometers driven.
- public standard constructor in whose body, as in the example below, the value for the Boolean attribute and the kilometers traveled are read from the standard character input stream and stored in the two attributes.
- public constructor with two suitable parameters for initialising the two attributes with the values of the parameters.
- private member function named get_co2_pkm without parameter and with a floating point number as return. In the body, the value 0.111 kg CO2 emission per passenger-kilometer driven should be returned for a local transport bus or 0.036 kg CO2 emission per passenger-kilometer driven for a long-distance bus (depending on the value of the attribute local_transport).
- public member function named get_co2 without parameter and with a floating point number as return. In the body, the product of the kilometers driven and the respective emission value for one kilometer (via a call to the previously defined member function) shall be calculated and returned.
- public member function with name print without parameter and without return. In the body, as in the example below, after the string "bus travel", depending on the value of the Boolean attribute "local transport" or "long distance" shall be written onto the standard character output stream, the kilometers driven with one decimal place, in round brackets the CO2 emission value per person-kilometer with three decimal places and the calculated CO2 emission with one decimal place (call the previous member functions suitably).
- Define a class with name Car with following members:
- private floating point number named l_fuel_km as an attribute for the liters consumption of fuel per 100 kilometers.
- private floating point number named km as an attribute for the number of kilometers driven.
- public standard constructor in whose body, as in the example below, the value for consumption of fuel and the kilometers traveled shall be read from the standard character input stream and stored in the attributes.
- public constructor with two suitable parameters for initialising the two attributes with the values of the parameters.
- private member function named get_co2_km without parameter and with a floating point number as return. In the body, the CO2 emission is to be calculated for one kilometer driven with 2.3 kg of CO2 emission per liter of fuel consumed (hint: the 2.3 kg consumption is per 100 km).
- public member function named get_co2 without parameter and with a floating point number as return. In the body, the product of the kilometers driven and the respective emission value (via a call to the previously defined member function) shall be calculated and returned.
- public member function with name print without parameter and without return. In the body, as in the example below the string "passenger car travel" shall be written onto the standard character output stream, the kilometers driven with one decimal place, in round brackets the CO2 emission value per kilometer with three decimal places and the calculated CO2 emission with one decimal place (call the previous member functions suitably).
- Define a class with name Cruise with following members:
- private floating point number named days as an attribute for the number of days of the cruise.
- private floating point number named sea_days as an attribute for the number of sea days of the cruise.
- public standard constructor in whose body, as in the example below, the values for the number of days/duration of the cruise and the number of sea days are read from the standard character input stream and stored in the two attributes.
- public constructor with two suitable parameters for initialising the two attributes with the values of the parameters.
- private member function named get_co2_day with a Boolean parameter for a sea day or not and with a floating point number as return. In the body, for a sea day (parameter value true) the value 280 kg CO2 emission or for a harbour day 190 kg CO2 emission shall be returned.
- public member function named get_co2 without parameter and with a floating point number as return. In the body, the result of the addition of the CO2 emissions of the harbour and sea days calculated each by the product of the days and the respective emission value (via a call to the previously defined member function) shall be returned.
- public member function with name print without parameter and without return. In the body, as in the example below, the string "cruise holiday (without flights):" shall be written onto the standard character output stream, the number of days and sea days, in round brackets the CO2 emission values for sea and harbour days with three decimal places and the calculated CO2 emission with one decimal place (call the previous member functions suitably).
- Define a class with name Flight with following members:
- private floating point number named km as an attribute for the number of flown kilometers.
- public standard constructor in whose body, as in the example below, the value for the kilometers flown shall be read from the standard character input stream and stored in the attribute.
- public constructor with one suitable parameter for initialising the attribute with the value of the parameter.
- private member function named get_co2_pkm without parameter and with a floating point number as return. In the body, a flatly calculated emission value of 0.27 kg CO2 for a flown passenger-kilometer shall be returned without differentiation between short and long distance or aircraft types.
- public member function named get_co2 without parameter and with a floating point number as return. In the body, the product of the kilometers flown and the emission value (via a call to the previously defined member function) shall be calculated and returned.
- public member function with name print without parameter and without return. In the body, as in the example below the string "flight travel" shall be written onto the standard character output stream, the kilometers flown with one decimal place, in round brackets the CO2 emission value per person-kilometer with three decimal places and the calculated CO2 emission with one decimal place (call the previous member functions suitably).
- Define a class with name Train with following members:
- private Boolean attribute named local_transport, whether the train runs on local transport or not, i.e. long-distance transport.
- privates Boolesches Attribut namens one_way, ob der Zug nur hin fhrt/einfache Hinfahrt oder hin und zurck./ private Boolean attribute named one_way, whether the train runs one way or return/roundtrip.
- private floating point number named km as an attribute for the number of kilometers driven.
- public standard constructor in whose body, as in the example below, the values for the two Boolean attributes and the kilometers traveled are read from the standard character input stream and stored in the three attributes.
- public constructor with two suitable parameters for initialising the two attributes with the values of the parameters - a one-way travel shall be defined as default parameter.
- private member function named get_co2_pkm without parameter and with a floating point number as return. In the body, the value 0.085 kg CO2 emission per passenger-kilometer driven should be returned for a local transport train or 0.035 kg CO2 emission per passenger-kilometer driven for a long-distance train (depending on the value of the attribute local_transport).
- public member function named get_co2 without parameter and with a floating point number as return. In the body, the product of the kilometers driven and the respective emission value (via a call to the previously defined member function) shall be calculated and returned. In case of a round trip, a doubled CO2 emission value shall be calculated and returned.
- public member function with name print without parameter and without return. In the body, as in the example below, after the string "train travel", depending on the value of the Boolean attribute "local transport" or "long distance" shall be written onto the standard character output stream, the kilometers driven with one decimal place, in round brackets the CO2 emission value per person-kilometer with three decimal places and the calculated CO2 emission with one decimal place (call the previous member functions suitably).
- Write a function main with following definitions and statements:
- define an object variable b1 of type Bus and input via the standard constructor as example long distance and 548.3 km (distance Duisburg-Berlin) on keyboard.
- define a pointer variable b2 of type Bus and initialise it with a new object on heap, having as two parameters in the constructor call a Boolean value for local transport and 2200 km (example: 220 attendance days with 2 * 5 km bus ride to work/university).
- send a message print to object b1.
- send a message print to the object pointer b2 points to
- define an object variable c1 of type Car and input via the standard constructor as example a consumption of 6 l fuel per 100 km and 432.78 km (distance Duisburg-Stuttgart) on keyboard.
- define a pointer variable c2 of type Car and initialise it with a new object on heap, having as two parameters in the constructor call 7.5 l fuel consumption per 100 km and 5500 km (example: 220 attendance days with 25 km typical commuter distance).
- send a message print to object c1./
- send a message print to the object pointer c2 points to
- define an object variable h1 of type Cruise and input via the standard constructor as example 3 days duration and 1 sea day on keyboard.
- define a pointer variable h2 of type Cruise and initialise it with a new object on heap, having as two parameters in the constructor call 14 days duration and 3 sea days.
- send a message print to object h1.
- send a message print to the object pointer h2 points to
- define an object variable f1 of type Flight and input via the standard constructor 15587.88 km (7793.94 km air distance Frankfurt (Main)-Beijing) on keyboard.
- define a pointer variable f2 of type Flight and initialise it with a new object on heap, having as two parameters in the constructor call 2669.9 km (1334.95 km air distance Dusseldorf-Palma de Mallorca) .
- send a message print to object f1.
- send a message print to the object pointer f2 points to
- define an object variable t1 of type Train and input via the standard constructor as example local transport, 53 km (distance Duisburg-Dortmund) and roundtrip/return travel on keyboard.
- define a pointer variable t2 of type Train and initialise it with a new object on heap, having as three parameters in the constructor call a Boolean value for long distance, 628.8 km (distance Duisburg-Munique) and roundtrip/return travel.
- send a message print to object t1.
- send a message print to the object pointer t2 points to.
- Sum up all CO2-emissions of the 10 example objects, output the sum value as in the example below in the units kilograms and tonnes as well as a concluding sentence "Based purely on the CO2 absorption capacity of nature, each world citizen should currently afford a maximum of around 2.3 tons per year.".
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started