Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2cpp files and 2 .h files please Instructions Identify a two (2) real-world objects related by inheritance such as vehicle-car, building-house, computer-macbook, person-student. Then, design

2cpp files and 2 .h files please

Instructions

Identify a two (2) real-world objects related by inheritance such as vehicle-car, building-house, computer-macbook, person-student. Then, design both classes which represent each category of those objects. Finally, implement it in C++.

Class requirements

The name of the classes must be related to the category of the object such as car, vehicle, building, house, etc.

The base class must contain at least 2 attributes (member variables). These must be private.

The derived class must contain at least 2 additional attributes (member variables). These must be private.

Each attribute must have at least one accessor and one mutator. These must be public. Accessors must have the const access modifier. The accessors and mutators inherited to the derived classes may be overridden if needed.

In each class, at least one mutator must have a business rule which limits the values stored in the attribute. Examples: a) The attribute can only store positive numbers. b) The attribute can only store a set of values such as "True", "False", "NA". c) The maximum value for the attribute is 100.

Each class must have at least 2 constructors.

At least one of the derived class' constructors must call one of the base class' constructors.

Each class must have one destructor. The destructor will display "An X object has been removed from memory." where X is the name of the class.

Additional private and public member functions can be implemented if needed in the class.

Implementation

Create h and cpp files to implement the design of each class.

Format

In a PDF file, present the description of both classes. The description must be a paragraph with 50-500 words which explains the class ideas or concepts and their relationships. Also, in this document, define each class using a UML diagram.

Present the header of each class, in the corresponding .h files.

Present the source file of each class, in the corresponding .cpp files.

Submission

Submit one (1) pdf, two (2) cpp, and two (2) h files.

Example of expected submission

Activity.pdf

This class design is related to course activity. Each course activity contains a name, number of points, and due date. The number of points must be 1 or greater. The default values are "Undefined", 1, and 01-01-1970 , correspondingly.

Activity

-name: string

-points: int

-dueDate: int[3]

+setName(string n): void

+setPoints(int p): void

+setDueDate(int month, int day, int year): void

+getName() const: string

+getPoints() const: int

+getDay() const: int

+getMonth() const: int

+getYear() const: int

Activity()

Activity(string n, int p, int month, int day, int year)

~Activity()

Essay class represents a essay activity in a course. Essay class is a derived class from Activity class. A essay has a title (inherited), description, points (inherited), due date (inherited), minimum number of words, and maximum number of words. The minimum number of words must be greater than 50. It is also its default. There are no limit for the number of words. The default value of maximum number of words is 500. Always minimum number of words must be less than maximum number of words. The default for a description is an empty string.

Essay

-description: string

-min: int

-max: int

+setDescription(string d): void

+setMinWords(int m): void

+setMaxWords(int m): void

+getDescription() const: string

+getMinWords() const: int

+getMaxWords() const: int

Essay()

Essay(int n, string d, int amin, int amax, int p, int month, int day, int year)

~Essay()

Activity.h

#include  using namespace std; class Activity { private: string name; int points; int dueDate[3]; public: void setName(string n); void setPoints(int p); void setDueDate(int month, int day, int year); string getName() const; int getPoints() const; int getMonth() const; int getDay() const; int getYear() const; Activity(); Activity(string n, int p, int month, int day, int year); ~Activity(); };

Activity.cpp

#include "Activity.h" void Activity::setName(string n) { name=n; } void Activity::setPoints(int p) { if (p>=1) points=p; } void Activity::setDueDate(int month, int day, int year) { if (month>=1 && month<=12 && day>=1 && day<=31 && year>=1970) { dueDate[0]=month; dueDate[1]=day; dueDate[2]=year; } } string Activity::getName() const { return name; } int Activity::getPoints() const { return points; } int Activity::getMonth() const { return dueDate[0]; } int Activity::getDay() const { return dueDate[1]; } int Activity::getYear() const { return dueDate[2]; } Activity::Activity() { setName("Undefined"); setPoints(1); setDueDate(1,1,1970); } Activity::Activity(string n, int p, int month, int day, int year) { setName(n); if (p<1) p=1; setPoints(p); if (month<1 || month>12) month=1; if (day<1 || day>31) day=1; if (year<1970) year=1970; setDueDate(month,day,year); } ~Activity::Activity() { cout << "An Activity object has been removed from memory."; } 

Essay.h

#include  using namespace std; class Essay : public Activity{ private: string description; int min; int max; public: void setDescription(string d); void setMinWords(int m); void setMaxWords(int m); string getDescription() const; int getMinWords() const; int getMaxWords() const; Essay(); Essay(int n, string d, int amin, int amax, int p, int month, int day, int year); ~Essay(); };

Essay.cpp

void Essay::setDescription(string d) { description=d; } void Essay::setMinWords(int m) { if (m>=50 && mmin) max=m; } string Essay::getDescription() const { return description; } int Essay::getMinWords() const { return min; } int Essay::getMaxWords() const { return max; } Essay::Essay() { setDescription(""); setMinWords(50); setMaxWords(500); } Essay::Essay(int n, string d, int amin, int amax, int p, int month, int day, int year) : Activity(n,p,month,day,year) { setDescription(d); if (amin<50) amin=50; setMinWords(amin); if (amax                        

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions

Question

i need correct answrrs 2 4 2 . .

Answered: 1 week ago