1. Homepage
  2. Programming
  3. CMSC 341 Data Structures - Project 1: The Airplane Fuel System

CMSC 341 Data Structures - Project 1: The Airplane Fuel System

Engage in a Conversation
USUniversity of Maryland-Baltimore CountyCMSC 341Data StructuresThe Airplane Fuel SystemC++

Objectives

  • Practice analyzing a project's requirements.
  • Implementing a circular buffer using linked list.
  • Implementing a singly linked list.
  • Combining two data structures to satisfy a project's requirements.
  • Practice C++ dynamic memory management, i.e. avoiding memory leaks, avoiding double free, protection against wrong accesses in memory (segmentation fault), etc.
  • Practice writing test cases for a project.

Introduction

The airplane fuel system in a delta-wings airplane such as Concorde has three functions: CourseNana.COM

  • to supply fuel to the engines,
  • to control the position of the aircraft’s Centre of Gravity (CG),
  • and to act as a heat sink to absorb kinetic heating from the structure and to dissipate heat generated by the air-conditioning and hydraulic systems.

A main job of the fuel system in such a design is transferring fuel across multiple tanks. Here is an explanation of this idea from the Concorde engineers: CourseNana.COM

 Before Concorde takes-off, the flight engineer will start to move fuel from the forward trim tanks to the rear trim and collection tanks, this will continue during the acceleration through Mach 1 and onto eventual Mach 2. During this process around 20 tons of fuel is moved and this results in a shift of the CG by 6ft (2meters). This will neatly balance the change in the center lift of the aircraft. 

CourseNana.COM

Figure from: https://www.heritageconcorde.com/fuel-transfer

Circular Linked List

A circular linked list is a linked list in which the last node points to the first node. To access the linked list we store the memory location for the last node in a pointer variable. This pointer variable in different applications is referred to by different names such as cursor or current. Generally the current pointer points to the latest node inserted into the list. Therefore, the next node of current is the first one inserted into the list. The circular linked list is commonly used to implement the queue ADT in which the dequeue happens at the next node of current. CourseNana.COM

CourseNana.COM

CourseNana.COM

Assignment

Your assignment is to implement a circular linked list data structure that stores the tanks information and provides the required functionality for the system. Since the number of tanks for different airplane designs would be different, using a linked list data structure makes this software module more general. CourseNana.COM

For this project, you are provided with the skeleton .h and .cpp files and a sample driver: CourseNana.COM

CourseNana.COM

  • fuel.h - Interface for the Tank, Pump, and FuelSys classes.
  • fuel.cpp - This file will be completed and submitted.
  • driver.cpp - A sample driver program showing the sample use of the FuelSys class.
  • driver.txt - Sample output from the sample driver.cpp.

CourseNana.COM

Additionally, you are responsible for thoroughly testing your program. Your test program, mytest.cpp, must be submitted along with other files. For grading purposes, your implementation will be tested on input data of varying sizes and configurations. Your submission will also be checked for memory leaks and memory errors. CourseNana.COM


Specifications

There are three classes in this project. The Tank class is a node in the linked list and it stores the information for a fuel tank. The Pump class is a node in a singly linked list and it stores the information for a pump that is installed in a tank. Every tank may have multiple fuel pumps installed. Every pump can transfer fuel from its parent tank to a specified target tank. The FuelSys class stores the information for the entire fuel system and it implements a circular linked list. CourseNana.COM

Class Tank

The implementation of this class is provided. You are not allowed to modify this class. The Tank class implements a node that can be used in a linked list. Every node has a pointer to the next node in the linked list. This pointer is stored in the m_next member variable. Every tank object has a unique ID number in this system. Moreover, every tank can have multiple fuel pumps. The pumps of a tank are stored in a singly linked list accessible through the head of the list that is stored in the member variable m_pumps. The member variable m_tankFuel stores the current amount of fuel in the tank. We can transfer part of the current fuel to another tank using one of the pumps installed in the tank. CourseNana.COM

Class Pump

The implementation of this class is provided. You are not allowed to modify this class. The Pump class implements a node that can be used in a linked list. Every node has a pointer to the next node in the linked list. This pointer is stored in the m_next member variable. Every pump object has a unique ID number in the context of its parent tank. Moreover, every pump has a target tank that can receive fuel from the pump. This tank ID is stored in the member variable m_target. CourseNana.COM

Class FuelSys

