c++
C++ CLASSES and objects
DO ADD COMMENTS
DISPLAY OUTPUT
First make three files: episode.cpp, episode.h andRun.cpp to
separate class header and implementation.
In this program, we are going to create a small scale Telivision Management System.
A)
Create a class Episode with following variables:
char* episode_name, char* episode_venue, char episode_date[22] and
char episode_time[18].
Input format for episode_date: dd-mm-yyyy
Input format for episode_time: hh:mm am/pm
B)
Implement default constructor and overloaded constructor. Print
“Default Constructor Called” and “Overloaded Constructor Called” in
the respective constructors. The declaration for overloaded
constructor is as follows:
Episode(char episode_name[200], char episode_venue[100], char
episode_date[22],char episode_time[18]);
C)
Implement all setters and getters for class Episode. You can create
a helper function userInput() to input episode details.
D)
Implement the destructor ~Episode() for class Episode. Print
“Destructor Called” in the destructor. Deallocate all the
dynamically allocated memory of class data members.
E)
Maintain an array of four Episode objects in theRun.cpp. i.e.
Episode* episode = new Episode[4];
F)
Implement addEpisodeOver() function. This function will add a new
Episode object to the episode object array using overloaded
constructor.
G)
Implement addEpisodeSet() function. This function will add a new
Episode object to the episode object array using setters.
H)
Implement displayEpisodes() function. This will display all episode
currently present in the episode object array. You can use getters
in this function.
I)
Implement a menu program inRun.cpp.
example Menu Program:
Menu Program
Add New Episode Using Overloaded Constructor: Enter 1
Add New Episode Using Setters: Enter 2
Display All Episodes: Enter 3
Exit: Enter 0
Enter your choice: 1
Add New Episode
Enter episode name: NATIONAL GEOGRAPHICS
Enter episode venue: HBO
Enter episode date: 17-12-2022
Enter episode time: 9:30 PM
N.B:
Deallocate all dynamically allocated memory.
Do not use copy constructor.
Do not use strcpy() function. Copy the character array manually
where needed based on ending ‘\0’ character.
Follow all the code indentation, naming conventions and code
commenting guidelines.
fullfill all the requirement of program by implementing all the parts
This is all the function details
/*----------------------------
File Name: episode.h
----------------------------*/
//class declaration
#include <string>
class episode
{
private :
char episode_name[200];
char episode_venue[100];
char episode_date[22];
char episode_time[18];
public:
episode();
episode(char episode_name1[200], char episode_venue1[100], char episode_date1[22],char episode_time1[18]);
void set_method(char episode_name1[200], char episode_venue1[100], char episode_date1[22],char episode_time1[18]);
void display();
std::string get_episode_name();
std::string get_episode_venue();
std::string get_episode_date();
std::string get_episode_time();
~episode();
};
file 2
/*--------------------------
File Name:- episode.cpp
---------------------------*/
//imported library
#include<string>
#include<cstdio>
#include<bits/stdc++.h>
#include"episode.h"
//default constructor
episode:: episode()
{
this->episode_name[0]='\0';
this->episode_venue[0]='\0';
this->episode_date[0]='\0';
this->episode_time[0]='\0';
}
//parametrized constructor
episode :: episode(char episode_name1[200], char episode_venue1[100], char episode_date1[22],char episode_time1[18])
{
strncpy(episode_name,episode_name1,200);
strncpy(episode_venue,episode_venue1,100);
strncpy(episode_date,episode_date1,22);
strncpy(episode_time,episode_time1,18);
}
//set methods to invoked details
void episode :: set_method(char episode_name1[200], char episode_venue1[100], char episode_date1[22],char episode_time1[18])
{
strncpy(episode_name,episode_name1,200);
strncpy(episode_venue,episode_venue1,100);
strncpy(episode_date,episode_date1,22);
strncpy(episode_time,episode_time1,18);
}
//function to return private value
std::string episode:: get_episode_name() {return episode_name;}
std::string episode::get_episode_venue() {return episode_venue;}
std::string episode::get_episode_date() {return episode_date;}
std::string episode::get_episode_time() {return episode_time;}
//destructor
episode:: ~episode()
{
}
file number 3
/*-------------------------------
FILE NAME : Run.cpp
--------------------------------*/
//imported library
#include<bits/stdc++.h>
#include"episode.h"
using namespace std;
//main function start
int main()
{
string str1,str2,str3,str4;
char name[200],venue[100],date[22],time[18];
episode epi[4];//("National Geographics","HB0","17-12-2022","9:30 PM");
for(int i=0;i<4;i++)
{
cout<<"Enter details number : "<<i+1<<endl;
cout<<"Enter episode name : "<<endl;
getline(cin,str1);
cout<<"Enter venue name : "<<endl;
getline(cin,str2);
cout<<"Enter date : "<<endl;
getline(cin,str3);
cout<<" Enter time : "<<endl;
getline(cin,str4);
strcpy(name, str1.c_str());
strcpy(venue, str2.c_str());
strcpy(date, str3.c_str());
strcpy(time, str4.c_str());
epi[i].set_method(name,venue,date,time);
}
cout<<"---------------------------------"<<endl;
cout<<"EPISODE DETAILS :: "<<endl;
cout<<"---------------------------------"<<endl;
for(int i=0;i<4;i++)
{
cout<<"\nDetail number :: " <<i+1<<endl;
cout<<"------------------------------"<<endl;
cout<<"episode name : "<<epi[i].get_episode_name()<<endl;
cout<<"Venue name : "<<epi[i].get_episode_venue()<<endl;
cout<<"Date details : "<<epi[i].get_episode_date()<<endl;
cout<<"time details : "<<epi[i].get_episode_time()<<endl;
}
return 0;
}
if you have g++ terminal
then for run type g++ Run.cpp episode.cpp for compilation
and run ./a.out
then enter your necessary details
then return method invoked will return your details
//output
Get Answers For Free
Most questions answered within 1 hours.