By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,047 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

desperately need help

P: n/a
This is definitely not the smart thing to do as far as my learning goes,
but desperate situations call for desperate measures.

The final lab for my introduction to C programming class is due tomorrow.
I was on vacation when we went over how to read files, so basically my
only resources are the book, the course notes, and the examples.
Unfortunately for me, none of them are usefull at all, so pretty much i
don't have a clue as to what i should do.

I haven't read one topic on these forums, so i have no idea how the
community works around here. If you want to flame me for being an idiot,
i back you up 100%. But if you want to help me out, then you've basically
saved my grade and hopefully that makes you feel good, because it'll make
me feel 100x better.

Here's what i have to do:

Use an input file which has several lines of department number, item
number, quantity and cost per item. Assume that the input file has been
sorted by department number and that all the input values are valid.
Write a program to read the input file one line at a time, and print to an
output file a Summary Report which shows the department number, item
number, quantity, cost/item, value (quantity*cost), total for each
department, the number of items (assume a unique item number on each line)
and grand total (total of all values). The Summary Report (output file)
should look something like:
Department Item Quantity Cost/Item Value Totals
15 1389 4 3.20 12.80
15 3821 2 7.00 14.00
26.80
16 0122 8 2.50 20.00
20.00
19 1244 100 0.03 3.00
19 1245 20 4.00 80.00
19 2469 4 16.00 64.00
147.00
Number of Items: 6 Grand Total 193.80

