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 :)
#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'.
}
#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!
There is no such thing. Perhaps you mean linear search. That's just checking every element until you find the right one, which is what std::find does: http://www.cplusplus.com/reference/algorithm/find/
Were you told that it's similar to a BUBBLE SORT where your data is first sorted usinga really basic, slow, but useful binary sort, which is then easier to search?
It's more FYI, but thought that it would help explain the 'bubble search' question.