In my assignment, one of the instructions says: "Create a class that implements a string to hold the infix version of a math problem. A real to hold the correct answer. A real to hold the user's answer, and a boolean to represent if the problem is correct or not."
My program is to be a WPF program that would have 4 text boxes. 1st box is to show a list/stack of the equation to answer, 2nd box is to show the list/stack of equations with the right answer, 3rd box is to show the list/stack of the equations with the wrong answer, and the last box is to let the user input their answer. I thought about setting the user's input answer as an int, but seeing that I need to set it as a "real", I don't understand.
A real number is most likely what they are looking for. As a 'real' isn't a type in c#.
You could use float, double, or decimal depending upon the requirements of what you need it to do.
Real number doc: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/floating-point-numeric-types
Related
I'm currently working on a form with a bunch of textboxes with quite specific requirements. For example one textbox contain cadastral number and should look like ##:##:#######:~ (last range of digits varies) and also it would be quite nice to see the pattern before you even type anything (if I recall correctly it's called mask). Also giving requirements first two digits always should be 24, so the end result should look shomething like this 24:##:#######:~. Another example is a numeric textbox with units and spaces between big digit numbers (ex 1 000 000 m2). For short this one text box and the others have both static elements (which user should not be able to edit) and dynamic (which makes masked textboxes and similar stuff quite hard to deal with).
So, I've tried different things:
Using maskedTextBox from toolkit package, which turned out bad, because it did poorly handle last part with range of digits, and also when a key was pressed when in the middle of the static mask, it just pushed the carret, but not actually add anything to the text;
Using converters prove quite chalenging at first, but gave remarcable results, it handles variable range of part perfectly, partialy, because of custom converter, but it was difficult to manage things, when user deleted text, because of static parts being integrated in the converter itself;
Using StingFormat for textbox with binding text property was almost useless, although it handle static part quite well, and in the end I couldn't make it work.
Intuition tells me a combination of a custom converter (handling dynamic part) and and StringFormat (handling uneditable static part) should do the job. Maybe the number of requirements is just too much for a simple textbox. Also one thing is bugging me, there could be a sutable existing general solution, that I am not aware of (At first I didn't know Converters was a thing).
Now the question, how would you generally approach this problem? Is there any existing solutions, that with a bit of tweaking would work?
Is it possible for c# to look past typos in user input and execute the proceeding code given that the user input is very similar to the condition. Lets say for example, we ask the user to pick an option from a switch consisting of colours."blue" is the desired colour and this has some code following it but the user inputs "bluu" or "glue", would c# be able to pick the "blue" option given that it can recognise the input is closer to blue then other colours such as "red". Is there some sort of method we could apply to this.
You could look into using the Levenshtein Distance Algorithm to check how similar the strings are, maybe if the algorithm finds the strings are only one character in difference you could then execute whatever code. It would probably be easier to use some conditional statements as opposed to a switch in this case.
see this answer for an imlementation of this algorithm
I have two strings (they're going to be descriptions in a simple database eventually), let's say they're
String A: "Apple orange coconut lime jimmy buffet"
String B: "Car
bicycle skateboard"
What I'm looking for is this. I want a function that will have the input "cocnut", and have the output be "String A"
We could have differences in capitalization, and the spelling won't always be spot on. The goal is a 'quick and dirty' search if you will.
Are there any .net (or third party), or recommend 'likeness algorithms' for strings, so I could check that the input has a 'pretty close fragment' and return it? My database is going to have liek 50 entries, tops.
What you’re searching for is known as the edit distance between two strings. There exist plenty of implementations – here’s one from Stack Overflow itself.
Since you’re searching for only part of a string what you want is a locally optimal match rather than a global match as computed by this method.
This is known as the local alignment problem and once again it’s easily solvable by an almost identical algorithm – the only thing that changes is the initialisation (we don’t penalise whatever comes before the search string) and the selection of the optimum value (we don’t penalise whatever comes after the search string).
Let's assume, that we're scanning test-like documents with checkboxes / empty circles (for signing / striking / ticking). What would be the proper way, to check, if already cropped checkbox/circle is checked/signed/striked/ticked?
In case we'll force test users to fully mark the area, just knowing the position of checkbox/circle and counting amount on non-white pixels would be enough (would it?), but what way should we approach to test, that the checkbox / circle is ticked or checked (X)?
This is going to be part of the project in C#, so code or even ready libraries for .net / c/c++ would be appreciated.
sorry for the shortness of this answer but you could have an ocr system run on the area within the checkbox.
If it returns nothing then you know it's not checked.
If it returns something then compare it against a large white list of possibilities and then flag uncertainties.
you could use the error handling that #dan proposed as well
What makes this more robust than just taking an average is that you can determine if it's not checked with a high certainty. because we're looking for a mark that is in some minimal way recognizable we know if there isn't anything there then it's definitely not checked. all you have to do then is find a good white list of characters and marks that could be used as checks (and think outside of the box, the ocr system may return an 'a' for a squiggle, but that is a positive response). And to clarify, the problem with just taking an average is that any increase in darkness in the check box yields a positive result, which isn't always the case. if someone puts a mark and then erases you're still going to have a increase in darkness within the box.
Lastly i'll add that there are a lot of OCR systems out there now that are pretty advanced. i doubt you'd have much trouble finding one where you could provide additional training data sets that would match you're cases better than random characters.
The algorithm would go something like this:
Find each checkbox (I understand you already have that)
Calculate the average of the color of all pixels
If it is above a certain threshold, it is marked, if below, it is unmarked
However, you should add some checks:
Are multiple above the threshold? -> Let a human check it, the student could have first ticked something and then changed it to another field.
Are none above the threshold? -> Let a human verify that really none have been checked.
I guess the important part about this answer is:
If the algorithm is unsure, flag it for manual processing.
Most of the high performance products that offer checkbox recognition use some kind of bell distribution curve to work out the likelihood of a box actually being checked: too much 'data' and there's a good chance the user changed their mind and has scribbled-out this box; too few and it could be the 'tail' left by a user ticking a box below and not lifting the pen before crossing the next box region.
I'd suggest you apply additional logic to deal with more than one box being allowed (e.g. do you own a car / do you also own a bike) as well as the situation where only one box can be correct (e.g. are you male or female). This should help your app. filter out the more obvious errors.
In my WPF application the user is inputting a GPS coordinates in the format of Degrees : Minutes : Seconds as decimal fraction of minutes.
So 60° 30' 45" would be entered as 60° 30.750' .
I then store it as a pure decimal number so the above example would be stored as 60.5125.
The idea was that so the users wouldn't mess up the input it would be set in 3 different textboxes. One for Degrees, other for Minutes and one for the fractionalSeconds. It's somewhat bad that one of the numbers is seperated into two textboxes but if they have to type the whole number in the are afraid of all the point or comma confusion and that they could mess up.
So one thing I thought might work was a IMultiValueConverter but it seems to only work with MultiBindings which is something I'm not doing here.
Currently my solution is to bind to different properties and do all the calculations in code behind but I'm not really happy about the fractional bit. I assume 3 fractional letters but if they enter only 7 and assume 0.700 but get 0.007 so I thought I would have to do a string format bit.
Is there a better solution out there. Can I use MultiValueConverter for something like this?
You could try using a MaskedTextBox, such as the one from the Extended WPF Toolkit.
You could use a Masked TextBox. This implementation uses MaskedTextProvider which is a .net class.