Help with an assigment

Hi.

I am a real beginner that really want to learn and i am not asking you to do my assignment but only to refer me to what i should use.

The assignment is to create a class named Film. A film is described by two textstrings named title and type. For example, DVD och Bluray.

There is to be a menu that handles the films. There is going to be possible to register new films, print list of films, search for films and exit program.

And then it contains a tip, create a vector that makes it possible to store the movies during running.

Sorry if there is bad spelling or lanuage, but i am Swedish.
Well, your code's baseline should look as follows:

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
#include <iostream>

struct Film {
    // Insert the per-film data here
};

void AddFilm(std::vector<Film>& Vector)
{
    Film newFilm;
    // Ask user about the new film's information
    // and store them in newFilm
    Vector.push_back(newFilm); // Send the new film with the others
}

void FindFilm(const std::vector<Film>& Vector)
{
    std::string FilmToFind;
    std::getline(std::cin, FilmToFind); // Get the film to look for

    // The following 'for' loop, checks all Vector elements for something.
    // The currently checked element is 'Vector[i]', and all elements
    // will be checked because 'i' increments every time until it reaches
    // the value of Vector.size().
    for(unsigned int i = 0; i < Vector.size(); ++i)
    {
        if(Vector[i].Name == FilmToFind)
        {
            // Found one!
        }
    }
}

void ListAllFilms(const std::vector<Film>& Vector)
{
    for(unsigned int i = 0; i < Vector.size(); ++i)
    {
        // Print each film's data, using Vector[i] as the current film, example:
        cout << Vector[i].Name;
    }
}

int main()
{
    while(1)
    {
        // Ask for User Action, and call ListAllFilms or AddFilm or FindFilm accordingly
        // If user wants to quit, use 'break;'.
    }
}


Also, are you going to use a GUI or the Console?
Last edited on
Pure console. Should i save films as strings or chars? Thank you very very very much. This is exactly what i needed. There is a crashcourse im taking, the step from assignment 2 to 3 were gigant to say the least.
I think you should use strings.
Beware using cin in the common way, it only 'grabs' a single word.
You have an example in my code that shows you how to grab the complete line.

Example:

1
2
3
4
5
6
7
8
9
10
// chars:
char FilmName[512] = {0};
cin >> FilmName; // User inputs "Saw 3"
// FilmName is "Saw". "3" is ignored and goes to the next cin.
// If user inputs more than 512 character, program crashes.

// strings:
std::string FilmNameStr;
std::getline(std::cin, FilmNameStr); // User inputs "Saw 3"
// FilmNameStr is "Saw 3". On a big input, the string will resize itself. 
Last edited on
Topic archived. No new replies allowed.