Question: c++ The Select class has a pure virtual function bool select(sheet, row) that represents its interface. This function returns true if the row should be

c++

The Select class has a pure virtual function bool select(sheet, row) that represents its interface. This function returns true if the row should be printed and false if the row should be ignored. You are also given the derived Select_Column helper class to simplify writing selectcion criteria that apply to the contents of a column.

You will need to implement four selection classes: Select_Contains, Select_Not, Select_And, and Select_Or. The Select_Contains::select routine should return true if the contents of the specified cell contains the given substring. The strings do not need to be equal; the substring may occur anywhere inside the cell's string.

main.cpp

#include "spreadsheet.hpp"
#include "select.hpp"
#include
int main(int argc, char* argv[])
{
Spreadsheet sheet;
sheet.set_column_names({"First","Last","Age","Major"});
sheet.add_row({"Amanda","Andrews","22","business"});
sheet.add_row({"Brian","Becker","21","computer science"});
sheet.add_row({"Carol","Conners","21","computer science"});
sheet.add_row({"Joe","Jackson","21","mathematics"});
sheet.add_row({"Sarah","Summers","21","computer science"});
sheet.add_row({"Diane","Dole","20","computer engineering"});
sheet.add_row({"David","Dole","22","electrical engineering"});
sheet.add_row({"Dominick","Dole","22","communications"});
sheet.add_row({"George","Genius","9","astrophysics"});
sheet.print_selection(std::cout);
std::cout << std::endl;
// Sample usage 1
// sheet.set_selection(new Select_Contains(&sheet,"Last","Dole"));
sheet.print_selection(std::cout);
std::cout << std::endl;
// Sample usage 2
// sheet.set_selection(
// new Select_And(
// new Select_Contains(&sheet,"Last","Dole"),
// new Select_Not(
// new Select_Contains(&sheet,"First","v"))));
sheet.print_selection(std::cout);
std::cout << std::endl;
// Sample usage 3
// sheet.set_selection(
// new Select_Or(
// new Select_Contains(&sheet,"First","Amanda"),
// new Select_Or(
// new Select_Contains(&sheet,"Last","on"),
// new Select_Contains(&sheet,"Age","9"))));
sheet.print_selection(std::cout);
std::cout << std::endl;
return 0;
}

select.hpp

#ifndef __SELECT_HPP__
#define __SELECT_HPP__
#include
class Select
{
public:
virtual ~Select() = default;
// Return true if the specified row should be selected.
virtual bool select(const Spreadsheet* sheet, int row) const = 0;
};
// A common type of criterion for selection is to perform a comparison based on
// the contents of one column. This class contains contains the logic needed
// for dealing with columns. Note that this class is also an abstract base
// class, derived from Select. It introduces a new select function (taking just
// a string) and implements the original interface in terms of this. Derived
// classes need only implement the new select function. You may choose to
// derive from Select or Select_Column at your convenience.
class Select_Column: public Select
{
protected:
int column;
public:
Select_Column(const Spreadsheet* sheet, const std::string& name)
{
column = sheet->get_column_by_name(name);
}
virtual bool select(const Spreadsheet* sheet, int row) const
{
return select(sheet->cell_data(row, column));
}
// Derived classes can instead implement this simpler interface.
virtual bool select(const std::string& s) const = 0;
};
#endif //__SELECT_HPP__

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!