Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

While calculating LCOM4, we ignore constructors and destructors. Constructors and destructors frequently set and clear all variables in the class, making all methods connected through

While calculating LCOM4, we ignore constructors and destructors. Constructors and destructors frequently set and clear all variables in the class, making all methods connected through these variables, which increases cohesion artificially.

LCOM4 = 1 indicates a cohesive class, which is the "good" class.

LCOM4 >= 2 indicates a problem. The class should be split into so many smaller classes.

LCOM4 = 0 happens when there are no methods in a class. This is also a "bad" class.

Calculate the value of the LCOM4 measurement for the following code:

#include "src/route.h"

Route::Route(std::string name, Stop ** stops, double * distances,

int num_stops, PassengerGenerator * generator) {

//Constructors ignored in LCOM4 calculation

}

void Route::Update() {

GenerateNewPassengers();

for (std::list::iterator it = stops_.begin();

it != stops_.end(); it++) {

(*it)->Update();

}

}

bool Route::IsAtEnd() const {

return destination_stop_index_ >= num_stops_;

}

void Route::NextStop() {

destination_stop_index_++;

if (destination_stop_index_ < num_stops_) {

std::list::const_iterator iter = stops_.begin();

std::advance(iter, destination_stop_index_);

destination_stop_ = *iter;

} else {

destination_stop_ = (*stops_.end());

}

}

Stop * Route::GetDestinationStop() const {

return destination_stop_;

}

double Route::GetTotalRouteDistance() const {

int total_distance = 0;

for (std::list::const_iterator iter = distances_between_.begin();

iter != distances_between_.end();

iter++) {

total_distance += *iter;

}

return total_distance;

}

double Route::GetNextStopDistance() const {

std::list::const_iterator iter = distances_between_.begin();

std::advance(iter, destination_stop_index_-1);

return *iter; // resolving the iterator gets you the Stop * from the list

}

int Route::GenerateNewPassengers() {

// returning number of passengers added by generator

return generator_->GeneratePassengers();

}

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_2

Step: 3

blur-text-image_3

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 In Depth Relational Theory For Practitioners

Authors: C.J. Date

1st Edition

0596100124, 978-0596100124

More Books

Students also viewed these Databases questions

Question

6. Describe to a manager the different types of distance learning.

Answered: 1 week ago