Lost Password?


Go Back   CodeCall Programming Forum > Software Development > General Programming

General Programming Non language specific, Assembly, Linux/Unix, Mac and anything not covered in other topics. Talk about Programming Theory here.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-17-2007, 01:36 AM
patience patience is offline
Newbie
 
Join Date: Mar 2007
Posts: 2
Rep Power: 0
patience is on a distinguished road
Default Algorithm help.

Algorithm Verification

Consider the following selection statement where X is an integer test score between 0 and 100.

input X

if (0 <= X and X < 49)
output "you fail"

else if (50 <= X and X < 70)
output "your grade is" X
output "you did OK"

else if (70 <= X and X < 85)
output "your grade is" X
output "you did well"

else if (85 <= X and X < 100)
output "your grade is" X
output "you did great"

endif
output "how did you do?"



I am so confused with these questions can someone help me please.


Answer the following question about the information of algorithm verification.

1. What will be printed if the input is 0?
2. What will be printed if the input is 100?
3. What will be printed if the input is 51?
4. What will be printed if the user enters “Wingding”?
5. Is this design robust? If so, explain why. If not, explain what you can do to make it robust.
6. How many levels of nesting are there in this design?
7. Give a set of test values that will cause each of the branches to be executed.
8. Give a set of test values that test the abnormal operation of this program segment.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 03-17-2007, 01:02 PM
icepack's Avatar   
icepack icepack is offline
Programmer
 
Join Date: Jul 2006
Location: North Carolina
Posts: 115
Rep Power: 9
icepack is on a distinguished road
Send a message via AIM to icepack
Default

well the input is X, so if X is 0....which one of the statements will be rendered "true" for both cases?

else if (70 <= X and X < 85)

is that true? is 0 greater than or equal to 70 and less than 85?...

think logically and this is very easy
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-18-2007, 01:09 AM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,433
Last Blog:
Google Web Toolkit
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default

It is simple logic that you usually learn in 7th grade. Lets look at some basic truth tables.

Lets assume:
^ is the AND operator
V is the OR operator
T is TRUE
F is FALSE

T ^ T = T
T ^ F = F
F ^ T = F
F ^ F = F

This means that an AND statement can only be true IF and ONLY IF both parts of the statement are true.


T V T = T
T V F = T
F V T = T
F V F = F

This means that an OR statement is true only when both parts of the statement are FALSE.

Algorithms operate in most cases from top to bottom left to right. With that said lets look at your first question.

1) What if X = 0? Well start from the top and evaluate each statement.

Is X >= 0? TRUE
AND
Is X < 49? TRUE

Since both are TRUE, that statement is logically true. By evaluating the rest the same way, you see that all the other statements are not true.

2)
What if X = 100?
0 <= X < 49
T F ---------- FALSE
50 <= X < 70
T F ---------FALSE
70 <= X < 85
T F ---------FALSE
85 <= X < 100
T F -------FALSE (100 is not less than 100)

(T ^ F) = F
Since none of the statements are true, nothing will appear other than maybe "How did you do?"
3)
What if X = 51
0 <= X < 49
T F ---------- FALSE
50 <= X < 70
T T ---------TRUE
70 <= X < 85
F F---------FALSE
85 <= X < 100
F F-------FALSE

4) Repeat the same thing. But you can easily see that Wingding is not in integer (its a string) and will never be greater or equal to another integer.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
New Algorithm Matches Any Tumor Cells To Best Possible Anticancer Treatments Kernel Programming News 0 07-29-2007 08:52 PM
efficient algorithm sovixi Python 3 04-19-2007 02:47 PM
Algorithm needed crazyinstinct Visual Basic Programming 2 03-03-2007 04:14 PM
can sum1 help me in making a CPU scheduling algorithm program in c? bryan General Programming 2 11-28-2006 12:55 PM


All times are GMT -5. The time now is 12:56 PM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 98%

Ads