question on inheritance

Hey Guys,

I'm learning about inheritance this week in class and I have a question on how to call a derived function to do some work then the abstract function to do the rest of the work.

here is the instruction I am given
Your Employee class also has a readData function and a writeData function. These will have to be modified slightly so that the functions only read and write the data common to both hourly and salaried employees. Then write a readData and WriteData method in each derived class. The derived class functions override the functions in the base class and should only read and write the data uniquely defined in their respective class, and call the base class readData and writeData functions to take care of the data that belongs to the base Employee class.


So The abstract function is supposed to read in int, string, string, string.
The first derived function reads in double, double.
The 2nd derived function reads in double.

The file that I'm writing into gets an address when I try to call the abstract while the derived function is writing to file just fine

Parent function
1
2
3
4
5
6
7
  void Employee::writeData(ofstream& stream) const
{
	stream << employeeNumber << endl;
	stream << name << endl;
	stream << streetAddress << endl;
	stream << phoneNumber << endl;
}


Child function
1
2
3
4
5
6
void Hourly::writeData(ofstream& stream) const
{
	Employee::writeData(stream);
	stream << hoursWorked << endl;
	stream << hourlyWage << endl;
}


Driver
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Hourly h1(1, "H. Potter", "Privet Drive", "201-9090", 40, 12.00);
			Salaried s1(2, "A. Dumbledore", "Hogewarts", "803-1230", 1200);
			Hourly h2(3, "R. Weasley", "The Burrow", "892-2000", 40, 10.00);
			Salaried s2(4, "R. Hagrid", "Hogwarts", "910-8765", 1000);
		
			string temp = "";
			cout << "Please enter a name for the file you wish to create:   " << endl;
			cin >> temp;

			ofstream myOutputStream(temp);

			h1.writeData(myOutputStream);
			s1.writeData(myOutputStream);
			h2.writeData(myOutputStream);
			s2.writeData(myOutputStream);
			myOutputStream.close();			
			cout << "The file was created. ";


Output to file:
-858993460



40
12
-858993460



1200
-858993460



40
10
-858993460



1000


Where am I going wrong?
So I figured it out. I hadn't filled in the parameterized constructor for the parent class. That's why things weren't being written. xD Thanks guys for letting me ask.
Last edited on
Topic archived. No new replies allowed.