Richard Heathfield <rjh@see.sig.invalidwrote in message
news:N6qdnaM2LbREkuDYnZ2dnUVZ8tmhnZ2d@bt.com...
Quote:
triplejump24 said:
>
Quote:
Hello. Im working on what seems to me a very complicated programming
assignment. I basically have to design a video library using class.
>
It's not actually that bad, believe it or not, but I can see why you might
find it a bit daunting.
>
It DOES exceed the complexity level of knowing the return value
of main()...
Quote:
If by "class" you mean a C++-style class, you're in the wrong newsgroup,
and
Quote:
you might want to ask in alt.comp.lang.learn.c-c++ instead. If you are in
fact learning C, then you need to know it doesn't have a "class" keyword.
It does, however, have a "struct" keyword which does basically the same
job
Quote:
- aggregating elements together - in a less syntactic-sugary way.
Heh. OK, I'll play...but let's be clear, this DOES seem to be a
classic "object-oriented programming" educational exercise (I actually
took this same basic "test" in what was the only formal programming
"class" I ever took, a two-day seminar on OOP), and there actually IS
an "A" answer (and an "F" answer, which is what most "C"
programmers get when they take it)...
Quote:
>
Quote:
The
program needs to read data files i have and put the into in arrays. I
have
Quote:
Quote:
to be able ot check out a video, check in a video, get video info, get
customer info.
>
I'll start you off:
>
int main(void)
{
return 0;
}
>
How do you know he doesn't get "points" for command-line
arguments?
Quote:
but we don't do your homework for you.
But we will help you do it wrong?
Quote:
For example, the problem with the above
code is that it doesn't do anything!
Man, have you got the wrong idea here...
Quote:
So your first job should be to write a
function to display a menu of choices.
Wrong. Wrong, wrong, wrong, so totally wrong...I can't say
for sure, but I'll bet he gets ZERO points for writing essentially
a "Hello World!" program...
OK, you assert that you can do object-oriented programming in
C, I'm not going to dispute that. What I must dispute is that when
starting an object-oriented programming task, you start by designing
a menu! Obviously, your particular "orientation" is anything BUT
"object-"...
What he really needs to do FIRST is to think about how to "classify"
objects in his program. So your first "structure" (or "class") you can
"design" on a piece of paper, nowhere near a computer. You just
write down the defining characteristics of a "video", how you actually
distinguish between different "videos" in the context of this program.
He apparently already has data files with this information, so he can
pretty much just look at those files and go from there. Now he
knows what his "video" structure (or class) will contain; he can
sit down at a computer and type the structure declaration into
a *.c (*.cpp, *.C?) file.
Then he can declare an array of these structures...he seems to be
sort of limited by the stated problem to only use an array, but really
it would be better to declare another "library" structure that contains the
array of videos (or pointer) with some additional information, such as
the total number of videos, etc., and to get really OOP, sort of an
extension of the "video" class to include information on whether
video has been checked out, etc.
And the next class is the video store "clerk", and that class
will largely be a series of declarations of functions that scan
through the extended array of videos to find titles, check
whether they have been checked out, check them out, etc.
This is the "class" that actually DOES something, but in
true OOP we FIRST figure out what the data is that we
will be manipulating, THEN we figure out how to manipulate
it. It actually is simpler and quicker to do it this way in
many cases...
After you've done all that, you're actually about 70% done writing
the program, and you actually didn't have to come close to a computer!
And of course, as your LAST declaration, you can include some user
interface menu functions in the video store "clerk" class!
Quote:
Let the first choice you implement
be "End program". And your second job should be to capture a menu choice
from stdin and do something with it - call a stub (dummy) function, say,
or, in the case of the "End program" choice, quit the program.
>
Talk about code that doesn't do anything...
---
William Ernest Reid