I am trying to make a program that can register new information and acces it on demand.
For exampel, i need to have a menu for accessing stored movies (format and title).
need to be able to store new movies,
search for movies and then be able to exit the program.
And my problem is that i am having a hard time understanding how to use vectors for exampel and i don't really understand what everything does.
#include <string>
#include <iostream>
#include <vector>
struct Movies
{
public:
Movies()
{
MovieName = "[ERROR] NAME NOT SET";
}
Movies(std::string name)
{
MovieName = name;
}
void HelloMoviez()
{
std::cout << "Haider, I am movie " << MovieName << std::endl;
}
private:
std::string MovieName;
};
int main()
{
std::vector<Movies> MovieList;
Movies Movie1("Legoluniuminus");
Movies Movie2;
MovieList.push_back(Movie1); // add the movie to the end of the vector
MovieList.push_back(Movie2);
MovieList[0].HelloMoviez(); // access the movie like an array, this is Movie1
MovieList[1].HelloMoviez(); // Movie2
return 0;
}
Huh?! Apparently his compiler has a lot of warning flags set or is brain dead because it says errors are } { and nothing. :-/ But I agree, how do you get a error in line 69 for a 41 line code file? :-/
The code as it is obviously cannot link because it does not have an entry point like main(), so if it was probably created by the IDE and copy pasted there line numbers are not the same.
I thought about that, but I've used a lot of IDEs and I've never seen one give the code 28 extra lines in the code. Don't know though, guess we will see :).
i tried answering yesterday but could not access this page.
anyhow, i am using Dev-C++ 4.9.9.2.
When i press line 69 it points to 29.
17 invalid token
17 expected constructor, destructor, or type conversion before '<' token
17 expected `,' or `;' before '<' token
(no number) In function `int main()':
69 redefinition of `int main()'
29 `int main()' previously defined here
well, i got it to compile now.
allthough i have no clue on how to actually add movies and being able to search for the movies.
since this code did nothing more than show two "movies"
That's because its nothing more than an example on how vectors work, what you're trying to is fairly hard, you'll need to look into sorting algorithms like bubble sort and quick sort, plus if you want to launch a program to watch the movie you'll need to run an external media player with arguments
start small, not big, or you will just get discouraged and stop programming.
You wouldn't have been given this assignment unless you had previous programming knowledge, your teacher should have explained some parts of this already, using vectors and classes are pretty basic stuff you should learn within the first two months.
this guy has made over 60 videos and they are a really good introduction to c++, I suggest you go back to basics and follow it from the start, make sure that you code while you watch, watching isn't good enough.
well, i am actually going through "programming" class faster than you would.
i have only been using c++ for 3 weeks and 2 assignments and now i got this.
why? well i have one week per assigment and i am obviously late with this one.
and just to point it out, i can not change the pace i am studying in.
so i have to pretty much code this and another one which i have not seen yet until friday. with my limited skills, and the school don't care about me not knowing and i can not talk to the teachers since i am doing tmy studying online.
so i am alone with this :P
thats why i am cowering for help
of course you can change the pace your studying, study more, or better yet, code more, instead of wasting your time asking us to do your homework which isn't allowed on these forums.