Question
Programming Assignment 1: Representing, Managing and Manipulating Travel Options You may NOT do any of the following: change any of the function names or signatures
Programming Assignment 1: Representing, Managing and Manipulating Travel Options
You may NOT do any of the following:
-
change any of the function names or signatures (parameter lists and types and return type)
-
introduce any global or static variables
-
use any arrays or vectors inside the TravelOptions class! Not for this assignment!! (You may use them as you see fit in any driver/tester programs you write)
You MAY do any of the following as you see fit:
-
Introduce helper functions. But you should make them private.
Reminders: Some functions eliminate list entries (e.g., prune_sorted). Don't forget to deallocate the associated nodes (using the delete operator).
Please read the below code and complete the missing parts.
#ifndef _TRVL_OPTNS_H
#define _TRVL_OPTNS_H
#include
#include
#include
// using namespace std;
class TravelOptions{
public:
enum Relationship { better, worse, equal, incomparable};
private:
struct Node {
double price;
double time;
Node *next;
Node(double _price=0, double _time=0, Node* _next=nullptr){
price = _price; time = _time; next = _next;
}
};
/* TravelOptions private data members */
Node *front; // pointer for first node in linked list (or null if list is empty)
int _size;
public:
// constructors
TravelOptions() {
front = nullptr;
_size=0;
}
~TravelOptions( ) {
clear();
}
/**
* func: clear
* desc: Deletes all Nodes currently in the list
* status: DONE
*/
void clear(){
Node *p, *pnxt;
p = front;
while(p != nullptr) {
pnxt = p->next;
delete p;
p = pnxt;
}
_size = 0;
front = nullptr;
}
/**
* func: size
* desc: returns the number of elements in the list
* status: DONE
*/
int size( ) const {
return _size;
}
/**
* func: compare
* desc: compares option A (priceA, timeA) with option B (priceB, timeA) and
* returns result (see enum Relationship above):
*
* There are four possible scenarios:
* - A and B are identical: option A and option B have identical price and time:
* ACTION: return equal
* - A is better than B: option A and B are NOT equal/identical AND
* option A is no more expensive than option B AND
* option A is no slower than option B
* ACTION: return better
* - A is worse than B: option A and B are NOT equal/identical AND
* option A is at least as expensive as option B AND
* option A is no faster than option B
* ACTION: return worse
* NOTE: this means B is better than A
* - A and B are incomparable: everything else: one option is cheaper and
* the other is faster.
* ACTION: return incomparable
*
* COMMENTS: since this is a static function, there is no calling object.
* To call it from a client program, you would do something like this:
*
TravelOptions::Relationship r;
double pa, ta, pb, tb;
// some code to set the four price/time variables
r = TravelOptions::compare(pa, ta, pb, tb);
if(r == TravelOptions::better)
std::cout << "looks like option b is useless!" << std::endl;
// etcetera
*
* status: TODO
*/
static Relationship compare(double priceA, double timeA,
double priceB, double timeB) {
return incomparable; // placeholder
}
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