
Cuko T.
asked 12/21/20oop classes and object question
Classes & UML Design
Objectives
To practice on UML
To practice on Class, its attributes and methods
To practice on Single Responsibility Principle and Singleton Pattern
Activities
The users will provide an input and output file from the command line. Write a program that reads
commands from the input file and prints output to the output file.
The input file contains the basic commands.
The command list;
-------------------------------------------------------------
start_engine;
stop_engine;
absorb_fuel <quantity>;
give_back_fuel <quantity>;
add_fuel_tank <capacity>;
list_fuel_tanks;
print_fuel_tank_count;
remove_fuel_tank <tank_id>;
connect_fuel_tank_to_engine <tank_id>;
disconnect_fuel_tank_from_engine <tank_id>;
list_connected_tanks;
print_total_fuel_quantity;
print_total_consumed_fuel_quantity;
print_tank_info <tank_id>;
fill_tank <tank_id> <fuel_quantity>;
open_valve <tank_id>;
close_valve <tank_id>;
break_fuel_tank <tank_id>;
repair_fuel_tank <tank_id>;
wait <seconds>;
stop_simulation;
--------------------------------------------------------------
The program needs to run until it takes a “stop_simulation;” command.
There is only one engine. The engine’s attributes are;
o fuel_per_second: double // it will always be 5.5
o status: boolean // true means running
The engine has its internal tank to store fuel. Internal tank capacity will be 55.0
There is no max tank count (Unlimited)
Each command takes 1 second. So, after the command is executed, the engine consumes
some fuel if it is running.
wait command consumes fuel along given seconds if the engine is running.
print_tank_info command prints all information about the selected tank.
The engine absorbs fuel from a connected tank when the internal tank capacity goes below
20.0. The connected tank is selected randomly, and if there is no enough fuel in it, another
tank will be selected.
The engine has to return fuel in its internal tank to the connected tanks before it is
stopped. Returned fuel needs to go connected tank, which has the minimum fuel in it.
There are several fuel tanks. Tank’s attributes are;
o capacity: double
o fuel_quantity: double
o broken: boolean
The engine needs a minimum of one connected tank to start; otherwise, the engine can not start.
Each tank has a valve to connect the tanks and the engine.
Task List;
1. Draw a UML diagram about the system.
2. Implement the classes. The classes need to include possible attributes and methods.
3. Simulate the system with several input files not only given example input file.
Problem Solving Tips
1. UML and source code has to match
2. Do not implement logic in Main. Do it in Class, which is responsible.
3. Have a look at the example input file.
----------------------------------------------------------------------------------
start_engine;
add_fuel_tank 100;
add_fuel_tank 150;
add_fuel_tank 100;
add_fuel_tank 250;
add_fuel_tank 100;
fill_tank 1 100;
fill_tank 2 150;
fill_tank 3 100;
connect_fuel_tank_to_engine 1;
connect_fuel_tank_to_engine 2;
connect_fuel_tank_to_engine 3;
fuel_tank_to_engine 4;
remove_fuel_tank 5;
connect_fuel_tank_to_engine 5;
disconnect_fuel_tank_from_engine 4;
give_back_fuel <quantity>;
open_valve 1;
open_valve 2;
fill_tank 1 100;
fill_tank 2 150;
fill_tank 3 100;
start_engine;
wait 5;
list_fuel_tanks;
print_fuel_tank_count;
list_connected_tanks;
print_total_fuel_quantity;
print_total_consumed_fuel_quantity;
print_tank_info 1;
print_tank_info 2;
close_valve <tank_id>;
wait 5;
fill_tank 1 100;
fill_tank 2 150;
fill_tank 3 100;
print_tank_info 1;
print_tank_info 2;
print_tank_info 3;
stop_engine;
print_tank_info 1;
print_tank_info 2;
stop_simulation;
1 Expert Answer

