STUDENT PRORGAMMER NEEDING HELP GETTING STARTED WITH A PROGRAM USING A CLASS.

I am writing a program for class and i need help. The instructions say; 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 anew 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. This is due Tuesday by midnight And I have started writing and rewriting this program so much that now I am confused as to what to do.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 #include <iostream>
  using namespace std;

class Heading                                                       //Class declaration.
{
     private:
        string companyName;                                        // 2 member variables.
        string reportName;

     public:
    Heading(string companyName, string reportName)           // 2 Parameter default with default argument.
 {
   cout << "ABC Industries" << endl;
   cout << "Report" << endl;
}

}; 
 


Am I headed in the correct direction?
Last edited on
Well first off, the class needs a closing brace with a semi-colon at the end.

Here's a start:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <string>
using namespace std;

class Heading
{
	private:
		string companyName;
		string reportName;
	public:
		Heading(const std::string compName = "ABC Industries", const std::string reportName = "Report")
		{
			// Add code
		}
		
		// Prints company
		void PrintCompany()
		{
			// Add code
		}
		
		// Prints report
		void PrintReport()
		{
			// Add code
		}
		
		// Prints both
		void Print()
		{
			// Add code
		}
 };


Now it should be fairly straightforward. I can't do any more without doing the homework for you. (I'd argue I already did...)
Last edited on
I can't do any more without doing the homework for you. (I'd argue I already did...)

At least you did omit to mention the class member initializer list. http://en.cppreference.com/w/cpp/language/initializer_list

oops...


I do hope that the next assignment requires separation of definition and implementation to their own files.
i added some code to it after you commented but before I saw you comment Avilius. I didn't do it quit like you did but it is starting to look similar to yours.
Last edited on
1
2
3
4
5
Heading(string companyName, string reportName)           // 2 Parameter default with default argument.
{
   cout << "ABC Industries" << endl;
   cout << "Report" << endl;
}

This is wrong. Pretty much the only way to do this is:
1
2
3
4
		Heading(const std::string compName = "ABC Industries", const std::string reportName = "Report")
		{
			// Add code
		}
As mentioned above.
Last edited on
Or rather:
1
2
3
Heading( const std::string compName = "ABC Industries",
         const std::string reportName = "Report" ) // Add code here
{ }
Topic archived. No new replies allowed.