GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 04-Dec-2005, 17:54
tylerfelix tylerfelix is offline
New Member
 
Join Date: Sep 2005
Posts: 28
tylerfelix is on a distinguished road

Calculating marks and displaying letter grades


Hi,

The following things must be computed using C++, here goes:

I am about to create a program that takes information from a text file. The text file will contain things such as student number, followed by the different marks that the student received. However there is a number displayed on the first line (4) that says how many assignments were passed in. ex:

4
123456 8 5 6 9
347687 10 10 9 9
132657 8 0 -1 10
273828 10 10 0 5


The first number is the student number, each other number divided by spaces is the marks received.

Notice that there is a -1 in there. This would mean that there is a valid excuse for not handing in an assignment (which is easily put into an if and else statement)

You must already know that the program will have to do this, ex:
(8 + 5 + 6 + 9) / 4 (being the top line number)
and if there is a -1 then -1 from the assignment number, making it 3.

There can be more than one -1, but there has to be at least one mark for each student.

From this there will be a traditional grade of :
95-100 A+ 90-94.9 A 80-89.9 A- 77-79.9 B+ 74-76.9 B 70 73.9 B- 67-69.9 C+ 64-66.9 C 60-63.9 C- 50-59.9 D 0 - 49.9 F

then there should be output to a text file of the scores, something like this:

123456 100 A+ (just an example)
234344 0 F

In a DIFFERENT file there should also be printed: number of students, average of class, and deviation for the class:

stdDev = sqrt ( ((s1-avg)2 + (s2-avg)2 + (s3-avg)2 + ... + (sn-avg)2)/(n+1) )

Of course average has to be figured out before the standard deviation,so I will need to open the input file, read it, close it, then open it again.


My question to all of you is: Could you give me a good way to format this program, and give me some hints and reminders, because I haven't gone this far into coding in C++ before.

You will probably recognize that I'm starting this off slowly, and not coding until I have the floor plan. That's my purpose
  #2  
Old 04-Dec-2005, 18:18
Paramesh's Avatar
Paramesh Paramesh is offline
Regular Member
 
Join Date: Sep 2005
Location: The Milky Way
Posts: 929
Paramesh is a jewel in the roughParamesh is a jewel in the roughParamesh is a jewel in the rough

Re: Calculating marks and displaying letter grades


Hi tyler,

Quote:
Originally Posted by tylerfelix
My question to all of you is: Could you give me a good way to format this program, and give me some hints and reminders, because I haven't gone this far into coding in C++ before.
  • Open the file.
  • Get the number of lines from the file.
  • Then in a loop that varies from 0 to number_of_lines - 1, :
  • Get the first line of data using getline function.For example, like this:
    CPP / C++ / C Code:
    fin.getline(str, 30);
    
  • Scan the string you got for specific format using sscanf.
    For example, you if the string is str, you can scan like this:
    CPP / C++ / C Code:
    sscanf(str, "%d %d %d %d %d ", 
                     &id1, &mark1, &mark2, &mark3, &mark4)
    
  • Then you can process the marks as you wish and then write back to the file using << operator.
  • Finally close all the files

Paramesh.
__________________

Don't walk in front of me, I may not follow.
Don't walk behind me, I may not lead.
Just walk beside me and be my friend.
  #3  
Old 04-Dec-2005, 19:02
tylerfelix tylerfelix is offline
New Member
 
Join Date: Sep 2005
Posts: 28
tylerfelix is on a distinguished road

Re: Calculating marks and displaying letter grades


Quote:
Originally Posted by Paramesh
Get the number of lines from the file.

how would I get the number of lines? I realize it would involve using .get . but that's my limit.
  #4  
Old 04-Dec-2005, 19:17
Paramesh's Avatar
Paramesh Paramesh is offline
Regular Member
 
Join Date: Sep 2005
Location: The Milky Way
Posts: 929
Paramesh is a jewel in the roughParamesh is a jewel in the roughParamesh is a jewel in the rough

Re: Calculating marks and displaying letter grades


You can use >> operator for that.

For example, like this:
CPP / C++ / C Code:
    int i = 0;
    ifstream fin;

    fin.open("somefile.dat");

    fin>>i;
    fin.get();

The get is used to get the line break after the number.


Paramesh.
__________________

Don't walk in front of me, I may not follow.
Don't walk behind me, I may not lead.
Just walk beside me and be my friend.
  #5  
Old 04-Dec-2005, 21:34
tylerfelix tylerfelix is offline
New Member
 
Join Date: Sep 2005
Posts: 28
tylerfelix is on a distinguished road

Re: Calculating marks and displaying letter grades


thanks, I'll be fine now.
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:45.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.