Write a class definition without a private section

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 
Homework?

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.
yup,

Ok, that doesn't sound to bad I'm just sort of unsure how he wants the answer... What is the format of the answer he is looking for?
a class?
Thats what I was thinking, but do I actually implement all the methods?
Doesn't look like you have any methods to implement based on that sample code.
I'm so confused, so what is he asking for?
You have a constructor that takes two parameters, a copy constructor, set that takes a string, ...
1
2
3
4
5
6
7
8
9
10
11
12
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.
I honestly did not know what a class was until a couple weeks ago, I'll try to read through the tutorial and post what I get.
1
2
3
4
5
6
7
8
9
10
11
class Baz{
Baz(int x, str "")
~Baz()
int max();
int x;
void set(str "");
int howmany();

private:
//Unknown
}


Is this what your getting at? Sorry, I know its bad I really need help!
anybody? Please help!
Just a quick glance at the post.
In the code you posted above, all methods are still private.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Baz{

public: 
Baz(int x, str "");  // now everything is public 
~Baz(); 
int max();
int x;
void set(str "");
int howmany();

private:
//Unknown
}
Thanks for that, what would you change in the public region of the code? I'm not supposed to have anything in the private section right???
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).
Topic archived. No new replies allowed.