Question: Please help, fragment of C++ code needed. Define a C++ enumeration (as an enum struct ) with the following four values: once , daily ,

Please help, fragment of C++ code needed.

  1. Define a C++ enumeration (as an enum struct ) with the following four values: once , daily , weekly , monthly .
  2. For this enumeration, define an overloaded output operator , which, depending on the enumeration value, writes daily , weekly , monthly , and otherwise, does not write anything to the character output stream reference passed as a parameter. Also define an overloaded input operator >> for enumeration values (see also examples below).
  3. Define an abstract class named CO2Emissionwith the following members:
    • private pointer attribute named next to build up a list of CO2 emissions .
    • public standard constructor initializing the pointer attribute to a C++ null pointer.
    • public virtual destructor writing " destructor CO2Emission : done" onto the standard character output stream .
    • public member function named get_next without parameter returning the value of the pointer attribute.
    • public member function named set_next with a pointer of type CO2Emission as parameter , which sets the value of the pointer attribute to the parameter value.
    • Public pure virtual member function named get_co2 without parameter and with a floating point number as return which has to be implemented in the derived classes.
    • public pure virtual member function named print without parameters and without return Which has to be Implemented in the derived classes .
  4. Define an abstract class with name Transportation publicly inherited from class CO2 emissions with Following members:
    • private attribute named km of type floating point number for the number of kilometers driven .
    • private attribute named frequency of above defined enumeration type Frequency , how often a transport takes place .
    • public standard constructor in whose body , as in the example below, the value for the kilometers traveled and the frequency (by input operator defined above) shall be read from the standard character input stream and stored in the two attributes.
    • public constructor with two parameters for initializing the two attributes with the values of the parameters - the parameter for the frequency shall be a default parameter with default value once from above defined enumeration data type Frequency .
    • public virtual destructor writing like in the examples below " destructor Transport: " , the frequency, the traveling distance value and " km done" onto the standard character output stream .
    • private member function named get_co2_pkm without parameter and with a floating point number as return which has to be implemented in the derived classes .
    • public member function named get_co2without parameters 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) and a number representing the frequency (once => 1, daily => 365, weekly => 52 , monthly => 12) 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 "transport" and the frequency (by above defined output operator) 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 function suitably).
  5. Define an class with name CO2Footprint with following members:
    • private attribute named name of type C++ string to whom the carbon footprint is assigned.
    • private pointer attribute named emissions in which to point to the head of a list of CO2 emissions.
    • public constructor initializing the name to the value of the parameter and the pointer attribute to a C++ null pointer.
    • public destructor writing "destructor for CO2Footprint for" , the name and " started... " onto the standard character output stream , then in a loop deletes all list items on the heap one by one and writes "destructor CO2Foodprint done" onto the standard character output stream at the end (see example below).
    • public member function named get_name without parameter returning the value of the same named attribute.
    • public member function named add with a pointer of type CO2Emission as parameter that inserts the object pointed to at the top of the list of CO2 emissions inserting the pointed to object at the head of the list of the carbon emissions.
    • public member function named get_sum_co2 without parameter and with a floating point number as return. In the body the carbon emissions of all list elements shall be added and this sum value get returned.
    • public member function named print without parameter and without return. In the body, the name shall be outputted after the string "CO2 FOODPRINT FOR: " , the message print shall be sent to all objects in the list, then the sum of all CO2 emissions shall be calculated and written onto the standard character output stream after "TOTAL CO2 EMISSIONS: " in the units kg and tons, each with 1 decimal place (see example below).

Please help, fragment of C++ code needed. Define a C++ enumeration (as

CO2Emission emissions next + CO2Emission + -CO2Emission() + get_next + set_next() + get_co20 + print CO2Footprint name : String + CO2Footprint() + -CO2Footprint() + get_name() + add + get_sum_co20) + print() Transport - km : Real + Transport + -Transport() -get_co2_pkmo + get_co20 + print) > frequency Frequency once daily weekly monthly

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!