Inheritance Problem

Multi-Inheritance

Page 1 of 1

7 Replies - 861 Views - Last Post: 20 March 2008 - 09:50 AM Rate Topic: -----

#1 unclecjetdude  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 20-February 08

Inheritance Problem

Posted 20 March 2008 - 08:06 AM

Greetings, I was assigned the following problem in class, and I believe I am making a good start at it so far, the problem is: Given the following declaration for a class that represents a computer in a company's inventory, write a derived class declaration (for a class called InstallRecord) that adds a string field representing the location of the computer, and a field of the class SimpleDate that holds the installation date. The new class should provide observers for each of the new fields. It should also reimplement the Write Function. The following code for the Computer class was given here it is

class Computer
{
public:
	Computer(
		/* in */ string newName,
		/* in */ string newBrand,
		/* in */ string newModel,
		/* in */ int	newSpeed,
		/* in */ string newSerial,
		/* in */ int	newNumber);
	string GetName() const;
	string GetBrand() const;
	string GetModel() const;
	int GetSpeed() const;
	string GetSerial() const;
	int GetNumber() const;
	void Write() const;
private:
	string name;
	string brand;
	string model;
	int speed;
	string serialNumber;
	int inventoryNumber;
};



I have started making the class for InstallRecord, I have no idea what it means by a field of the class SimpleDate that holds the installation date. Here is my code for the InstallRecord Class using inheritance.

#include "Computer.h"

class InstallRecord : public Computer
{
 public:
	 InstallRecord(
		 /* in */ string newcompLocation);
	 string GetCompLocation() const;
 private:
	 string compLocation;
}



Thanks in advance for the help. Knowledge and learning is power.

Is This A Good Question/Topic? 0
  • +

Replies To: Inheritance Problem

#2 GWatt  Icon User is online

  • member icon

Reputation: 269
  • View blog
  • Posts: 3,067
  • Joined: 01-December 05

Re: Inheritance Problem

Posted 20 March 2008 - 08:17 AM

A field is a fancy term for variable. The assignment says it wants a variable of type SimpleDate. It's like asking you to declare an int.
Was This Post Helpful? 0
  • +
  • -

#3 unclecjetdude  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 20-February 08

Re: Inheritance Problem

Posted 20 March 2008 - 08:22 AM

Well I'm guessing they want me to declare SimpleDate? so are they talking about something like this, because the problem doesn't give us class SimpleDate.

Here is the re-written version of the InstallRecord Class:

#include "Computer.h"
#include "SimpleDate.h"

class InstallRecord : public Computer
{
 public:
	 InstallRecord(
		 /* in */ string newcompLocation);
	 string GetCompLocation() const;
	 SimpleDate First;
private:
	 string compLocation;
}


Was This Post Helpful? 0
  • +
  • -

#4 GWatt  Icon User is online

  • member icon

Reputation: 269
  • View blog
  • Posts: 3,067
  • Joined: 01-December 05

Re: Inheritance Problem

Posted 20 March 2008 - 08:23 AM

that would work.

[edit] although you might want to make it private.

This post has been edited by GWatt: 20 March 2008 - 08:24 AM

Was This Post Helpful? 0
  • +
  • -

#5 unclecjetdude  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 20-February 08

Re: Inheritance Problem

Posted 20 March 2008 - 08:31 AM

View PostGWatt, on 20 Mar, 2008 - 08:23 AM, said:

that would work.

[edit] although you might want to make it private.


Thanks, It's just confusing, because we're not given the SimpleDate class file. That's why I'm a bit surprised the problem is asking for that, maybe that shows up in a later part. I will keep you posted as I'm working on this, it's due before 10AM PST. But I will work on it, and get your input thanks for the help in advance.
Was This Post Helpful? 0
  • +
  • -

#6 unclecjetdude  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 20-February 08

Re: Inheritance Problem

Posted 20 March 2008 - 08:45 AM

Ok, the next steps, are to implement the constructor for the Computer class, implement the constructor for the InstallRecord class, and Implement the Write Function for the Computer class to output each member field on a seperate line, and to implement the Write Function for the InstallRecord class so that it outputs each member field on a seperate line. Assume that the SimpleDate class provides a void function called Write() that outputs the date in a standard format. When it says implement, does that mean I should make a .cpp file(s) with these classes included?
Was This Post Helpful? 0
  • +
  • -

#7 unclecjetdude  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 20-February 08

Re: Inheritance Problem

Posted 20 March 2008 - 09:21 AM

Ok given the previous code, I have written the implementation file for both Computer and InstallRecord. Both contain constructors and the write function, I have no clue on how to write the write function though, to make it display the information on seperate lines. Here's the Implementation file for Computer First:

#include "Computer.h"
#include <iostream>
#include <string>
using namespace std;

Computer::Computer(
		/* in */ string newName,
		/* in */ string newBrand,
		/* in */ string newModel,
		/* in */ int	newSpeed,
		/* in */ string newSerial,
		/* in */ int	newNumber)

//constructor

{

}

Computer::Computer()

{

}

void Computer::Write() const
{


}



And here's the implementation file for InstallRecord:
#include "InstallRecord.h"
#include <string>
#include <iostream>
using namespace std;

InstallRecord::InstallRecord(
		 /* in */ string newcompLocation)
		 : Computer( string newName, string newBrand, string newModel,int newSpeed,string newSerial,int newNumber)

{

}

InstallRecord::InstallRecord()

{

}

void InstallRecord::Write() const
{

}



Any form of help will be appreciated. Thanks!
Was This Post Helpful? 0
  • +
  • -

#8 unclecjetdude  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 20-February 08

Re: Inheritance Problem

Posted 20 March 2008 - 09:50 AM

Would anyone happen to know how this works? thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1