The following is a Class interface implied by client code:
Write the class definition, without a private section (as you cannot tell what would be in it), implied by the following client code. That is, create a class definition with an interface required to implement the following code. Can somebody walk me through this?
1 2 3 4 5 6 7 8 9 10 11 12
Baz foo(const Baz& tex)
{
Baz* var = new Baz(5, "This is fun!");
tex.set("This string.");
for (int i = tex.howMany(); i < Baz::MAX; ++i)
{
doc->write();
} // end for
return *doc;
} // end func
Look for all the member functions being on Baz and what parameters thy have, and add them to the interface. Then think about how you'd implement Baz::MAX.
class Baz
{
public:
//This area is for public functions/methods
// This area is also for public variables
int SomeFunctionNameHere(int someParameterHere);
float SomeMemberVariableHere;
private:
//This area is for private functions/methds
//This area is also for private variables
};
Is this the format the code should be in? Can somebody help fill this in, this code makes no sense to me, I haven't seen anything like this before!
He's asking for the class interface. Without any details on the private section, you can't actually implement any of the calls, but with the provided usage, you can certainly provide the interface definition to the extent that the example uses it.
So:
1 2 3 4 5 6 7
class Baz{
public:
//add methods here
private:
//Unknown
}
fill in the public method prototypes that would be needed to make the example code functional. (again, only the prototypes, you have no way of actually implementing the method calls themselves)
That's pretty basic class definition code kyleg033. I find it hard to believe you'd be given the above assignment in a course without at least covering the basics of classes.
Either way, read the class tutorial here: http://cplusplus.com/doc/tutorial/classes/
That and the following page will give you all the infor needed to complete this assignment.
You are on the right track now kyle. Couple more pointers...
MAX isn't properly implemented. refer to static class members. It also isn't a function call.
Your interface is not const correct. ie, you are passed a const instance of Baz called tex. Const instances of a class cannot call non-const member functions. Currently none of your interface members are callable from a const instance of Baz.
Your string specifications are incorrect. You have two popular choices to use here. The STL string container (preferred), and a char* (old C syntax, should be avoided).