0% found this document useful (0 votes)
42 views3 pages

CS202: Programming Systems: LAB 4: Inheritance

The exercises are designed to

Uploaded by

adminsvth
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views3 pages

CS202: Programming Systems: LAB 4: Inheritance

The exercises are designed to

Uploaded by

adminsvth
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CS202: Programming Systems

LAB 4: Inheritance
Instructor: Hunh Cng Php Affiliation: IT Faculty, Danang University of Technology Implement the following exercises with C++ and Java 1. Declare the GreatPoint class as a class that extends MyPoint, the given class. You should declare in the GreatPoint class the method distance() that calculates the distance of the point from (0,0) and check it using the given application.
#include <stdio.h> #include <math.h> #include <conio.h> class MyPoint { private: double x; double y; public: MyPoint() { } MyPoint(double a, double b) { x=a; y=b; } double getX() { return x; } double getY() { return y; } void setX(double xVal) { x = xVal; } void setY(double yVal) { y = yVal; } }; class GreatPoint: public MyPoint { public: GreatPoint(double xVal, double yVal):MyPoint(xVal,yVal)

{ } double distance() { return sqrt(getX()*getX() + getY()*getY()); } }; main() { GreatPoint gp(12,24); printf("The distance of gp from (0,0) is %f", gp.distance()); getch(); }

2. Declare the following classes: The Shape class (abstract), that contains two abstract methods: area and perimeter The Rectangle class, that extends Shape, describes a simple rectangle. The Circle class, that extends Shape, describes a simple circle. 3. Create a Employee class including following members Data members char *name int age float hourRate Employee name Employee age Rate per hour Functions Employee(char *nameVal, int age, float hourRateVal) float salary(float hours); void display() Constructor abstract method, caculating salary for a employee display detailed employee information Description Description

Then, create the following classes: The Manager class, that extends Employee, describes a manager. The Clerk class, that extends Employee, describes a clerk. Define in each one of these classes all the needed methods and constructors and check them using the given application. Notice: The formulas calculating: salary for a Manager = hours * hourRate * 2.0 salary for a Clerk = hours * hourRate * 1.2

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy