LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-22-2012, 04:18 AM   #1
priya sweet
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Rep: Reputation: Disabled
file handling


hello friends this is priya...
i hope u people will help me with the following question
the question is :
Write a program to process a set of student marks.Each line of the data contains a person's name (a single word) followed by five marks. Each mark should be an integer between zero and 10 inclusive.
Your program should:
1.·print the name and average mark for each student to two decimal places
2.print the total number of students processed
3.·print the overall average to two decimal places
The input should come from a file called data.txt. The output should be printed to standard output.

Last edited by priya sweet; 09-22-2012 at 04:19 AM.
 
Old 09-22-2012, 04:53 AM   #2
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 647

Rep: Reputation: 189Reputation: 189
Hi and welcome to the forum.
Show us where you've got at and tell us what got you stuck.
You're not expecting us to write down all the code for you, do you?
 
Old 09-22-2012, 05:23 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
i hope u people will help me with the following question
Sure!!! What help do you need?

What language did they ask you to use?
 
Old 09-22-2012, 05:48 AM   #4
priya sweet
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
This code is to be done in c++
we have entered name and marks of 5 subjects of a student in one line
and while writing it to standard output we have displayed the line up to that i am done. My doubt is that later how to find avg of a particular student and of whole students that i am not clear. soo please can u give me idea about how to do that .
 
Old 09-22-2012, 06:02 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Have you studied the C++ functions for handling strings? One thing you will need to do is extract the five "marks" one each line into variables (I think an array is probably the best approach). If you have the marks in an array, then you cam simply use a loop to step thru the array and add up the values. Then divide by 5.
 
Old 09-22-2012, 07:38 AM   #6
priya sweet
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
yeah thanqq but how can i extract the marks? i have read them. u mean i can use seekg and seekp . but i dont know how many bytes the name takes so can u plzz tell me how can i proceed ??
 
Old 09-22-2012, 08:02 AM   #7
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 647

Rep: Reputation: 189Reputation: 189
I believe that, from your requirements, it is expected of you to first parse the input file using an appropriate data structure (given that we're talking about C++, this would likely be a class) to contain the information about every student (namely: the name and the 5 marks) and then you should write appropriate methods to process this data and produce the results required in your assignment.
If you don't know how to parse a single line of input, you can make use of the C fscanf function like this:
Code:
FILE *f = ...;
char name[100];
int m1,m2,m3,m4,m5;
fscanf (f, "%s %d %d %d %d %d", name, &m1, &m2, &m3, &m4, &m5);
Keep in mind that those variables should be contained inside an appropriate data structure as said before, if you want to code in an object oriented way.

Last edited by 414N; 09-22-2012 at 08:33 AM. Reason: changed from scanf to fscanf
 
Old 09-22-2012, 11:39 AM   #8
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Priya;

Please don't use SMS-speak here.....spell out you, please, thank you, etc.

I think it will help for you to tell us how much C++ code you are expected to know----and, in general, more about the class, the kinds of things you have been studying, etc.
 
Old 09-23-2012, 04:00 AM   #9
priya sweet
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
thank you so much for all your replies.
 
Old 09-23-2012, 04:07 AM   #10
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by priya sweet View Post
thank you so much for all your replies.
You're welcome!!---However, the normal etiquette is to give us feedback on whether your question was resolved----in this case, did you successfully finish the assignment?
 
Old 09-23-2012, 04:56 AM   #11
priya sweet
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
yeah thank you so much. I have done with my assignment.
 
Old 10-09-2012, 08:38 AM   #12
priya sweet
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
dear friends
can you please suggest me how to reduce time limit while coding in c++??
 
Old 10-09-2012, 08:43 AM   #13
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 647

Rep: Reputation: 189Reputation: 189
Of what time limit are you talking about?
You should open a new thread (if you really cannot find a proper answer while searching the forums) instead of adding new issues to this one.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] using # and * for file handling sameera7788 Linux - Newbie 4 07-06-2012 05:23 AM
text file handling in C jus71n742 Programming 6 05-05-2010 09:31 PM
File Handling in C++ jmandumpal Programming 6 09-04-2008 09:18 PM
File Handling In C/C++ vikasumit Programming 5 06-18-2006 11:43 PM
file handling in c++ gtk+ alisha Programming 1 04-13-2004 12:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration