LinuxQuestions.org
Review your favorite Linux distribution.
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, 05: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 05:19 AM.
 
Old 09-22-2012, 05:53 AM   #2
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 635

Rep: Reputation: 186Reputation: 186
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, 06:23 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
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, 06: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, 07:02 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
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, 08: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, 09:02 AM   #7
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 635

Rep: Reputation: 186Reputation: 186
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 09:33 AM. Reason: changed from scanf to fscanf
 
Old 09-22-2012, 12:39 PM   #8
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
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, 05: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, 05:07 AM   #10
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
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, 05: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, 09: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, 09:43 AM   #13
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 635

Rep: Reputation: 186Reputation: 186
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 06:23 AM
text file handling in C jus71n742 Programming 6 05-05-2010 10:31 PM
File Handling in C++ jmandumpal Programming 6 09-04-2008 10:18 PM
File Handling In C/C++ vikasumit Programming 5 06-19-2006 12:43 AM
file handling in c++ gtk+ alisha Programming 1 04-13-2004 01:22 PM


All times are GMT -5. The time now is 02:25 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration