#ifndef FILM_H
#define FILM_H
#include <QString>

class Film {
  protected:
    QString title;
    double dailyRate;
  public:
    Film(QString ti,double dr);
    QString getTitle() const;
    virtual double calculateRental(int num)const;
};

class Video: public Film {
public:
    Video(QString ti,double dr,QString vt,int d);
    QString getTitle() const;
    QString getVideoType() const;
    virtual double calculateRental(int num)const;
protected:
    QString videoType;
    int discount;
};

#endif // FILM_H

Film.cpp

#include "film.h"
#include <QString>

String ti,double dr){
  title=ti;
  dailyRate=dr;
}

 QString Film::getTitle() const {
   return title;
}

 double Film::calculateRental(int num)const {
   return dailyRate*num;
}

 Video::Video(QString ti,double dr,QString vt,int d)
     :Film(ti,dr){


        videoType = vt;
        discount = d;
 }

  QString Video::getTitle() const {
    return title;
 }

  QString Video::getVideoType() const {
    return videoType;
 }

  double Video::calculateRental(int num)const {
    return (dailyRate*num)-discount;
 }

main.cpp

 #include <QtCore/QCoreApplication>
 #include <QtCore/QTextStream>
 #include  "film.h"

 using namespace std;

 int main(int argc, char *argv[]) {
 QCoreApplication a(argc, argv);
 QTextStream cout(stdout, QIODevice::WriteOnly);
 Film f("Top Gun", 10.00);
 // Print out title and rental fee (based on 2 days rental).
   cout << "Title: " << f.getTitle() << endl;
   cout << "Rental Fee: " << f.calculateRental(2)<<  endl;

   cout <<" " <<  endl;//blank line

 Video v("Top Gun", 10.00,"DVD",5);
 // Print out title and rental fee (based on 2 days rental).
   cout << "Title: " << v.getTitle() << endl;
   cout << "Video Type: " << v.getVideoType() << endl;
   cout << "Rental Fee: " << v.calculateRental(2) << endl;

}

how do I count the number of Film instances created? I know is something like that:

static int numOfFilms;
numOfFilms++;

how do I use the code?

yes my friend you need to create a static variable inside the class, then increment the variable when constructor is called and decrement when destructor is called. And don't forget to initialize to 0 ;

in the film.cpp or in the main.cpp?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.