Help with search function and delete

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#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!  



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#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
The vector function is called erase, not delete (delete is a reserved keyword).
See here: http://www.cplusplus.com/reference/stl/vector/erase/

I got told it’s called "Bubble search"

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/
Based on the comment on line 45 of dvdDB.h, I'd say he wants to use BubbleSort (which does exist) to assist the search.

I don't really understand how, though. Or why, for that matter.
Ah is their an easier way gaminic to find the artists?
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.
Last edited on
ye i think thats it. I was just doing some reserach. but if their is an easier way could u tell me about it?
Topic archived. No new replies allowed.