Working on a program using classes:
I cannot figure out to write my default constructor.
Report Heading- uses a class named Heading that has 2 data
members. There is a 2-parameter default constructor allows for theses to be specified
at the a new Heading object is created. If the user creates a Heading object without
passing any arguement, the default for company name will be "ABC Industries and the
default for the report name will be "Report",
*/
#include <iostream>
usingnamespace std;
//Class declaration.
class Heading
{
private:
// 2 member variables.
string companyName;
string reportName;
public:
void displayHeading (string, string);
string getNames();
//Member fubctions:
/**********************************************************
* Heading::displayHeading *
* This function will display the heading with company *
* name on the first line and the report name name on the *
* secomd line. *
**********************************************************/
void Heading::displayHeading(string, string)
{
cout << companyName << endl;
cout << reportName << endl;
}
/***********************************************************
* Heading::getNames *
* This function will retrieve the names of the compANY and *
* the name of the report. If no name is provided for either*
* a default name will print. *
***********************************************************/
string Heading::getNames(string, string)
{
cout << "Company Name: ";
cin >> companyName;
cout <<"Report Name: ";
cin >> reportName;
}
};
int main ()
{
//Object created.
Heading heading;
//Gets names from the user.
string getNames();
//Displays the company heading.
void displayHeading();
system ("pause");
return 0;
}
Hmmm! I see we have a long way to go as you calling a function by creating it over again in your main, and manipulating/assigning values for that function inside your class.
//Class declaration.
class Heading
{
private:
// 2 member variables.
string companyName;
string reportName;
public:
void displayHeading (string, string);
string getNames();
}; //Your done with your class right here <<<<<<<---------------------------------------------
//Member fubctions: <<<<<<<<<-----------------------------------------------------------
/**********************************************************
* Heading::displayHeading *
* This function will display the heading with company *
* name on the first line and the report name name on the *
* secomd line. *
**********************************************************/
void Heading::displayHeading(string, string)
{
cout << companyName << endl;
cout << reportName << endl;
}
/***********************************************************
* Heading::getNames *
* This function will retrieve the names of the compANY and *
* the name of the report. If no name is provided for either*
* a default name will print. *
***********************************************************/
string Heading::getNames(string, string)
{
cout << "Company Name: ";
cin >> companyName;
cout <<"Report Name: ";
cin >> reportName;
}
// --------------------------Now for main----------------------------
int main ()
{
//Object created.
Heading heading;
//Gets names from the user.
//string getNames(); <<<<<<<<<<<<<You not calling the function this way
heading.getNames(); <<<<<<<<<<<This is how you call it. do the same for below
/*Note when you created getNames() at the top you not passing parameters yet on
line 39 you have string heading::getNames(string, string)
*/
//Displays the company heading.
void displayHeading();
system ("pause");
return 0;
}
I am getting error on line 38 - 41 on the couts << it says there is no such operator as << and error on the dot operator in heading.getNames in line 52.