-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInheritance3.cpp
More file actions
63 lines (53 loc) · 1.24 KB
/
Inheritance3.cpp
File metadata and controls
63 lines (53 loc) · 1.24 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
Author: CWN221
Date: 24/10/2024
Description: Demonstrating concept of Inheritance in C++
RegNo: BSE-01-0032/2024
*/
#include <iostream>
using namespace std;
class Movie {
protected:
string title;
string director;
int duration;
float rating;
public:
//Constructor
Movie(string tte, string dir, int dur, float rtg){
title = tte;
director = dir;
duration = dur;
rating = rtg;
}
//Display
void display() {
cout<<"Title: " << title << endl;
cout<<"Director: " << director << endl;
cout<<"Duration(minutes): " << duration << endl;
cout<<"Rating: " << rating << endl;
}
//Function for rating movie
void rateMovie(float rate) {
if (rate >= 1.0 && rate <= 5.0) {
rating = rate;
} else {
cout<<"Invalid rating"<<endl;
}
}
};
int main()
{
Movie play("Inception", "Christopher Nolan", 148, 4.8);
//Display the results of the movie
play.display();
//Updating rate
cout<<"\nUpdated rating;\n"<<endl;
play.rateMovie(5.0);
play.display();
//Test to show invalid rating
cout<<"\nTest to show invalid rating;\n"<<endl;
play.rateMovie(6.0);
play.display();
return 0;
};