2018年7月29日 星期日

Add more public methods to an existing class


/* Dog.h */

#ifndef __DOG_H__
#define __DOG_H__
#include <string>
using namespace std;

class Dog {
private:
    string name;
    int age;
public:

    string get_name() {return name; }
    void set_name(string n) {name = n; }
    int get_age() {return age; }
    void set_age(int a) { age = a;}
    //---- WRITE YOUR CLASS FUNCTIONS BELOW THIS LINE----
    int get_human_years();
    string speak();
   
    //---- WRITE YOUR CLASS FUNCTIONS ABOVE THIS LINE----
};
#endif

========================================

/* exercise.cpp */

// THIS FILE IS EMPTY----
#include "Dog.h"

int Dog::get_human_years(){return  7*age;}
std::string Dog::speak(){
        return "Woof";
    }

沒有留言:

張貼留言