This class implements a circular linked list data structure. You need to implement the class. The Tank nodes are stored in the linked list which is presented by the pointer to its current node stored in the member variable m_current. Every tank has a unique ID number. The list does not hold duplicate tank IDs. The tank IDs are integer numbers greater than or equal to zero. CourseNana.COM

CourseNana.COM

FuelSys::FuelSys()
Default constructor creates an empty object and initializes member variables.
FuelSys::~FuelSys()
Destructor deallocates all memory and reinitializes member variables.
bool FuelSys::addTank(int tankID, int tankCap, int tankFuel = 0)
This function creates and inserts a new Tank object after the current location of the list and makes the node the current location. If the insertion is successful the function returns true, otherwise it returns false. Since the tank IDs must be unique in the list this function will not insert the tank if it already exists. In such a failure case the function returns false. The tankCap cannot be less than the min capacity. The amount of fuel cannot exceed the tank capacity.
bool FuelSys::removeTank(int tankID)
This function removes the tank with tankID from the list. If the requested tank is removed the function returns true otherwise it returns false, i.e. if tankID does not exists the function returns false. Note, if the tank has pumps the list of pumps must be removed too.
bool FuelSys::findTank(int tankID)
This function searches the list for tankID. If the ID is found the function makes it the next of current location and it returns true. If the ID is not found the function returns false.
bool FuelSys::addPump(int tankID, int pumpID, int targetTank)
This function finds the tankID and adds a pump with pumpID to the tank's pump list. The targetTank is the tank ID that will receive fuel from the parent of the pump in the case of transfer requests. Both tankID and targetID must exist in the list in order to add the pump. In the case of success the function returns true, otherwise it returns false. The pump must be added to the head of the pump list.
bool FuelSys::removePump(int tankID, int pumpID)
This function removes the pumpID from the tankID. If the remove operation is successful the function returns true. If either tankID or pumpID does not exist it is a failure and the function returns false.
bool FuelSys::fill(int tankID, int fuel)
This function fills up the tankID with the amount of fuel. If the empty space of the tank is less than fuel the function still fills up the tank up to its capacity and returns true. If the tank does not exist the function returns false.
int FuelSys::totalFuel() const
This function calculates and returns the total amount of current fuel in the airplane. The total amount of fuel is the sum of fuel in all tanks.
bool FuelSys::drain(int tankID, int pumpID, int fuel)
This function transfers the fuel from tankID to the targetID specified in the pumpID. If the amount of requested transfer is more than the current empty space in the target tank, the function fills the target tank and returns true. If the amount of requested transfer is less than the empty space of the target tank the function transfers all and returns true. If the amount of requested transfer is greater than the current fuel in the source tank, the function performs the transfer and makes the source tank empty. In a case of failure that either tank or the pump does not exist the function returns false.
void FuelSys::dumpSys() const
This function prints out the list of tanks along with the amount of current fuel in the tank and the list of its pumps to the standard output. The implementation of this function is provided for the debugging purposes.
const FuelSys & FuelSys::operator=(const FuelSys & rhs)
The assignment operator creates a deep copy of rhs. Reminder: a deep copy means the current object has the same information as rhs object, however, it has its own memory allocated. Moreover, an assignment operator needs protection against self-assignment. Note: the new copy is an exact copy of rhs. For example, the pumps of a tank appear in the same order as in rhs.

CourseNana.COM

Additional Requirements

  • The class declarations (Tank), (Pump) and (FuelSys) and provided function implementations in fuel.cpp may not be modified in any way. No additional libraries may be used in the project implementation. Private helper functions may be added but must be declared in the private section of the FuelSys class. There is a comment indicating where private helper function declarations should be written.
  • No STL containers or additional libraries may be used except the ones that are already in the project files. STL containers or additional libraries may be used in your tests, i.e. mytest.cpp.
  • Your code should not have any memory leaks or memory errors.
  • Follow all coding standards as described on the C++ Coding Standards. In particular, indentations and meaningful comments are important.

Testing

You need to test your project and you need to submit your tests along with your project. Tests must be submitted in a file called mytest.cpp. CourseNana.COM

  • The test file name must be mytest.cpp; the file name must be in lower case, a file name like myTest.cpp is not acceptable.
  • The test file must contain the declaration and implementation of your Tester class and the main() function as well as all your test cases, i.e. calls to your test functions.
  • You are responsible for thoroughly testing your work before submission. The following section presents a non-exhaustive list of tests to perform on your implementation.
  • You must write a separate function for every test case.
  • Every test function must return true/false depending on passing or failing the test. Visual outputs are not accepted as test results.
  • Tests cannot be interactive. The test file mytest.cpp must compile and run to completion.
  • An example of declaring, implementing, and calling a test function, and outputting the test results was provided in the driver.cpp file of project 0.
  • The testing guidelines page provides information that helps you to write more effective test cases.