Main should only open the files, and if they both open, call a function
(that you write) to print the summary report to the output file, then
close the files in main. (If either file doesn't open, print an error
message and quit the program.)
The summary report function must print headers to the output file. Also
in this report function, call the function that reads a line from the
input file (see below), do all the calculations (you could do them in
another function), print to the output file (one line at a time), count #
of lines (items) and accumulate the totals (all in a for loop). After the
end of the input file (and last item line printed), print the last
department total, the # of items, and the grand total with labels. Hint:
You'll need a counter and 2 totals (one for the departments, another for
the grand total), and a variable to store the previously read department
number (in order to know when a new department number was read).
DO NOT USE ANY EXTERNAL VARIABLES!!!
Include in your programs:
A function to print the summary report (described above)
A function to read a line of input that returns 0 if end of file
detected (call this from the summary report function)
A for loop (count the # of lines using expr1 & expr3)
Two text files (one for input, the other for output)
Nov 14 '05 #1
Share this Question
Share on Google+
17 Replies


P: n/a
Oops, i forgot; here's the input:
100 2398 45 67.89
108 3278 88 70.75
108 3421 123 8.99
108 4032 17 30.82
108 4360 56 18.78
121 5084 27 121.21
133 6599 5 204.08
133 6787 33 82.01
133 7121 12 73.35

Nov 14 '05 #2

P: n/a
EkteGjetost wrote:
This is definitely not the smart thing to do as far as my learning goes,
but desperate situations call for desperate measures.

The final lab for my introduction to C programming class is due tomorrow.
I was on vacation when we went over how to read files, so basically my
only resources are the book, the course notes, and the examples.
That should be sufficient.
Unfortunately for me, none of them are usefull at all, so pretty much i
don't have a clue as to what i should do.

I haven't read one topic on these forums, so i have no idea how the
community works around here. If you want to flame me for being an idiot,
i back you up 100%. But if you want to help me out, then you've basically
saved my grade and hopefully that makes you feel good, because it'll make
me feel 100x better.

Here's what i have to do:

Use an input file which has several lines of department number, item
number, quantity and cost per item. Assume that the input file has been
sorted by department number and that all the input values are valid.
Write a program to read the input file one line at a time, and print to an
output file a Summary Report which shows the department number, item
number, quantity, cost/item, value (quantity*cost), total for each
department, the number of items (assume a unique item number on each line)
and grand total (total of all values). The Summary Report (output file)
should look something like:
Department Item Quantity Cost/Item Value Totals
15 1389 4 3.20 12.80
15 3821 2 7.00 14.00
26.80
16 0122 8 2.50 20.00
20.00
19 1244 100 0.03 3.00
19 1245 20 4.00 80.00
19 2469 4 16.00 64.00
147.00
Number of Items: 6 Grand Total 193.80

Main should only open the files, and if they both open, call a function
(that you write) to print the summary report to the output file, then
close the files in main. (If either file doesn't open, print an error
message and quit the program.)
The summary report function must print headers to the output file. Also
in this report function, call the function that reads a line from the
input file (see below), do all the calculations (you could do them in
another function), print to the output file (one line at a time), count #
of lines (items) and accumulate the totals (all in a for loop). After the
end of the input file (and last item line printed), print the last
department total, the # of items, and the grand total with labels. Hint:
You'll need a counter and 2 totals (one for the departments, another for
the grand total), and a variable to store the previously read department
number (in order to know when a new department number was read).
DO NOT USE ANY EXTERNAL VARIABLES!!!
Include in your programs:
A function to print the summary report (described above)
A function to read a line of input that returns 0 if end of file
detected (call this from the summary report function)
A for loop (count the # of lines using expr1 & expr3)
Two text files (one for input, the other for output)


We won't do your homework for you but,
if you will attempt to write some code and post it here,
I'm sure that everyone would be glad to help.

Nov 14 '05 #3

P: n/a
Could you help get me started? Maybe a structure chart or something?

Thanks for the reply.

Nov 14 '05 #4

P: n/a
Mac
On Sun, 05 Dec 2004 21:52:17 -0500, EkteGjetost wrote:
This is definitely not the smart thing to do as far as my learning goes,
but desperate situations call for desperate measures.

The final lab for my introduction to C programming class is due tomorrow.
I was on vacation when we went over how to read files, so basically my
only resources are the book, the course notes, and the examples.
Unfortunately for me, none of them are usefull at all, so pretty much i
don't have a clue as to what i should do.

I haven't read one topic on these forums, so i have no idea how the
community works around here. If you want to flame me for being an idiot,
i back you up 100%. But if you want to help me out, then you've basically
saved my grade and hopefully that makes you feel good, because it'll make
me feel 100x better.

[snip]

You picked the worst possible place to ask people to do your homework for
you.

If this was plan A, I suggest you go to plan B immediately and not waste
any more time here. If this was plan B, go to plan C, and so on.

To me, I think it is basically impossible for you to finish the
assignment, so I recommend you give up and work on something else. Perhaps
you can still salvage a better grade in another class.

I am not trying to be negative, just realistic.

--Mac

Nov 14 '05 #5

P: n/a
EkteGjetost wrote:
Could you help get me started? Maybe a structure chart or something?


int main(int argc, char* argv[]) {
// your code goes here
return 0;
}

Nov 14 '05 #6

P: n/a
whoa whoa, how does this make me a troll? I'm sorry if i didn't understand
that i shouldn't be asking questions like that on these forums, but it's
not like i'm posting here just to be obnoxious. I'll do as much as i can
figure out, and hopefully someone will be able to either help me, or at
least give me a little guidance from there if that's ok.

Nov 14 '05 #7

P: n/a
Mac
On Mon, 06 Dec 2004 01:27:24 -0500, EkteGjetost wrote:
whoa whoa, how does this make me a troll? I'm sorry if i didn't understand
that i shouldn't be asking questions like that on these forums, but it's
not like i'm posting here just to be obnoxious. I'll do as much as i can
figure out, and hopefully someone will be able to either help me, or at
least give me a little guidance from there if that's ok.


E. Robert Tisdale implied that your Original Post was a troll. I did not.

If you post code to this group, and a clear description of what it is
supposed to do, people will USUALLY try to help you out a bit.

But you don't have time for many iterations of this sort of thing. That is
why I believe you will not finish in time.

Anyway, I bear you no malice or ill-will whatsoever. I have been in your
shoes before, many years ago, so I recognize your position.

Good luck.

--Mac

Nov 14 '05 #8

P: n/a
In article <5985d2bcb013629c3380239268dfc348
@localhost.talkaboutprogramming.com>, ch*********@gmail.com says...
whoa whoa, how does this make me a troll?
Mac didn't call you a troll, our resident troll, ERT did.
I'm sorry if i didn't understand that i shouldn't be asking
questions like that on these forums, but it's not like i'm
posting here just to be obnoxious. I'll do as much as i can
figure out, and hopefully someone will be able to either help
me, or at least give me a little guidance from there if that's
ok.
Nobody will write your homework assignment for you. On the other
hand, if you send me your professor's email address, I'll be
happy to submit something for you.

The point is, you said in the original artice that: my only resources are the book, the course notes, and the examples.


Those three things (especially the example code, perhaps the book,
considering on which is being used) should be more than sufficient
for anyone with a chance of passing a computer programming course
in the first place.

Waiting until the day before it's due to start, while taking vacation
during the middle of the class is not the best indicator that you
are cut out for this sort of thing.

If you had started a bit earlier, odds are you could have come up
with something, even if not working perfectly, people often help
correct code that is flawed here. They will not just write it for
you though, you have to put in effort up front.

--
Randy Howard (2reply remove FOOBAR)
"For some reason most people seem to be born without the part
of the brain that understands pointers." -- Joel Spolsky
Nov 14 '05 #9

P: n/a
"EkteGjetost" writes:
I'm sorry if i didn't understand
that i shouldn't be asking questions like that on these forums, but it's
not like i'm posting here just to be obnoxious. I'll do as much as i can
figure out, and hopefully someone will be able to either help me, or at
least give me a little guidance from there if that's ok.


There just isn't enough time. Programming contains such a seemingly
infinite number of little and not so little hurdles that IMO no beginner
could finish this by the end of the day. I saw the post last night and that
was my opinion then and it's even more so now. Think of taking 10 to 100
times what a skilled programmer would need in terms of time. It's not like
building a house or something where a pro could do it in x and an amateur
could do it in 2 x. There is a factor of five *or more* even between two
competent programmers, an astonishing difference in itself.

You need to negotiate at the very least a three day extension, perhaps more.
And presumably you have other courses to attend to. As someone has already
suggested, resign yourself to taking a fail on this and focus your energies
someplace else. I'm not averse to helping, it's just that you need too much
help.
Nov 14 '05 #10

P: n/a
Mac <fo*@bar.net> writes:
On Mon, 06 Dec 2004 01:27:24 -0500, EkteGjetost wrote:
whoa whoa, how does this make me a troll? I'm sorry if i didn't understand
that i shouldn't be asking questions like that on these forums, but it's
not like i'm posting here just to be obnoxious. I'll do as much as i can
figure out, and hopefully someone will be able to either help me, or at
least give me a little guidance from there if that's ok.


E. Robert Tisdale implied that your Original Post was a troll. I did not.


No, nobody called him a troll; the OP was the one who introduced the
word in to the discussion.

The OP's statement in the initial post:

I haven't read one topic on these forums, so i have no idea how
the community works around here. If you want to flame me for being
an idiot, i back you up 100%.

was refreshingly honest, but following that up with a complaint about
being called a troll (when nobody actually did so) seems less than
entirely consistent.

As for the OP's question, I'm in no more of a position to help than
anyone else.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #11

P: n/a
Square cat EkteGjetost was jivin' on Sun, 05 Dec 2004 21:52:17 -0500
in comp.lang.c.
desperately need help's a bad trip! Dig it!
This is definitely not the smart thing to do as far as my learning goes,
but desperate situations call for desperate measures.

The final lab for my introduction to C programming class is due tomorrow.
Left it a bit late, then, didn't we?
I was on vacation when we went over how to read files, so basically my
Let me get this straight. Instead of attending your classes, you
went away on vacation? And now you expect us to make up for your lack
of dedication to your studies?
only resources are the book, the course notes, and the examples.
Here's a thought. Why don't you try reading them?
Unfortunately for me, none of them are usefull at all, so pretty much i
No, well things like that are generally not very useful unless you
open them up and point your eyes at them.
don't have a clue as to what i should do.

I haven't read one topic on these forums, so i have no idea how the
community works around here.
Oh dear!
If you want to flame me for being an idiot,
i back you up 100%.
Oh good, you know what I'm thinking of you right now. That'll save
me the trouble of telling you.
But if you want to help me out, then you've basically
Sure. Which way did you come in?
saved my grade and hopefully that makes you feel good, because it'll make
me feel 100x better.
Interesting... uh... "logic"! Unfortunately it is flawed.
Here's what i have to do:


[Snip.]

So, you want us to do the work for you, to make up for your slacking
off?
Now, let me lay a few rules of newsgroup etiquette on you. First,
before you post to a newsgroup it is a must to lurk for a time (a
month or two is customary) to get a feel for the group and its rules
and to know whether your question has already been answered. It is
also a must to read a newsgroup's FAQ, welcome message, charter and
any other relevant material before posting to that newsgroup. (The
welcome message or charter will sually tell you what to read.)
comp.lang.c does not have a charter, however it does have a FAQ and a
welcome message.
Also, I notice elsewhere in this thread you follow up to messages
without quoting the text to which you are responding. Newsgroup
articles don't always arive in the order in which they were posted,
and sometimes they get lost. Unless you quote, with proper
attributions, what you are responding to, as I have done above, noone
will have any idea what you're talking about.

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
Nov 14 '05 #12

P: n/a
Keith Thompson wrote:
Mac <fo*@bar.net> writes: No, nobody called him a troll; the OP was the one who introduced the
word in to the discussion.
Sorry, but you are mistaken. ERTrollsdale in
<cp**********@nntp1.jpl.nasa.gov> changed the orginial header Subject: desperately need help to Subject: Troll Alert: desperately need help

Nov 14 '05 #13

P: n/a
Martin Ambuhl wrote:
Keith Thompson wrote:
Mac <fo*@bar.net> writes:

No, nobody called him a troll; the OP was the one who introduced
the word in to the discussion.


Sorry, but you are mistaken. ERTrollsdale in
<cp**********@nntp1.jpl.nasa.gov> changed the orginial header
> Subject: desperately need help

to
> Subject: Troll Alert: desperately need help


Which is just one more of Trollsdales sneaky changes. Most people
have the common decency to flag their subject changes with a (was:
....) indicator. Trollsdale is famous for at least altering quotes,
misinformation, and trolling.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #14

P: n/a

On Wed, 8 Dec 2004, CBFalconer wrote:

Martin Ambuhl wrote:
Keith Thompson wrote:
No, nobody called him a troll; the OP was the one who introduced
the word in to the discussion.


Sorry, but you are mistaken. ERTrollsdale in
<cp**********@nntp1.jpl.nasa.gov> changed the orginial header
> Subject: desperately need help

to
> Subject: Troll Alert: desperately need help


Which is just one more of Trollsdales sneaky changes. Most people
have the common decency to flag their subject changes with a (was:
...) indicator. Trollsdale is famous for at least altering quotes,
misinformation, and trolling.


I don't think you can fault Trollsdale for the subject line change.
It's not like he altered the OP's subject line; he just added a tag
on the front of it, the same way many contributors flag subjects with
"[OT]", or the way some sci.math readers try to flag JSH's posts with
"[JSH]" (it's a losing battle). I see nothing wrong with the subject-
line change, stylistically speaking.
Of course, the flagging of the OP as a "troll" is questionable, and
ERT does have a history of other misdemeanors (and a few felonies).
But I don't think ERT's "Troll Alert:" banner really counts as a
"sneaky change." It's just silly, incorrect, and a little rude, that's
all.

-Arthur,
way OT
Nov 14 '05 #15

P: n/a
Martin Ambuhl <ma*****@earthlink.net> writes:
Keith Thompson wrote:
Mac <fo*@bar.net> writes:

No, nobody called him a troll; the OP was the one who introduced the
word in to the discussion.


Sorry, but you are mistaken. ERTrollsdale in
<cp**********@nntp1.jpl.nasa.gov> changed the orginial header
> Subject: desperately need help

to
> Subject: Troll Alert: desperately need help


My mistake, I missed that.

Apparently irony is dead, but I never saw the obituary.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #16

P: n/a
CBFalconer <cb********@yahoo.com> scribbled the following:
Martin Ambuhl wrote:
Keith Thompson wrote:
Mac <fo*@bar.net> writes:
No, nobody called him a troll; the OP was the one who introduced
the word in to the discussion.
Sorry, but you are mistaken. ERTrollsdale in
<cp**********@nntp1.jpl.nasa.gov> changed the orginial header
> Subject: desperately need help

to
> Subject: Troll Alert: desperately need help

Which is just one more of Trollsdales sneaky changes. Most people
have the common decency to flag their subject changes with a (was:
...) indicator. Trollsdale is famous for at least altering quotes,
misinformation, and trolling.


Having your post called an "obvious troll" by ERT is actually a sign of
a well-written post and good understanding of C and/or Usenet behaviour.
Somehow ERT picks out the most clueful posts and calls them "obvious
trolls". I think he does this on purpose.
Being called an "obvious troll" by anyone other than ERT is a bad sign.
If that happens you should reconsider your arguments or stay quiet for
a while.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"O pointy birds, O pointy-pointy. Anoint my head, anointy-nointy."
- Dr. Michael Hfuhruhurr
Nov 14 '05 #17

P: n/a
On Wed, 8 Dec 2004 00:40:49 -0500 (EST), in comp.lang.c , "Arthur J.
O'Dwyer" <aj*@nospam.andrew.cmu.edu> wrote:
Of course, the flagging of the OP as a "troll" is questionable, and
ERT does have a history of other misdemeanors (and a few felonies).


Hmm, I always assumed that Trollsdale was notifying everyone that /he/ was
a troll when he did that.... :-)
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 14 '05 #18

This discussion thread is closed

Replies have been disabled for this discussion.