Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Machine Performance Modeling Methodologies And Evaluation Strategies Lncs 257

Authors: Francesca Cesarini ,Silvio Salza

1st Edition

3540179429, 978-3540179429

More Books

Students also viewed these Databases questions