Any of you ever play with "Psuedocode?" Any Programmers PLEASE HELP!

Nutdotnet

Diamond Member
Dec 5, 2000
7,721
3
81
Hey all.

I have this Programming Class that I am taking that uses PsuedoCode. PsuedoCode is not real Code but it describes the LOGIC of Steps in a Program. Well I am having a little bit of a problem on a question.

How would one properly Write and Validate a "Part Number" that is 6 characters where the first two are alpha (AA, BB, etc.) and the last four characters are Numeric (1234, 5434, etc.) Now the Algorithm that I am writing would read the "Part Number" and check with it meets the criteria I just described. But how would I writh that?

I don't think "IF strPartNumber = 6 THEN......." Would work because I have nothing to tell the program that the first two need to be ALPHA and the last four need to be numerical.

Even if you haven't used Psuedocode I would still apprectiate the help, it is the logic that I am after.

Thanks!
 

Nutdotnet

Diamond Member
Dec 5, 2000
7,721
3
81
The Topic says PsuedoCode, I am using Psuedocode. Like I said in my first post, it is not real code but it is what this class is using becuase we are focusing on the logic of Programming not the syntax.
 

yiwonder

Golden Member
Nov 30, 2000
1,185
0
0
I understand what Pseudo Code is, but how do I know what you can do and what you can't?

If you are using C++:
I was thinking of entering it as a String and then using the string like a vector(string[0] will be your first letter, string[1] will be your second, and so on). You coul djust use that in your if statements then:

String S;
cout << &quot;Enter the part number&quot;'
cin >> S;
if (S[0]==&quot;A&quot;)
...do something;

does it make any sense?
 

beat mania

Platinum Member
Jan 23, 2000
2,451
0
76
enter input
check str has 6 characters
check str[0:1] =~ /A-Za-z/
check str[2:5] =~ /0-9/
do stuff with string
done

psuedocode is just like thinking out loud ...
 

Nutdotnet

Diamond Member
Dec 5, 2000
7,721
3
81
beat, yeah you are right and what you wrote makes sense but I am having a hard time implementing it to the commands and what not I can use.

I can use &quot;IF-THEN&quot; Statements and Select Cases.

Does that help at all yiwonder? It is the basic aspects of programming.
 

propellerhead

Golden Member
Apr 25, 2001
1,160
0
0
You said the program needs to validate the part number. You did not mention anything about prompting the user and accepting input. So...

Pseudo-code (as in used to describe the logic, totally detached from any specific language):

If the first two characters alphabetic

If the last four characters are numeric

Do something with the valid input.

End if

End if

 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
propellerhead has the right idea although I'd scrap the &quot;end if&quot;, the rest of you, no idea :)

Generally pcode (more formally known as PDL - program design language) uses uppercase to denote more language specific elements.
 

Phil21

Golden Member
Dec 4, 2000
1,015
0
0
or just use perl. ;)

if ($string =~ m/(^[A-Za-z]{2})(\d{4})/) {
# String matches criteria
# Letters are in $1
# Numbers are in $2
}

;) Perl == godly.

-Phil
 

littleprince

Golden Member
Jan 4, 2001
1,339
1
81
you dont implement psudeocode.
it just helps you understand the logic, in which this case there doesnt seem to be much.

i'd say propeller had it.

its just something that someone who noes any language would understand, it doesnt matter if you noe basic, or c, or fortran or wutever.

get part number
if part # is 6 characters and part # starts with 2 alpha, and ends with 4 #'s.
do something
else
try again

end program
 

Phil21

Golden Member
Dec 4, 2000
1,015
0
0
Well, I was trying to give an example of an implentation that would work, from there you get your logic.

That regex does &quot;If the first 2 characters are a letter, and the next 4 are digits then evaluate to true and store them in temp. vars&quot; (basically, you get the idea)

-Phil
 

iamwiz82

Lifer
Jan 10, 2001
30,772
13
81
psuedo code is quite good to see an algorithm. Once you get into really complex programs, their relevence becomes apparent.