Question

In: Computer Science

2. Report Heading Design a class called Heading that has data members to hold the company...

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.

Solutions

Expert Solution

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!!!!!!!!----------


Related Solutions

C++ Define a base class called Person. The class should have two data members to hold...
C++ Define a base class called Person. The class should have two data members to hold the first name and last name of a person, both of type string. The Person class will have a default constructor to initialize both data members to empty strings, a constructor to accept two string parameters and use them to initialize the first and last name, and a copy constructor. Also include appropriate accessor and mutator member functions. Overload the operators == and !=...
Write a class called Person that has two private data members - the person's name and...
Write a class called Person that has two private data members - the person's name and age. It should have an init method that takes two values and uses them to initialize the data members. It should have a get_age method. Write a separate function (not part of the Person class) called std_dev that takes as a parameter a list of Person objects and returns the standard deviation of all their ages (the population standard deviation that uses a denominator...
Write the definition for a generic class called Rectangle that has data members length and width....
Write the definition for a generic class called Rectangle that has data members length and width. The class has the following member functions: setlength to set the length data member setwidth to set the width data member perimeter to calculate and return the perimeter of the rectangle area to calculate and return the area of the rectangle show to return a text to display the length and width of the rectangle sameArea that has one parameter of type Rectangle. sameArea...
Write the definition for a generic class called Rectangle that has data members length and width....
Write the definition for a generic class called Rectangle that has data members length and width. The class has the following member functions: setlength to set the length data member setwidth to set the width data member perimeter to calculate and return the perimeter of the rectangle area to calculate and return the area of the rectangle show to return a text to display the length and width of the rectangle sameArea that has one parameter of type Rectangle. sameArea...
Write a class called Person that has two private data members - the person's name and...
Write a class called Person that has two private data members - the person's name and age. It should have an init method that takes two values and uses them to initialize the data members. It should have a get_age method. Write a separate function (not part of the Person class) called basic_stats that takes as a parameter a list of Person objects and returns a tuple containing the mean, median, and mode of all the ages. To do this,...
11. Payroll in C++ Design a PayRoll class that has data members for an employee’s hourly...
11. Payroll in C++ Design a PayRoll class that has data members for an employee’s hourly pay rate, number of hours worked of type double. The default constructor will set the hours worked and pay rate to zero. The class must have a mutator function to set the pay rate for each employee and hours worked. The class should include accessors for both the hours worked and the rate of pay. The class should lastly have a getGross function that...
c++ Design the Weather class that contains the following members: Data members to store: -a day...
c++ Design the Weather class that contains the following members: Data members to store: -a day (an integer) -a month (an integer) -a year (an integer) -a temperature (a float) -a static data member that stores the total of all temperatures (a float) Member functions: -a constructor function that obtains a day, month, year and temperature from the user. This function should also accumulate/calculate the total of all temperatures (i.e., add the newly entered temperature to the total). -a static...
C++ Assignment. Design the Weather class that contains the following members: Data members to store: -...
C++ Assignment. Design the Weather class that contains the following members: Data members to store: - a day (an integer) - a month (an integer) - a year (an integer) - a temperature (a float) - a static data member that stores the total of all temperatures (a float) Member functions: - a constructor function that obtains a day, month, year and temperature from the user. This function should also accumulate/calculate the total of all temperatures (i.e., add the newly...
In C++ Define a base class called Person. The class should have two data members to...
In C++ Define a base class called Person. The class should have two data members to hold the first name and last name of a person, both of type string. The Person class will have a default constructor to initialize both data members to empty strings, a constructor to accept two string parameters and use them to initialize the first and last name, and a copy constructor. Also include appropriate accessor and mutator member functions. Overload the operators == and...
Design a Ship class that has the following members: • A member variable for the name...
Design a Ship class that has the following members: • A member variable for the name of the ship (a string) • A member variable for the year that the ship was built (a string) • A constructor and appropriate accessors and mutators • A virtual print function that displays the ship’s name and the year it was built. Design a CruiseShip class that is derived from the Ship class. The CruiseShip class should have the following members: • A...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT