I've written a program to display a company's name and report name, however, I need to make it so that if someone does not enter anything the program displays two default names. I need to add a constructor with 2 parameters. I find that I'm confusing myself, and getting more and more lost. I've tried making my code look like that of the textbook example, but to no avail. Could someone please give me some pointers and a direction?
I am using C++ in Microsoft Visual Studios Express 2012, and here is my current code.
//This program displays a company's name and report.
#include <iostream>
#include <string>
using namespace std;
class Heading
{
private:
string company;
string report;
public:
void storeInfo (string c, string r);
string getCompany()
{
return company;
}
string getReport()
{
return report;
}
};
void Heading::storeInfo(string c, string r)
{
company = c;
report = r;
}
void storeInfo(Heading&);
void showInfo(Heading);
int main()
{
Heading company;
storeInfo(company);
showInfo(company);
cin.ignore();
cin.get();
return 0;
}
/*****storeInfo*****/
void storeInfo(Heading &item)
{
string company;
string report;
cout << "\nPlease enter the company name.\n";
getline(cin, company);
cout << "\nPlease enter the report name.\n";
getline(cin,report);
item.storeInfo(company, report);
}
/*****showInfo*****/
void showInfo(Heading item)
{
cout << item.getCompany() << endl;
cout << item.getReport();
}