Okay. This problem is from "Objects,Abstraction,Data Structures and Design using C++" by Elliot Koffman and Paul Wolf Gang pg127. #2

Implement an array- based program application that manages a collection of DVDs. The data for each DVD will consist of a title , a category, running time, year of release, and price. The user should be able to add new DVDs, to the collection, remove DVD, edit the information stored for a DVD,list all DVDs in a specified category, and retrieve and display the information saved for a DVD given its title.

I need some ideas, especially on creating the remove, add ,and edit functions.

Dani AI

Generated

A concise, assignment-friendly approach (array-based) that complements ’s problem and builds on ’s pointer to higher‑level containers: wrap a fixed-size C++ array inside a small manager class, keep a count field, and implement add/remove/edit/find/list as simple operations that maintain invariants. This keeps code close to what the textbook expects while making behavior easy to reason about and test.

struct DVDItem {
  std::string title;
  std::string category;
  int year;
  int durationMinutes;
  double price;
};

class DVDCollection {
  static const size_t MAX = 200;
  DVDItem items[MAX];
  size_t count = 0;

public:
  bool add(const DVDItem& d) {
    if (count >= MAX) return false;            // full
    if (findIndex(d.title) != -1) return false;// optional: prevent duplicates
    items[count++] = d;
    return true;
  }

  int findIndex(const std::string& title) const {
    auto lower = [](std::string s){
      std::transform(s.begin(), s.end(), s.begin(),
                     [](unsigned char c){ return std::tolower(c); });
      return s;
    };
    std::string t = lower(title);
    for (size_t i = 0; i < count; ++i)
      if (lower(items[i].title) == t) return (int)i;
    return -1;
  }

  bool removeByTitle(const std::string& title) {
    int i = findIndex(title);
    if (i < 0) return false;
    for (size_t j = i; j + 1 < count; ++j) items[j] = items[j+1];
    --count;
    return true;
  }

  bool editByTitle(const std::string& title, const DVDItem& newInfo) {
    int i = findIndex(title);
    if (i < 0) return false;
    items[i] = newInfo;
    return true;
  }

  void listByCategory(const std::string& cat, std::ostream& os) const {
    auto lc = [](std::string s){ std::transform(s.begin(), s.end(), s.begin(),
                     [](unsigned char c){ return std::tolower(c); }); return s; };
    std::string c = lc(cat);
    for (size_t i = 0; i < count; ++i)
      if (lc(items[i].category) == c)
        os << items[i].title << " (" << items[i].year << ") $" << items[i].price << '\n';
  }
};

Practical tips: validate inputs (year/price), normalize strings for search (trim + lowercase), decide how to handle duplicate titles (reject or remove all matches), and add simple save/load (CSV) if persistence is needed. Complexity notes: add is O(1), remove/find/list are O(n) because of linear search/shift — acceptable for small collections and textbook assignments. If your assignment permits, switch to std::vector or an associative container later for easier resizing and faster lookups; otherwise this array wrapper is clear, testable, and matches an “array-based” requirement.

class Collection; // <-- pointers to Category
class Category; // <-- pointers to array dvd[] and std::string description/name
struct dvd_info {
  category* cat;
  std::string title;
  int year;
  double time, price; // <-- time in seconds, use a formatting function

  dvd_info() : cat(NULL), title("\0") { }
  dvd_info( cat *c, std::string &t, int yr, double s, double m ) : cat(c), title(t), year(yr), time(s), price(m) { }
};
Class dvd {
public:
dvd_info* ret_info() { return &inf; } // edit or read from pointer
private:
dvd_info inf;
}

adding should be fairly straightforward, just add a function like this:

Categories::push( dvd_info &d ) { vector.push_back(d); }
/* or whatever container...
You could use std::map for easy use of strings (titles, categories) for searching in the collection(s) */
map.find( std::string("some movie") );
map["some movie"];

If you want more help than that, you have to post some code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.