Ask Question, Ask an Expert

+1-415-315-9853

info@mywordsolution.com

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.
Instructions

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.

Tasks

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++

1 write a c program that allows the user to create a test

1. Write a C++ program that allows the user to create a test bank of questions 2. The program should first ask the user how many questions he or she wishes to create. 3- The user should now be prompted for all informatio ...

Modules in c are called functions c programs are typically

Modules in C are called functions. C programs are typically written by combining user created functions as well as "pre-packaged" functions found in the C Standard Library. For instance, printf() is a function that is fo ...

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 ...

Computer sciencewhere do you think c and coding games in c

Computer Science Where do you think C++ and coding games in C++ is headed in the next five years? How about in the next 10 years? Do you think there are any significant improvements that need to be made to the code to en ...

Object-oriented programming assignmentintroduction -nbspa

Object-Oriented Programming Assignment Introduction -  "A logical matrix or (0, 1) matrix is a matrix with entries from the Boolean domain B = {0, 1}. Such a matrix can be used to represent a binary relation between a pa ...

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 ...

Computer scienceyou have gathered your information on the

Computer Science You have gathered your information on the AI for the Tic-Tac-Toe game and began to develop your own ways to improve it using C++. Now, it's time to present your findings in a final paper. Remember that y ...

Assignmentthis assignment gives you the opportunity to

Assignment This assignment gives you the opportunity to practice array of pointers, linked lists and self referential structures. Write a program that initializes two parallel arrays as follows: char * String[] = { "Abbi ...

1 three employees in a company are up special pay increase

1. Three employees in a company are up special pay increase. You are given a file, with the following data: Miller Andrew 65789.87 5 Green Sheila 75892.56 6 Sethi Amit 74900.50 6.1 Each input line consists of an employee ...

Assignmentthis is the programthis program will use 2

Assignment This is the program: This program will use 2 different data structures to perform the same tasks; a vector and a dynamically sized array Write a complete C++ program that will: Declare a vector of integers wit ...

  • 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