Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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?
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 .
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.
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 ??
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:
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
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.
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?
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.