Solved

inheritance in c++

Posted on 1998-12-28
6
202 Views
Last Modified: 2010-04-02
/*******************************************************
 * These are the .h files for the question given by the textbook authors to
 * exercise 9.13 of Deitel & Deitel.  
 *******************************************************/

// P9_13.H
#ifndef P9_13_H
#define P9_13_H
#include <iostream.h>
 
class Point {
   friend ostream &operator<<(ostream&, const Point&);
public:
   Point(double = 0, double = 0);
   void setPoint(double, double);
   void print(void) const;
   double getX(void) const { return x; }
   double getY(void) const { return y; }
private:
   double x, y;
};
 
#endif
//*******************************************************
// P9_13Q.H
#ifndef P9_13Q_H
#define P9_13Q_H
#include "p9_13.h"
 
class Quadrilateral {
   friend ostream &operator<<(ostream&, Quadrilateral&);
public:
   Quadrilateral(double = 0, double = 0, double = 0, double = 0, double = 0,
                 double = 0, double = 0, double = 0);
   void print(void) const;
protected:
   Point p1;
   Point p2;
   Point p3;
   Point p4;
};
 
#endif
//*******************************************************
// P9_13T.H
#ifndef P9_13T_H
#define P9_13T_H
#include "p9_13q.h"
 
class Trapazoid : public Quadrilateral {
   friend ostream& operator<<(ostream&, Trapazoid&);
public:
   Trapazoid(double = 0, double = 0, double = 0, double = 0, double = 0,
             double = 0, double = 0, double = 0, double = 0);
   void print(void) const;
   void setHeight(double h) { height = h; }
   double getHeight(void) const { return height; }
private:
   double height;
};
 
#endif
//********************************************************
// P9_13PA_H
#ifndef P9_13PA_H
#define P9_13PA_H
#include "p9_13q.h"
 
class Parallelogram : public Quadrilateral {
   friend ostream& operator<<(ostream&, Parallelogram&);
public:
   Parallelogram(double = 0, double = 0, double = 0, double = 0,
                 double = 0, double = 0, double = 0, double = 0);
   void print(void) const;
private:
   // no private data members
};
 
#endif
//********************************************************
// P9_13R.H
#ifndef P9_13R_H
#define P9_13R_H
#include "p9_13pa.h"
 
class Rectangle : public Parallelogram {
   friend ostream& operator<<(ostream&, Rectangle&);
public:
   Rectangle(double = 0, double = 0, double = 0, double = 0,
             double = 0, double = 0, double = 0, double = 0);
   void print(void) const;
private:
   // no private data members
};
 
#endif
//********************************************************
// P9_13S.H
#ifndef P9_13S_H
#define P9_13S_H
#include "p9_13pa.h"
 
class Square : public Parallelogram {
   friend ostream& operator<<(ostream&, Square&);
public:
   Square(double = 0, double = 0, double = 0, double = 0,
          double = 0, double = 0, double = 0, double = 0);
   void print(void) const { Parallelogram::print(); }
private:
   // no private data members
};
 
#endif


0
Comment
Question by:delltrotter
6 Comments
 

Author Comment

by:delltrotter
ID: 1181151
i am new to c++ and have just started classes and inheritance
i am using borland c++ builder and i was wondering does anyone know how to set up a project properly as when i tried to run the abive program it was unable to link any of the headerfiles

0
 
LVL 1

Expert Comment

by:The_Brain
ID: 1181152
Is this an assignment by chance?
0
 

Author Comment

by:delltrotter
ID: 1181153
yes but i have it done i only want to know how to run it
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 10

Accepted Solution

by:
viktornet earned 50 total points
ID: 1181154
Are you sure you are using Borland C++ Builder (it's for Windows)??? Is that what you are using... or is it simply a compiler for DOS?? Anyway, you should #include all the header files that you need...

exampe....

#include "MyHeaderFile.h"
if the header file is in your INCLUDE folder then you use
#include <MyHeaderFile.h>

YOu usually have to show the full path.. I don't know about all the compilers, but that's the way mine works.. (it's an old one for DOS)....

If you are using Borland C++ Builder then you should create a folder and out all the files from your project there... Then you put all the header files at the same folder, and do this///

#include "myheaderfile.h"

for each of the header files that you have...

Hope this helps...

-Viktor
--Ivanov
0
 
LVL 22

Expert Comment

by:nietod
ID: 1181155
Unfortunately, I am away from home now so I don't have builder with me.  But you want to create a "win32 console project" for this.  A "win32 console program" is like a DOS program or like a program that standard C++ was designed to run as.  It has a standard output device (the screen) and a standard input device (the keyboard) that work like standard C++ requires.  A windows GUI program (the other type of program that can be created by builder) does not have these standard devices and thus will not compile stnadard C++ code.

If I remember correctly the way to create a win32 console project is a little missleading.  I think you with want to selected like a windows GUI icon and then under there select a win32 console icon.


I hope that helps.
0
 

Author Comment

by:delltrotter
ID: 1181156
I just finished the question .Thanks to all who replied and
"A happy new year to all".
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SendMessage fails while PostMessage works 2 107
thread-safe code in c++ 2 84
Better understanding on C++ Class serialization and formats 9 60
White board coding practice 3 80
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now