I have to create a structure array that contains the title, director, year made, and run time of a list of 4 movies. Then I need to create a function to display the contents of the array. Then ask the user what movie they'd like to search for. Create a function to do a linear search and then display the information for the movie or display invalid entry.
I keep getting a lot of errors in my code.
These are the most common:
movie.cpp:48: error: no matching function for call to 'Movie::Movie(const char [9], const char [10], int, int)'
movie.cpp:29: note: candidates are: Movie::Movie(int, int)
movie.cpp:23: note: Movie::Movie(const Movie&)
movie.cpp:59: error: invalid conversion from 'Movie*' to 'int'
movie.cpp:59: error: initializing argument 1 of 'Movie::Movie(int, int)'
movie.cpp:73: error: no match for 'operator[]' in 'Info[value]'
Can anyone tell me what I'm doing wrong? Why isn't the function recognizing the structure? Did I enter it in wrong?
Thanks,
ACRobison
1 #include <iostream>
2 #include <string>
3 using namespace std;
4
5 struct Movie
6 {
7 string name;
8 string director;
9 int year;
10 int time;
11
12 Movie(int y=0, int t=0)
13 {
14 year = y;
15 time = t;
16 }
17};
18
19// Function prototypes
20
21 void displayInfo(Movie);
22 int search(Movie, string &);
23 int main()
24 {
25
26 //Names and Types of Inputs
27 string value;
28 int position;
29 Movie Info[4] = { Movie("Firewall", "Loncraine", 2006, 105),
30 Movie("Crash", "Haggis", 2005, 112),
31 Movie("Breach", "Ray", 2007, 110),
32 Movie("Enchanted", "Lima", 2007, 107),
33 Movie("Star Wars", "Lucas", 2002, 120) };
34 displayInfo(Info);
35
36 cout<<"What is the name of the movie you are searching
37 for?"<<endl;
38 cin>>value;
39 position = search(Info, value);
40 if (position == -1)
41 cout << "Sorry that movie title is not in the list" << endl;
42 else
43 {
44 cout << Info[value].name <<endl;
45 cout << Info[value].director<< endl;
46 cout << Info[value].year<< endl;
47 cout << Info[value].time << endl;
48 }
49
50 return 0;
51 }
52
53 void displayInfo(Movie Info[])
54 {
55 for (int a=0; a<4; a++)
56 {
57 cout << Info[a].name <<endl;
58 cout << Info[a].director<< endl;
59 cout << Info[a].year<< endl;
60 cout << Info[a].time << endl;
61 }
62 }
63 int searchList(Movie Info[], string &value)
64
65 {
66 int index = 0; // Used as subscript to search array
67 int position = -1; // To record position of search value
68 bool found = false; // Flag to indicate if value found
69
70 // Step through the array as long as the value is not found
71 while (index < 4 && !found)
72 {
73 if (Info[index].name == value)
74 {
75 found = true; // The value is found
76 position = index; // Record the value's position
77 }
78 index++; // Go to next element
79 }
80
81 return position;
82 }