Starting from:

$20

CSCI235-Project 1: OOP - a Very Simple Class Solved

Project1 is trivial and simply a starter project to establish basic ideas of OOP and ensuring you can successfully submit to Gradescope. 

You will write 1 very simple class: Animal. Every Animal has a name, it may be domestic (or not) and it may be a predator (or not).

Implementation: 

You must separate interface from implementation (.hpp and .cpp files) and implement the class based on the following specification (FUNCTION PROTOTYPES AND MEMBER VARIABLE NAMES MUST MATCH EXACTLY). This class has only accessor and mutator functions for its private data members. Recall that accessor functions (e.g. getName()) are used to access the private data members (e.g. all getName() will do is return name_), while mutator functions give a value to the data members. Remember, you must thoroughly document your code!!! 

class Animal public members:

    Animal();

      Animal(std::string name, bool domestic = false, bool predator = false);  std::string getName() const;   bool isDomestic() const;      bool isPredator() const;     void setName(std::string name);      void setDomestic();      void setPredator();


class Animal private members:

    std::string name_;  bool domestic_;  bool predator_;

Testing: 

This project is very basic, but it is never too early to set in good debugging and testing habits. You must always implement and test your programs INCREMENTALLY!!!

What does this mean? 

Implement and test one class at a time!!!
For each class:
Implement one function/method and test it thoroughly (multiple test cases + edge cases if applicable)
Implement the next function/method and test it …

How do you do this?  

Write your own main() function to test your classes. In this course you will never submit your test program but you must always write one to test your classes.  As you implement each Animal method, instantiate objects of type Animal in main and call the method to test it is correct. Start from the constructor(s), then move on to the other functions.  You may output the return values to inspect your program’s behavior. Choose the order in which you implement your methods so that you can test incrementally (i.e. implement mutator functions before accessor functions). Sometimes functions depend on one another. If you need to use a function you have not yet implemented, you can use stubs: a dummy implementation that always returns a single value for testing (don’t forget to go back and implement the stub!!! If you put the word STUB in a comment, some editors will make it more visible so you will remember to implement it later) For example:

//******** STUB ************// bool Animal::isPredator() const

{

    return false;

}

Note: this will make much more sense as your programs become more complex, but it is very important to understand the fundamental concepts and develop good implement/test/debug habits from the very beginning.

More products