Note: Testing incrementally makes finding bugs easier. Once you finish a function and it is testable, make sure it is working correctly. CourseNana.COM

Testing FuelSys class:

  • Test whether addTank() works correctly for a normal case, i.e. inserting multiple tanks. We check whether the function returns true for every insertion. And we check whether all nodes are inserted.
  • Test whether addTank() works correctly for an error case. For example, for the error case of insertion we check that the tank with an ID less than zero is not inserted and the function returns false. Another error case would be inserting a duplicate ID.
  • Test whether removeTank() works correctly for a normal case. Create an object with a decent number of tanks and remove all, then check if all are removed correctly and at every removal the function returns true.
  • Test whether removeTank() works correctly for an error case which the removal request is for a non-existing tank.
  • Test whether findTank() works correctly for a normal case. Create an object with a decent number of tanks and search for them, then check if the found tank is the next node of the current node in the list and at every search operation the function returns true.
  • Test whether findTank() works correctly for an error case which the tank does not exist in the list.
  • Test whether totalFuel() works correctly for a normal case. It returns the correct value.
  • Test whether totalFuel() works correctly for an error case. It returns zero where there is no tank in the system.
  • Test whether addPump() works correctly for a normal case. It adds multiple pumps to some of the tanks.
  • Test whether addPump() works correctly for an error case. It does not add a duplicate pump ID to a tank. Another error case would be adding a pump to a tank that does not exist.
  • Test whether removePump() works correctly for a normal case. It removes multiple pumps from some of the tanks.
  • Test whether removePump() works correctly for an error case. That is trying to remove a non-existent pump or trying to remove a pump from a non-existent tank.
  • Test whether drain() works correctly. It transfers the fuel from the source tank to the target tank correctly where the requested fuel is less than the empty space of the target tank. Another case would be when the amount of fuel is more than the empty space of the target tank.
  • Test whether drain() works correctly for the error cases. For example, the source tank or the pump or the destination tank does not exist in the system.
  • Test the overloaded assignment operator.

Memory leaks and errors:

  • Run your test program in valgrind; check that there are no memory leaks or errors.
    Note: If valgrind finds memory errors, compile your code with the -g option to enable debugging support and then re-run valgrind with the -s and --track-origins=yes options. valgrind will show you the lines numbers where the errors are detected and can usually tell you which line is causing the error.
  • Never ignore warnings. They are a major source of errors in a program.

What to Submit

You must submit the following files to the proj1 submit directory: CourseNana.COM

  • fuel.h
  • fuel.cpp
  • mytest.cpp (Note: This file contains the declaration and implementation of your Tester class and the main function as well as all your test cases, i.e. calls to your test functions.)

If you followed the instructions in the Project Submission page to set up your directories, you can submit your code using the following command: CourseNana.COM

   cp fuel.h fuel.cpp mytest.cpp ~/cs341proj/proj1/

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
US代写,University of Maryland-Baltimore County代写,CMSC 341代写,Data Structures代写,The Airplane Fuel System代写,C++代写,US代编,University of Maryland-Baltimore County代编,CMSC 341代编,Data Structures代编,The Airplane Fuel System代编,C++代编,US代考,University of Maryland-Baltimore County代考,CMSC 341代考,Data Structures代考,The Airplane Fuel System代考,C++代考,UShelp,University of Maryland-Baltimore Countyhelp,CMSC 341help,Data Structureshelp,The Airplane Fuel Systemhelp,C++help,US作业代写,University of Maryland-Baltimore County作业代写,CMSC 341作业代写,Data Structures作业代写,The Airplane Fuel System作业代写,C++作业代写,US编程代写,University of Maryland-Baltimore County编程代写,CMSC 341编程代写,Data Structures编程代写,The Airplane Fuel System编程代写,C++编程代写,USprogramming help,University of Maryland-Baltimore Countyprogramming help,CMSC 341programming help,Data Structuresprogramming help,The Airplane Fuel Systemprogramming help,C++programming help,USassignment help,University of Maryland-Baltimore Countyassignment help,CMSC 341assignment help,Data Structuresassignment help,The Airplane Fuel Systemassignment help,C++assignment help,USsolution,University of Maryland-Baltimore Countysolution,CMSC 341solution,Data Structuressolution,The Airplane Fuel Systemsolution,C++solution,