0
#include <iostream>
#include <cstring>
using namespace std;

class Film {
private:
    string name;
    int year_prod;
    string producer;
    string main_actor;

public:
    Film();
    void print()
    {
        cout << "\nThe name of movie: " << name;
        cout << "\nThe year of produced: " << year_prod;
        cout << "\nProducer: " << producer;
        cout << "\nMain actor: " << main_actor << endl;
    }
    void SetName(string xName)
    {
       name = xName;
    }

    string GetName()
    {
       return name;
    }

    void SetYearP(int xYearP)
    {
        year_prod = xYearP;
    }

    int GetYearP()
    {
        return year_prod;
    }

    void SetProducer(string xProducer)
    {
        producer = xProducer;
    }

    string GetProducer()
    {
        return producer;
    }

    void SetMaina(string xMaina)
    {
        main_actor = xMaina;
    }

    string GetMaina()
    {
        return main_actor;
    }


};


int main()
{
    Film obs[100]; // maximum of 100 hundred films
    int n;
    cout << "how many films ";
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        string name;
        int year;
        string prod;
        string actor;
        cout << "enter the film name ";
        cin >> name;
        cout << "enter the production year ";
        cin >> year;
        cout << "enter the producer name ";
        cin >> prod;
        cout << "enter the actor name ";
        cin >> actor;
        obs[i].SetName(name);
        obs[i].SetYearP(year);
        obs[i].SetProducer(prod);
        obs[i].SetMaina(actor);
    }
} 

I've done half of my code but I get errors while compiling saying: unresolved external symbol "public: __thiscall Film::Film(void)" (??0Film@@QAE@XZ) referenced in function _main AND 1 unresolved externals. I'm not sure if I had in the correct way objects of n Film from user input because I'm still a beginner in OOP.

  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Ulrich Eckhardt Apr 03 '20 at 10:52
  • Not at all :) @UlrichEckhardt –  Apr 03 '20 at 10:54
  • There is no constructor for `Film` class. – Eddymage Apr 03 '20 at 10:59

3 Answers3

1

You didn't implement your constructor:

public:
    Film();//<-- declared, but not defined.

If you don't want your constructor to do anything, just add an empty body:

public:
    Film() {};

or even better, explicitly declare it as the default-constructor:

public:
    Film()=default;
melk
  • 530
  • 3
  • 9
0

Please try this out. Hope this helps.

class Film {
...
...
...
public:
        //Film(); Remove this line if you are not defining Film()
        void print()
        {
            cout << "\nThe name of movie: " << name;
            cout << "\nThe year of produced: " << year_prod;
            cout << "\nProducer: " << producer;
            cout << "\nMain actor: " << main_actor << endl;
        }
...
...
...
}

If you want it to be a default constructor add an empty block Film(){}

0

You have to implement the constructor for your class. The constructor is the method that create an instance of the class. The set functions have the purpose to modify the attributes of an object, but the initialization of the attributes must be done in the constructor.

For example:

public:
  //default constructor: it does not take 
  //anything as input, it sets name as an 
  //empty string and the year to 1900
  Film(){
    name = "";
    year = 1900;
  }
  // It creates a Film object, whose name 
  // is NAME and whose year is YEAR
  Film(string NAME, int YEAR){
    name = NAME;
    year = YEAR;
  }

// set function which allows to modify the 
// year of a Film object.
void setYear(int newYear){
  year = newYear;
}

Have a look here for a quick introduction.

EDIT: you may want to set the default constructor as

Film(){};

In this way you have to invoke all the set functions to initialise its attributes.

Eddymage
  • 1,008
  • 1
  • 7
  • 22