Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Question 16 of assignment 2
May 02, 2008 04:18PM
Question 16 of assignment 2 uses algorithm 8.3 from F&M, however I cannot see the logic in this algorithm. Can somebody please enlighten me?
The algorithm states:
1.) If the score is smaller or equal to 100, or bigger or equal to 90, then grade = A (which makes sense)
2.) If the score is smaller or equal to 80, or bigger or equal to 89, then grade = B (which does not make sense)
3.) If the score is smaller or equal to 70, or bigger or equal to 79, then grade = C (which does not make sense)
4.) If the score is smaller or equal to 60, or bigger or equal to 69, then grade = D (which does not make sense)
5.) If the score is smaller or equal to 0, or bigger or equal to 59, then grade = F (which does not make sense)
If you enter this algorithm into a programming language and provide it with sample scores, only scores from 90 to 100 returns a grade.
avatar Re: Question 16 of assignment 2
May 02, 2008 05:33PM
It just a bunch of if statements.

Your code should look like this. Run it with different values and then you will understand.



#include <iostream>
using namespace std;

int main ()
{
  char grade;
  int score;

  cout << "Please enter score: ";

  cin >> score;

  if (score >= 90 && score <= 100) grade = 'A';
  if (score >= 80 && score <= 89) grade = 'B';
  if (score >= 70 && score <= 79) grade = 'C';
  if (score >= 60 && score <= 69) grade = 'D';
  if (score >= 0 && score <= 59) grade = 'F';

  cout << "Your grade is: " << grade << endl;
}

// eof

--------------------------------------------------------------
Don't Assume Everything is a Nail Just Because You Have a Really Big Hammer
Re: Question 16 of assignment 2
May 02, 2008 05:52PM
Hi
This was the code that I did to simulate the algorithm before I posted my initial message (I sommer did it in QBasic because the only other language on my pc is Delphi which I don’t like):

-------------------------------------
score% = put_your_number_here
IF 100 >= score% AND score% >= 90 THEN grade$ = "A"
IF 80 >= score% AND score% >= 89 THEN grade$ = "B"
IF 70 >= score% AND score% >= 79 THEN grade$ = "C"
IF 60 >= score% AND score% >= 69 THEN grade$ = "D"
IF 0 >= score% AND score% >= 59 THEN grade$ = "F"

PRINT grade$
--------------------------------------

Why did you change the algorithm’s operators? What you wrote there is not what the algorithm states.

Algorithm Example:
If (score <= 80 && score >= 89) grade = ‘B’ ;

Your version:
If(score >=80 && score <= 89) grade=’B’;


Your version will work because you have fixed the algorithm (as common sense dictates)
Since the errata do not indicate that there are any problems with this algorithm, I would like think there is something else I’m missing (or maybe not)
avatar Re: Question 16 of assignment 2
May 02, 2008 08:43PM
Hi. I see you are not interpreting the pseudocode incorrectly:

100 ≥ SCORE ≤ 90

translates to

( 100 ≥ SCORE ) ≤ 90 becomes 100 >= SCORE and swap it to SCORE <= 100 (you are just swapping)

100 ≥ ( SCORE ≤ 90 ) becomes SCORE <= 90


so we then have

IF SCORE <= 100 AND SCORE >= 90

This is the correct way to write an if statement. The way you have done it is prone to failure (experience has taught me). I've debugged hundreds of lines due to this mistake.


BEWARE OF PSEUDOCODE: 100 ⪰ SCORE ⪯ 90 is very common and has more a mathematical background than development. Pseudocode has no standards or even guidelines and is merely a neutral way of writing a code concept.



PS: I have to edit this damn post cause the OSPREY upgrade is screwed with character underlines.

--------------------------------------------------------------
Don't Assume Everything is a Nail Just Because You Have a Really Big Hammer
avatar Re: Question 16 of assignment 2
May 02, 2008 09:16PM
PS THIS IS WRONG:

IF 100 >= score% AND score% >= 90 THEN grade$ = "A" ... correct

IF 80 >= score% AND score% >= 89 THEN grade$ = "B" ... wrong
IF 70 >= score% AND score% >= 79 THEN grade$ = "C" ... wrong
IF 60 >= score% AND score% >= 69 THEN grade$ = "D" ... wrong
IF 0 >= score% AND score% >= 59 THEN grade$ = "F" ... wrong

THIS IS WHAT YOU SHOULD HAVE DONE:

IF 89 >= score% AND score% >= 80 THEN grade$ = "B"
IF 79 >= score% AND score% >= 70 THEN grade$ = "C"
IF 69 >= score% AND score% >= 60 THEN grade$ = "D"
IF 59 >= score% AND score% >= 0 THEN grade$ = "F"

You swapped the values around. Again do not put values before variables, experience has taught me and corrected you smile

--------------------------------------------------------------
Don't Assume Everything is a Nail Just Because You Have a Really Big Hammer
Re: Question 16 of assignment 2
May 03, 2008 12:28AM
The only part of the algorithm that is done correctly in the book is the Grade A test (which I so indicated) and now you use this as your example for the whole algorithm while ignoring the rest.
Let’s go through this again…
The book states:
If(100 >= score >= 90) grade = A *This is correct*
Then the book states:
If(80 >= score >=89) grade = B
But hang on… this is not right… should it not read:
If(89 >= score >=80) grade = B
And then the book states:
If(70 >= score >= 79) grade = C
But hang on…this is not right…should it not read:
If(79 >= score >= 70) grade = C
Need I go on?
The code that I wrote is obviously wrong and that is the whole point – it’s based on what the book says.
avatar Re: Question 16 of assignment 2
May 03, 2008 08:42PM
@hexium The code that I wrote is obviously wrong and that is the whole point – it’s based on what the book says.

OK, I see the problem. The pseudocode in the book can easily be misinterpreted.

You are correct in literally translating the pseudocode but there is no correction to this in their errata.

This algorithm is a classic example of the danger of pseudocode. Not everybody will interpret it the way you wrote it, or in this example, the way it was meant to be written, or is this intended?


I'm not knocking the principal, even I use it to document algorithms, but using LaTeX symbols can cause problems. I would rather have written:

if SCORE between (100 AND 90)

...because even if you swop it, if SCORE between (90 AND 100), you will still end up with the same code.

--------------------------------------------------------------
Don't Assume Everything is a Nail Just Because You Have a Really Big Hammer
Re: Question 16 of assignment 2
May 03, 2008 10:54PM
We are not discussing ancient ruins or musing over the meaning behind some 16th century play. Pseudo code is not supposed to be ambiguous. Are you sure that you had a good look at the algorithm before you replied the first time?
avatar Re: Question 16 of assignment 2
May 03, 2008 11:19PM
1) Agree that Pseudocode should never be ambiguous.

2) To be honest was not really paying much attention to the detail first time. I tend to filter out errors in pseudocode automatically as I'm use to working on daily bases with other peoples code.

--------------------------------------------------------------
Don't Assume Everything is a Nail Just Because You Have a Really Big Hammer
Re: Question 16 of assignment 2
May 04, 2008 10:37PM
Face the fact! We've all paid hundreds of rands for textbooks that are full of errors...

The options for answers to the questions is giving it away... Error in the textbook. Don't worry about it. You spot the mistake now feel good about yourselft.

Pick the answer you know the lectures want to see and get your one point smile
Re: Question 16 of assignment 2
May 05, 2008 10:06AM
Had done that already before initiating this discussion smile
I would rather say that this is an indication of how necessary a subject like CSS101 is to BSc students.
Re: Question 16 of assignment 2
May 06, 2008 11:07AM
Yes you are correct, this is a mistake in the textbook regarding Algorithm 8.3. The question will not be marked but you will get full credit for it.

In the previous edition the algorithm was phrased slightly differently but correct and we did not spot the change in this edition, sorry about this.
Re: Question 16 of assignment 2
May 30, 2008 12:29AM
What am I missing? My textbook's version of Algorithm 8.3 in Chapter 8 of F & M (on page 148) is as follows:

1. if (the number is between 90 and 100, inclusive)
   then
     1.1 Set the grade to "A"
   End if
2. if (the number is between 80 and 89, inclusive)
   then
     2.1 Set the grade to "B"
   End if
...

Do I have a "wrong" version of the textbook? I feel cheated. I also want an incorrect textbook! Anyone want to swop? smiling smiley
avatar Re: Question 16 of assignment 2
May 30, 2008 09:48AM
The book is screwed .... it was mention somewhere in one of the posts. Marks for the question will be given for attempting the pseudo code and not for accuracy...

--------------------------------------------------------------
Don't Assume Everything is a Nail Just Because You Have a Really Big Hammer
Re: Question 16 of assignment 2
May 30, 2008 09:57AM
authors who sound like members of the taliban should be avoided
avatar Re: Question 16 of assignment 2
May 30, 2008 10:54AM
Its Bin Ladens way of bringing the American infadils down. Teach them such crapy CS that all their mainframes r belong to us.

--------------------------------------------------------------
Don't Assume Everything is a Nail Just Because You Have a Really Big Hammer
Re: Question 16 of assignment 2
May 30, 2008 10:58AM
rofl
Re: Question 16 of assignment 2
May 30, 2008 12:17PM
"All your database are belong to us?"
Re: Question 16 of assignment 2
May 30, 2008 12:29PM
cbrunsdonza Wrote:
-------------------------------------------------------
> The book is screwed .... it was mention somewhere
> in one of the posts. Marks for the question will
> be given for attempting the pseudo code and not
> for accuracy...

That is not what the lecturer said in this thread...
avatar Re: Question 16 of assignment 2
May 30, 2008 12:51PM
Look the problem is the text book has a serious error in its pseudo code. Most people will read it and then interpet it the way the author intended to write it.

You have 2 choices: Code 100% to the pseudo code and have a broken function; Or fix the pseudo code and have a function that works.

rdebruyn made the point that we should all work on: Pick the answer you know the lectures want to see and get your one point

Contact your lectures if you want to know what they want to see.

--------------------------------------------------------------
Don't Assume Everything is a Nail Just Because You Have a Really Big Hammer
Re: Question 16 of assignment 2
May 30, 2008 12:52PM
becked Wrote:
-------------------------------------------------------
> Yes you are correct, this is a mistake in the
> textbook regarding Algorithm 8.3. The question
> will not be marked but you will get full credit
> for it.
>
> In the previous edition the algorithm was phrased
> slightly differently but correct and we did not
> spot the change in this edition, sorry about this.
Sorry, only registered users may post in this forum.

Click here to login