Ask Question, Ask an Expert


Ask C/C++ Expert

Home >> C/C++

problem 1) Background

Encapsulation and inheritance are two major concepts of object oriented programming, which are tested in this assessment.

Encapsulation allows:

1. Bundling of data and functions together

2. Access restrictions to certain components as defined by the programmer.

Hence when you prepare a class, you place data variables (like double, int, string) at the same place as you would place functions (including the constructor too – as constructors are special types of functions that are called when the object of the class is created).

Also you define public: protected: and private: “areas”, all of which have different access restrictions. Public members can be accessed from main(), which is interpreted or seen as the “outside world”. Private members can only be accessed by class itself, i.e., only the functions of that class might access the members. Codes from main() cannot access private members of a class.

Protected members might only be accessed by the class itself, and also its child classes (through inheritance). No one else in main() can access them.

Inheritance is demonstrated through several related classes. The parent class is a more GENERAL version of a child class. This means, the child class is a more SPECIFIC version of the parent class. Always check the validity of a child class by using the “… is a …” test.

You are assessed on:

1) understanding of encapsulation in the design of your classes;

2) understanding of inheritance;

3) writing useful comments

You require to prepare a main.cpp, appropriate .h (header files) and .cpp (source files), rather than writing all classes in the same file as main.cpp.


prepare the following five classes:

Animal, Dog, Cat, PetDog, StrayDog.

These are the properties of the above classes:

• They all have a name and an age each.

• They all can speak: the Dog barks and the Cat meows. (i.e., prepare a function called speak)

• However, the StrayDog’s speak function overrides the speak function of Dog, and it should say “woof woof”.

• The PetDog performs an action: “fetch a stick”; while the StrayDog performs another action: “chase cars”.

The speak and action functions simply display the words on the console.

Show encapsulation by writing appropriate functions (including constructors) and data members for the above classes.

For ex, you should inherit protected from the parent class, and then inherit private from the child class (to the grandchild).

In your main() program,

i. declare an array of seven animal pointers;

ii. instantiate (create) at least one objects from each of the five classes;

iii. point the animal array to the objects

iv. using a suitable loop, loop through all animal references (pointers) and

a. call the speak function of each animal; (genius task:)

b. call the action function, if the animal is a petdog or a straydog.

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M95500

Have any Question? 

Related Questions in C/C++

Assignmentwhen writing c programs include comments in your

Assignment When writing C++ programs include comments in your code, make the program readable by indenting, use meaningful variable and function names, and produce meaningful output. This assignment will be to write a bm ...

1 we know that from ece 109 to calculate the

1. We know that from ECE 109, to calculate the equivalent resistance of a network of resistors in series in parallel are given by: Write a C++ program that asks the user to input values for resistors (as many as they wou ...

Assignmentgoals developing problem-solving skills declaring

Assignment Goals: Developing problem-solving skills, declaring variables, multi-way branches, data validation. Problem: Complete Programming Challenge 4.19 in your text book. Do not accept values larger than 10 meters or ...

Projectdecision statementsdirections read carefully and

Project: Decision Statements Directions (Read CAREFULLY and follow COMPLETELY): - Create the following programs in C++ that perform the purpose described and show the sample output (with user input where applicable). - I ...

Write a c program that calculates and prints the average of

Write a C program that calculates and prints the average of two or more salaries entered by the user. The program should first prompt the user to enter the number of salaries to process (make sure: at least 2 salaries mu ...

Discussionobject-oriented design please respond to the

Discussion "Object-Oriented Design" Please respond to the following: • Suppose you were required to write a C++ program that captures and stores data about automobiles that a small dealership in your city sells. Consider ...

C projectphase 11- you need to take input from user study

C project Phase 1 1- You need to take input from user study year (proper value check from 1 to 4) 2- Take input semester (proper value check 1 to 8) 3- Calculate GPA (use Loop, calculate GPA for semester 1,2,3...) Exampl ...

Discussionkeyboard versus file input please respond to the

Discussion "Keyboard versus File Input" Please respond to the following: • Suppose you are designing a C++ application that needs to capture user input specifically via a keyboard or from a file. Determine the method tha ...

C-programmingcreate a c program that sorts a sequence of

C-Programming Create a C program that sorts a sequence of positive numbers using the bubble sort algorithm in an increasing or decreasing order based on the user's choice. The pseudo code for the bubble sort algorithm is ...

Assignment part acreate a checkbook program using c

Assignment (part a) Create a Checkbook program using C : • Create a Check structure. Include:   o Check number (should be an integer).   o Date (use type char[ ]).   o To   o Amount   o Description • Add functions to:   ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Section onea in an atwood machine suppose two objects of

SECTION ONE (a) In an Atwood Machine, suppose two objects of unequal mass are hung vertically over a frictionless

Part 1you work in hr for a company that operates a factory

Part 1: You work in HR for a company that operates a factory manufacturing fiberglass. There are several hundred empl

Details on advanced accounting paperthis paper is intended

DETAILS ON ADVANCED ACCOUNTING PAPER This paper is intended for students to apply the theoretical knowledge around ac

Create a provider database and related reports and queries

Create a provider database and related reports and queries to capture contact information for potential PC component pro

Describe what you learned about the impact of economic

Describe what you learned about the impact of economic, social, and demographic trends affecting the US labor environmen