Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
44 views
in Programming by (25 points)
Private Members:

Playid integer

Playtitle 20 character

Duration float

Rating float

Public functions:

A constructor to initialise  duration as 60 and rating as 3.5

Inp() to accept the full data

Opt() to display the full data

Please log in or register to answer this question.

1 Answer

0 votes
by (13.8k points)
#include <iostream>
#include <string>
using namespace std;

class Play {
private:
    int playId;
    char playTitle[21]; // 20 characters + null terminator
    float duration;
    float rating;

public:
    // Constructor to initialize duration as 60 and rating as 3.5
    Play() : duration(60.0), rating(3.5) {}

    // Function to accept full data
    void input() {
        cout << "Enter Play ID: ";
        cin >> playId;

        cout << "Enter Play Title (max 20 characters): ";
        cin.ignore(); // Ignore previous newline character
        cin.getline(playTitle, 21); // Read up to 20 characters

        cout << "Enter Duration (in minutes): ";
        cin >> duration;

        cout << "Enter Rating: ";
        cin >> rating;
    }

    // Function to display full data
    void display() {
        cout << "Play ID: " << playId << endl;
        cout << "Play Title: " << playTitle << endl;
        cout << "Duration: " << duration << " minutes" << endl;
        cout << "Rating: " << rating << endl;
    }

};

int main() {
    Play play;
    play.input();
    play.display();

    return 0;
}

This code defines a class Play with private members playId, playTitle, duration, and rating. It has a default constructor that initializes duration to 60 and rating to 3.5. The input() function accepts user input for all data members, and the display() function displays all the data members.

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...