In: Computer Science
2. Report Heading Design a class called Heading that has data members to hold the company name and the report name. A two-parameter default constructor should allow these to be specified at the time a new Heading object is created. If the user creates a Heading object without passing any arguments, “ABC Industries” should be used as a default value for the company name and “Report” should be used as a default for the report name. The class should have member functions to print a heading in either one-line format, as shown here: Pet Pals Payroll Report or in four-line “boxed” format, as shown here: ******************************************************** Pet Pals Payroll Report ******************************************************** Try to figure out a way to center the headings on the screen, based on their lengths. Demonstrate the class by writing a simple program that uses it.
SOLUTION-
I have solve the problem in C++ code with comments and screenshot for easy understanding :)
CODE-
Code1:
#include <iostream>
#include <string>
using namespace std;
// class Heading having two members and a constructor
class Heading {
string company, report;
public:
//constructor if the user creates a object it will
envoke
//if the user don't pass the arguments then it takes
defalut values ABC Industires and Report
Heading(string a="ABC Industries",string
b="Report"){
company = a;
report = b;
}
//print1() member fucntion that
prints the output
void print1(){
cout<<company<<" "<<report<<endl;
}
};
int main()
{
// Constructor called
Heading h("Pet Pals" , "Payroll Report");
Heading h1;
h.print1();
return 0;
}
Code2:
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
// class Heading having two members and a constructor
class Heading {
string company, report;
public:
//constructor if the user creates a object it will
envoke
//if the user don't pass the arguments then it takes
defalut values ABC Industires and Report
Heading(string a="ABC Industries",string
b="Report"){
company = a;
report = b;
}
//print1() member fucntion that
prints the output
void print1(){
cout<<"***********************"<<endl;
cout<<setw(10)<<company<<endl;
cout<<setw(10)<<report<<endl;
cout<<"***********************"<<endl;
}
};
int main()
{
// Constructor called
Heading h("Pet Pals" , "Payroll Report");
//calling print1
h.print1();
return 0;
}
SCREENSHOT-
IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I
WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK
YOU!!!!!!!!----------