Patrick B. answered 12/22/20
Math and computer tutor/teacher
Hello Cuko !!!
and Happy Holidays...
Thank you for your posting and the challenging project..
I have posted a design document for you to read over, peruse, and examine. It contains the UML diagram along with the requirements you have given and further questions and suggestions to consider?
After perusing the requirements and specifications you have kindly provided, I am beginning
implementation on what is is completely understood, namely items #1-5 I have listed below. However, there are some other design issues to discuss further, in particular #6-12, which deal with the engine-tank connection logic and how the script is to terminate as gracefully as possible if and when the engine runs out of fuel. Specifically, it is possible that none of the tanks declared are available, sufficient, and substantial. They are all either broken or do not contain sufficient fuel to keep the engine running above the required thresholds. I am suggesting an automatic engine shutdown in this case.
Finally, there is the issue of physical heap memory constraints. The specs say UNLIMITED tanks, but physical heap memory says otherwise.
Here they are for your convenience. As stated #1-5 are ok. The questions begin with #6-12, which address these unstated issues and their potential solutions...
(1) each command takes 1 second = 5.5 units of fuel if the engine is ON;
(2) wait command consumes fuel if engine is running...
(3) Engine consumes fuel from a connected tank when it’s internal fuel quantity drops below 20; the connected tank is selected randomly, and if there is not enough fuel in it, another is selected
(4) Engine must return the fuel in its internal tank to the most empty tank(s) before shutting off
(5) The engine must be connected to at least one tank before it can start... AND IF IT's not???? see #12
--------------------------------------------------------------
(6) cannot use tank if it is broken?
(7) must open the valves after connecting tank to engine; otherwise tank is broken?
(8) must close value before disconnecting tank from engine; otherwise tank gets broken?
(9) What to do if there is no more fuel available in any of the tanks and the engine runs out of fuel?
No further commands in the script can be executed.. This is a LOGIC error in the script made by the programmer and not a violation of the STOP_SIMULATION rule. The script terminates ungracefully/with an exception (see #12)
(10) Procedure/Subroutine ACTIVATE_TANK( int) which automatically connects the tank to the engine and opens the valve, so that breakage is prevented
(11) Procedure/Subroutine DEACTIVATE_TANK(int) which automatically closes the valve and disconnects the tank from the engine, so that breakage is prevented
(12) Automatic Engine shutdown when there is only 15 units of fuel remaining in the internal tank, with no sufficient, substantial available tanks. This is sufficient to issue the commands to return the internal fuel to tanks and shut off. The remaining 15 – 5.5 – 5.5 = 4 units of fuel are returned to the tank(s) before shutdown.
I am waiting for your response and feedback...

Patrick B.
Though I am revealing my age, there is an old video game called "Scramble" that uses this very same logic. The jet must "refuel" by blowing up oil and gas tanks during gameplay. Another example is the video game "Phoenix" which uses the same logic, though with a protective shield.12/22/20
Cuko T.
First of all, thank you very much for your answer and suggestions. My explanation for incomprehensible points is as follows: 6) Cannot be used if the tank is broken 7) After connecting the tank to the engine, if the valve is not opened, the tank is broken. 8) After the tank leaves the engine, its value should be turned off. otherwise it breaks down. 9) If the fuel in the tanks and engine runs out, it ends with a stop engine notification. I created 4 classes and headers as part of the project: 1) engine 2) tank 3) valve 4) fileinput (I use it with fstream to read and print the input txt file.) I used a structure like I wrote below here but I don't know how to fill it. #include #include #include #include "File.h" #include "Engine.h" #include "Tank.h" #include "Valve.h" using namespace std; /** * @brief:This function reads commands from a file. * @param:fstream& commands-commands which are read from file. */ void FileInput::is_command(fstream& commands) { string str; if (!commands.is_open()) { cout << "File does not exist!" << endl; system("pause"); exit(0); } if (commands.peek() == ifstream::traits_type::eof()) { cout << "File is empty!" << endl; system("pause"); exit(0); } while (commands >> str) { if (str == "start_engine;") { cout << "Engine starts." << endl; } else if (str == "stop_engine;") { cout << "Engine stops." << endl; } else if (str == "give_back_fuel") { } else if (str == "add_fuel_tank") { } else if (str == "list_fuel_tanks;") { } else if (str == "remove_fuel_tank") { } else if (str == "connect_fuel_tank_to_engine") { } else if (str == "disconnect_fuel_tank_from_engine") { } else if (str == "open_valve") { } else if (str == "close_valve") { } else if (str == "break_fuel_tank") { } else if (str == "repair_fuel_tank") { } else if (str == "stop_simulation;") { cout << "End of the simulation." << endl; exit(0); } else { cout << "This command does not exist!" << endl; } } }12/22/20

Patrick B.
My email is patrick dot baldwin dot 1 at wyzant dot com ----------------------------------------------------------------------------------- we need to discuss more things: (1) Does the tank have only 1 value or ANY number of valves? (2) what to do if invalid command or syntax error?12/22/20
Cuko T.
ı send you a mail mr. Patrick12/25/20
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Patrick B.
Also, the Engine and it's Fuel Tank Manager implemented as Singletons12/22/20