Can anybody help walk me through this? This is my homework for an entry level Computer Science Class. I have no idea where to start. Any advice? I'm not looking for the answer, I am trying to understand these concepts and the tutoring center in my school is closed so you guys are my only hope!
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.
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
class AValidClassNameHere
{
public:
//This area is for public functions/methods
// This area is also for public variables
private:
//This area is for private functions/methds
//This area is also for private variables
};
Now you need to fill in the important stuff like functions and variables.
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
I am unclear on the statement, is the foo function to wrapped in a class or are you to define the Baz class? If the Baz class... then look for all the function/method calls. Look for all the member variables. Create the class definition. i.e.
1 2 3 4 5 6 7 8 9 10 11 12
class AValidClassNameHere
{
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
};
Post your work, and I'll help you if you still have problems. Its not overly tough, but it is a good learning assignment (however unusefule the code actually is).
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
A few things:
1) Why are you making 'var' and then never using it?
2) Where did 'doc' come from? Was 'doc' supposed to be 'var'?
3) You have a memory leak. You're making 'var' with new, but you're never deleting it.
Disch, it is a homework assignment given by a teacher to try to get the student to understand the different methods and member variables used with classes. I.e. constructor. Its not a useful code example by any other means.