Hi there just doing some work where i need to produce a database in C++ for DVD now I have done most of it but I’m stuck on some bits. I have split the database up into different files but I will post the files which are important. I just need help on how to do a search function. I got told it’s called "Bubble search" and then a delete function which i think is called "Vector delete". Thank you for your time.
P.S its a simple program so don’t laugh :P. Not the best programmer
My header file
Code:
#ifndef DVD_DB_H
#define DVD_DB_H
#include "dvd.h"
#include <vector>
class dvdDB
{
private:
std::vector<DVD> dvds; // A container that contains an arry of DVDs
public:
void insert();
void list();
void listArtist();
void deleteDVD();
void fileLoad();
void fileSave();
};
#endif
My file for the header
Code:
#include "dvdDB.h" //Calls the header file
#include <iostream.h>
void dvdDB::insert() // First function for inserting a DVD
{
std::string title, artist, category; //Variables
int year; //Variable
std::cout << "Please enter the title of the DVD: ";
std::cin >> title;
std::cout << std::endl;
std::cout << "Please enter the year: ";
std::cin >> year;
std::cout << std::endl;
std::cout << "Please enter the artist: ";
std::cin >> artist;
std::cout << std::endl;
std::cout << "Please enter category";
std::cin >> category;
std::cout << "DVD has been stored...";
std::cout << std::endl;
dvds.push_back(DVD(title, year, artist, category)); //Will give a new slot for a new DVD
}
void dvdDB::list() //Will list the DVD
{
for(int i = 0; i < dvds.size(); i++) //Loop to display all my DVD which has been stroed
{
dvds[i].display();
}
}
void dvdDB::listArtist() //Will list all the DVD by artist
{
for(int i = 0; i < dvds.size(); i++)
{
dvds[i].display();
//bubble sort
}
}
void dvdDB::deleteDVD() //Will delete DVD
{
int i
list();
std::cout <<"Enter the number for the DVD to be deleted";
std::cin >> i;
//use vector function called 'delete'.
}
My other Header file
Code:
#ifndef DVD_H
#define DVD_H
#include <string>
class DVD
{
private:
std::string _title;
int _year;
std::string _artist;
std::string _category;
public:
DVD(std::string t, int y, std::string artist, std::string c);
void display(); //Will display things like name, year etc.
};
#endif //Make sure that the class will not play twice. Just once!
Code:
#include "dvd.h"
#include <iostream.h>
DVD::DVD(std::string t, int y, std::string a, std::string c):
_title(t), _year(y), _artist(a), _category(c)
{
}
void DVD::display()
{
std::cout << "Title" << _title;
std::cout << "Year" << _year;
std::cout << "Aritst" << _artist;
std::cout << "Category" << _category;
}
I just need help to implement the last bits to the codes. Thank you