Suppose there is a txt file with following format:Student name Grades in subjectsX ABA+CDA+Y B+CAA+AAthere can be many students with there grades in various subjects. (number of subjects are unknown)Possible values of grade are: A, A+, B, B+, C, D now suppose the file gets corrupted and all '+' are replaced by 'A'Write a program to restore the file

Questions by smart_coder   answers by smart_coder

Showing Answers 1 - 3 of 3 Answers

Indrajit

  • Jul 23rd, 2007
 

Since the number of subject for a perticular student is unknown and A is a valid grade, If a + symbol is replaced by a A then it would be impossible to find out without any other correct source of the same student's grades that the "A" there is occuring by mistake.

Hence it is impossible to write the programm.

MumblesCrzy

  • Sep 24th, 2009
 

So I don't know if it's possible to make a perfect program, but one that can get a close estimate would go as such.

If all the +'s in the files have been changed to A's then the two examples would look something like

ABAACDAA
BACAAAAA

So the idea here is to first change every A in a +

+B++CD++
B+C+++++

From this you can see that some errors start to occur since there are only a few given grades that can exist. So taking the first grade set here as a example:

The first plus is an A, because there is nothing before it.
AB++CD++
From there we can see that while B+ is a valid grade there is another + after that one meaning the first one can't be a true +.
ABA+CD++
The second + is unknown, even though it is right in this case.
From here we can see the next possible grade would be a D+, except we know that grade doesn't exist.
ABA+CDA+

So 3 rules exist so far. The grade set cannot start with a +. Any pairs of +'s have the first + turned into an A, and make sure +'s only make real grades.

It sounds good, but there are some issues as can be seen with the second grade set.
We start with
BACAAAAA
after the error. If we take our first step and transform all A's back to +'s
B+C+++++
we get this.
So the first grade we run into is a B+ and it's a given grade and nothing says it's not right so
B+C+++++
stays.
But the next part get's a little tricky. The next grade in the series is C+, which doesn't exist, so we would normally turn that into CA, but after applying other rules we get
B+CA+A++
This mainly depends on how you treat the last 4 +'s. If you only look for the first pair of +'s and change on that the above answer is what you get. If you keep going and only assume that the last + in any series is correct you get.
B+CAAAA+
So as stated before this method has been flawed from the start of the this grade set due to not being able to distinguish the B+ from a BA, but if I were an admin at a school I would rather deal with this error than the original.

Again the steps for the program would be.
1. Change all A's to +'s
2. Apply the 3 rules

  • The grade set cannot start with a +
  • Make sure all pluses make a given grade possibility
  • In any sequence of +'s only the last one can be assumed real.
And lastly smack the admin for not keeping track of how many classes a student is taking. 

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.