GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C++
Go To First  |  Previous Question  |  Next Question 
 C++  |  Question 109 of 203    Print  
Suppose there is a txt file with following format:

Student name Grades in subjects
X ABA+CDA+
Y B+CAA+AA

there 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


  
Total Answers and Comments: 3 Last Update: September 25, 2009     Asked by: smart_coder 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
July 23, 2007 03:05:20   #1  
Indrajit        

RE: Suppose there is a txt file with following format:...
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.

 
Is this answer useful? Yes | No
June 18, 2008 09:44:56   #2  
chiyuwang Member Since: June 2008   Contribution: 4    

RE: 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 variou
agree
 
Is this answer useful? Yes | No
September 24, 2009 16:55:29   #3  
MumblesCrzy Member Since: September 2009   Contribution: 1    

RE: 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 variou
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.

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape