|
Firstly, thankx for your reply.
yes, I need the code to calculate the grade.
|
|
|
|
|
At a first glance it doesn't look too hard, what have you done so far?
edit: I have some code here, but I haven't tested it and I may not fully understand your requirements, so be careful and test it.
if (TotalMark >= 80)
return "HD";
if (TotalMark < 40)
return "F";
if ((LabsMarks + Assignment1 + Assignment2) >= 25 && Final >= 25)
{
if (TotalMark < 50)
return "MF";
if (TotalMark < 60)
return "P";
if (TotalMark < 70)
return "C";
if (TotalMark < 80)
return "D";
}
else
{
return "MF";
}
|
|
|
|
|
What were you smoking when you decided to check the scores in that order?
|
|
|
|
|
Nothing. What is wrong about the order?
Suppose TotalMark is 75, the expected result is D
if (TotalMark < 50)
return "MF";
if (TotalMark < 60)
return "P";
if (TotalMark < 70)
return "C";
if (TotalMark < 80)
return "D";
|
|
|
|
|
I didn't say that it wouldn't work, I asked why you went in that order? What made you decide to test the last case in the list first, and then go back to the first case?
By the way, if they passed, then there's no way they scored less than 50, since 50 is the minimum required to pass. So, you'll never get to the return "MF" under if (TotalMark < 50).
|
|
|
|
|
William Winner wrote:
By the way, if they passed, then there's no way they scored less than 50, since 50 is the minimum required to pass. So, you'll never get to the return "MF" under if (TotalMark < 50).
Ok I couldn't know that, there was no description of how TotalMark should be calculated
|
|
|
|
|
Ooh do you mean "why check for < 40 and >= 80 first"?
Because they are the only two cases where you don't need to know whether the student passed, so you can skip that calculation. I know it's pointless to optimize, it's a bit of a reflex (I learned to program in assembly first - I'll blame that)
Not that it's any faster..
|
|
|
|
|
Like the other responder said,
public readonly string Grade() is not the normal way to write a read-only property if that is what you're trying to do.
It should be
public string Grade
{
get
{
}
}
So, now you just need to test the scores to determine the grade...this isn't that complicated. Just go in order of what your prof gave you.
int totalMark = LabsMark + Assignment1 + Assignment2 + Final;
if (totalMark < 40)
{
return "F";
}
else if (!Passed())
{
return "MF";
}
else if (totalMark < 60)
{
return "P";
}
it's true that you don't need the else if's, but it makes the code a lot more readable.
|
|
|
|
|
I have Simulated OPC Server like Kepware,Matrikon and i need to access the OPC Server through C# Code.I have VB Code but I need to do in C#.
|
|
|
|
|
I have a senior developer that consistently checks for null after initializing an object...
<code>
CustomObject tmp = new CustomObject();
if (tmp == null)
{
throw new NullReferenceException();
}
</code>
I personally don't see the need to do this. Can anyone explain if this is a good/bad/old practice?
Thanks in advance.
|
|
|
|
|
Yes, that belongs in coding horrors.
|
|
|
|
|
Makes no sense to me.. there is no way a ctor can ever return null , at worst it throws it an exception
Besides, the whole
if (tmp == null)
{
throw new NullReferenceException();
}
Thing doesn't really make sense. If you're just going to throw a NullReferenceException then you might as well just try to use the object and get that exception automatically
|
|
|
|
|
yes, that is good old non-sense.
you could create a static class and method to do it for you though:
CustomObject tmp = StupidOperations.MakeSureItIsntNull( new CustomObject() );
That improves readability a bit.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
But then you have a method call... DEFINE a macro instead.
|
|
|
|
|
Nice answer...
Thanks
Md. Marufuzzaman
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
Hay... Nice answer, I agreed
Thanks
Md. Marufuzzaman
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
The reason for that is maybe he is an old c++ developer.
IN C++ the new and all other allocation functions could
return a null pointer if the function couldn't allocate
the memory.
In C# this is not necessary, because it allocates the memory
block you requested or it throws an OutOfMemoryException.
But it is a common mistake made by the most old c++
developer (including me ) as they started
developing in C#.
Edit:
But throwing a NullReferenceException is very uncommon and cruel (can be misunderstood).
Greetings
Covean
|
|
|
|
|
Yes, his background is in C++
|
|
|
|
|
Just give him a friendly hint (senior developer don't like it if you say the produce senseless code )
that he hasn't to check for null and that those lines never will be executed -> just a waste of time.
Greetings
Covean
|
|
|
|
|
or just ask him to provide a class whose constructor does return null. That will keep him busy...
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Hehe, I like this idea...but will probably go with the gentle reminder approach.
|
|
|
|
|
Hi
I've got a pretty basic question. I've got an application that loads up one main form where users can login using face recognition. I want to include a button called "Alternate login". If the user clicks this button, another form should load providing an alternate means of logging in. But the other form should close though, and this new form must load in its place, with the same size etc. In essence, it shouldn't look like a new form is opened at all, it should simply look like only the controls on the form change.
Is there an efficient way to do this without actually hiding and showing controls? Another example would be a wizard interface, where the user clicks next the whole time and then the form stays the same, only the controls change.
|
|
|
|
|
Check out this tip/trick:
Multiple Subsequent Main Forms in C# Winform Apps.aspx[^]
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
or use a TabControl?
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|