/*
* \file main.cpp
* \author CS 70 Provided Code
* \brief Creates and interacts with some Cows.
*/
#include <iostream>
#include "cow.hpp"
using namespace std;
int main() {
Cow bessie{3, 12};
const Cow mabel{1, 2};
// This line wouldn't work!
// Cow duke;
bessie.moo(1);
mabel.moo(2);
bessie.setAge(4);
// This line wouldn't work!
// mabel.setAge(2);
return 0;
}
/*
* \file cow.hpp
* \author CS 70 Provided Code
* \brief Interface definition for the Cow class.
*/
#ifndef COW_HPP_INCLUDED
#define COW_HPP_INCLUDED
#include <iostream>
#include <fstream>
/*
* \class Cow
* \brief Knows how many spots it has and how old it is. Can moo.
*/
class Cow {
public:
// We can only have a Cow if we know
// how many spots it has and how old it is
Cow(int numSpots, int age);
Cow() = delete;
// Moo the right number of times.
void moo(int numMoos) const;
// Accessor member functions
int getNumSpots() const;
int getAge() const;
// Mutator member functions
void setNumSpots(int numSpots);
void setAge(int age);
private:
// Per-cow data
int numSpots_;
int age_;
};
#endif // ifndef COW_HPP_INCLUDED
/*
* \file cow.cpp
* \author CS 70 Provided Code
* \brief Implements the Cow class
*/
#include <cstddef>
#include <iostream>
#include "cow.hpp"
using namespace std;
Cow::Cow(int numSpots, int age)
: numSpots_{numSpots},
age_{age}
{
cout << "Made a cow with " << numSpots_ << " spots!" << endl;
}
void Cow::moo(int numMoos) const {
for (int i = 0; i < numMoos; ++i) {
cout << "Moo! ";
}
cout << endl;
}
int Cow::getNumSpots() const {
return numSpots_;
}
int Cow::getAge() const {
return age_;
}
void Cow::setNumSpots(int numSpots) {
numSpots_ = numSpots;
}
void Cow::setAge(int age) {
age_ = age;
}