lundi 24 octobre 2016

Can't remember how to start C++

I didn't want to be the guy to ask for help on his homework on here, but it's been a few years since I last did C++ and I am just at a loss to even start this project.

I am not asking anyone to do this for me, I'm just asking for help on how/where to start and a sample so I can learn from and do it myself.

#include <iostream>
using std::cout;
using std::endl;

/*
 * A Class to hold a non-negative number. DO NOT CHANGE!!!
 */
class CounterType {
 public:
  CounterType(int count);
  void set_count(int count);
  void Increase();
  void Decrease();
  int count();
  void Output();
 private:
  int count_;
};

// Execution begins here
int main() {
  // Uncomment to test
/*
  CounterType my_count(5);
  my_count.Output();
  my_count.Increase();
  cout << "count() is: " << my_count.count() << endl;
  my_count.Decrease();
  my_count.Output();
  my_count.set_count(500);
  my_count.Output();
  my_count.set_count(-10);
  my_count.Output();
  my_count.Decrease();
  my_count.Output();
  my_count.Increase();
  my_count.Output();
*/
  // Program ends here
  return 0;
}

/*
 * A constructor to initialize your object.
 * DO NOT CHANGE
 */
CounterType::CounterType(int count) {
  set_count(count);
}

// Write Member Function Definitions Here

That is the code the teacher gave us to help us. His assignment is as follows:

Create a class named CounterType. This class is used to record a count that is a nonnegative whole number. Use the file named counter_type.cpp to help complete the class. This class will have the following features: a. An accessor function to return the current count value i. Named count b. A mutator function that sets the counter to a given value (1 parameter) i. Named set_count ii. If the value given in the parameter is incorrect (i.e. negative) set count_ to be 0 c. A function to increase the count by 1 i. Named Increase d. A function to decrease the count by 1 (Cannot decrease to a negative number) i. Named Decrease ii. If the count would decrease to a negative number, do nothing. e. A function to output the current count i. Named Output

A correctly written CounterType class should have the following output: The current count is: 5 count() is: 6 The current count is: 5 The current count is: 500 The current count is: 0 The current count is: 0 The current count is: 1

>

I think I may just not be understanding his question. I'm not sure. Please don't hate me for asking for help on homework. :/

Thank you!

Aucun commentaire:

Enregistrer un commentaire