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...
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...
C++ make a rational class that includes these members for rational -private member variables to hold...
C++ make a rational class that includes these members for rational -private member variables to hold the numerator and denominator values -a default constructor -an overloaded constructor that accepts 2 values for an initial fraction -member fractions add(), sub(), mul(), div(), less(), eq(), and neq() (less should not return true if the object is less than argument) -a member function that accepts an argument of type of ostream that writes the fraction to that open output stream do not let...
A Bookstore Application C++ Design the class Book. Each object of the class Book can hold...
A Bookstore Application C++ Design the class Book. Each object of the class Book can hold the following information about a book: title, authors, publisher, ISBN Include the member functions to perform the various operations on the objects of Book. For example, the typical operations that can be performed on the title are to show the title, set the title. Add similar operations for the publisher, ISBN , and authors. Add the appropriate constructors and a destructor (if one is...
In c++, define a class with the name BankAccount and the following members: Data Members: accountBalance:...
In c++, define a class with the name BankAccount and the following members: Data Members: accountBalance: balance held in the account interestRate: annual interest rate. accountID: unique 3 digit account number assigned to each BankAccount object. Use a static data member to generate this unique account number for each BankAccount count: A static data member to track the count of the number of BankAccount objects created. Member Functions void withdraw(double amount): function which withdraws an amount from accountBalance void deposit(double...
C++ Create a class for working with fractions. Only 2 private data members are needed: the...
C++ Create a class for working with fractions. Only 2 private data members are needed: the int numerator of the fraction, and the positive int denominator of the fraction. For example, the fraction 3/7 will have the two private data member values of 3 and 7. The following methods should be in your class: a. A default constructor that should use default arguments in case no initializers are included in the main. The fraction needs to be stored in reduced...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT