User Tools

Site Tools


notes:cprog:fall2021:projects:oop1

This is an old revision of the document!


Corning Community College

CSCS1320 C/C++ Programming

PROJECT: Object-Oriented Programming (OOP1)

Objective

Collaborate in the creation of a useful, originally-voiced informational source on the various aspects of C++ programming, specifically inheritance, and the implementation of a simple program that has and uses a class with inheritance.

Additionally, the entire class will be participating in documenting and filling out this project page. It is the responsibility of EACH class member to:

  • ask copious, clarifying questions (so you can better add content)
  • craft a coherent and organized document, with information located under pertinent headings
  • explain the fundamentals of the process, conceptual background, algorithmic approach, unrelated snippets to do things, just not the exact code for the program you have to individually create and submit.
  • to get full credit, each individual that submits must perform no fewer than 4 contributions to this document (as viewable from the wiki revision system). Failure to do so will result in documentation penalties being applied.

C++

Inheritance

Classes that inherit from another class acquire the attributes and behaviors of the class they inherit from.

Classes that inherit from another are called derived classes, child classes, or subclass. Classes that are inherited from are called base classes, parent classes, or superclasses.

A class can inherit data or functions from multiple base classes. In order to do this, we would create a class derivation list, which names the base classes. This would take the form of:

        
        class derived class: access-specifier base class
        

To inherit traits from another class use a colon after the class's declaration, followed by the name of the base class (and optionally an access specifier).

class Derived : public Base

Access Control implications

Inheriting from a base class using the public access specifier means public members of the base class will become public members of the derived class, and protected members of the base class will become protected members of the derived class. Private members of the base class will still be private.

A class with the keyword struct, and unions, will have public access by default, for their members and base classes.

Inheriting from a base class using the protected access specifier means both public and protected members of the base class will become protected members of the derived class. Private members of the base class will still be private.

Inheriting from a base class using the private access specifier means all members of the base class will become private members of the derived class.

A class with the keyword class will have private access for its members and base classes by default.

Parent-Child Relationships

The Child class is being referred to the class that inherits from another class, and the Parent class is being referred to the class that is being inherited from.

Since the Child simply inherits the properties of the Parent, one Parent can have multiple Children. Two Children of the same Parent will also have no direct relationship. Children can themselves have Children that inherit from them, creating large inheritance chains.

Parent/Child inheritance chains are a beneficial way to add specifications to classes without changing the base class functions. An example of this may be Animals→Dogs: An animal would have a size, age, living/death status, which are all properties that a dog could inherit, however, a dog could have it's own functions like fur length, temperament, so on and so forth. This could be extended by creating a dog breed class.

Each Child belongs to one Parent, and the Child needs to know the Parent to which it belongs. The construction of the Parent logically includes the construction of the Child.

Program

Write a program that creates a parent-child class structure. It can be anything, so long as you genuinely implement it and it works. A few possible examples for inspiration:

  • shape → rectangle
  • vehicle → car
  • fruit → strawberry

Be sure to make use of and follow proper conventions having public, protected, and private access control (no cheating by making everything public), and demonstrate inheritance.

Have a main() function that instantiates an instance of your chosen theme of class with inheritance, and runs that instantiated object through a range of tests demonstrating the class works as intended (likely also prompting the user to input any needed values to configure the attributes of the object).

References

Submission

I'll be looking for the following:

104:oop1:final tally of results (104/104)
*:oop1:no compiler messages, program compiles and runs without issue [26/26]
*:oop1:specified functionality is implemented [26/26]
*:oop1:project page contributions as per project specifications [52/52]

Additionally:

  • Solutions not abiding by SPIRIT of project will be subject to a 25% overall deduction
  • Solutions not utilizing descriptive why and how COMMENTS will be subject to a 25% overall deduction
  • Solutions not utilizing INDENTATION to promote scope and clarity will be subject to a 25% overall deduction
  • Solutions lacking ORGANIZATION and are not easy to read (within 90 char width) are subject to a 25% overall deduction
notes/cprog/fall2021/projects/oop1.1635977636.txt.gz · Last modified: 2021/11/03 22:13 by toverhi1