View Full Version : Progaming and Logic Question Please Help!
LOgle0917
09-14-2004, 09:53 PM
I am a beginning Prog Logic and Design student. I have a project to write pseudocode and draw a flow chart to do the following. From an Alumni File I have the following fields
Alumnus Number
Alumnus Name
Year Graduated
Major
I want to get all Alumni With a Major in Bus, who graduated from 1984 and then print the total of the Alumni listed, then create a flow chart showing how to do this.
I have started my pseudocode like this as our teacher said to state it out:
Start
If Major ="Bus" then
If Year Graduated ="1984" then
Printf "Alumnus Number","Alumnus Name"
Else End Then
Get calculated total of "Alumus Name"
Printf Numeric Total "Alumnus Name"
Stop
Does this look correct? I am not sure what to do if the answer is No to the first 2 conditions. Can someone help me? I think I can flowchart it okay if I can just get this part of it.
Thank you!
scroots
09-15-2004, 06:27 PM
psuedo code is your way of expressing what your going to do. Some people indent stuff (like if contents) and space it out a bit.
scroots
Mhtml
09-16-2004, 12:06 PM
Pseudo code can be written however you like, you don't even need to use real functions or anything, as long as you can understand basically what is going on.
Also, generally speaking, BEGIN and END are commonly used as what are called terminators.
So let's have a look at your code:
Start
If Major ="Bus" then
If Year Graduated ="1984" then
Printf "Alumnus Number","Alumnus Name"
Else End Then
Get calculated total of "Alumus Name"
Printf Numeric Total "Alumnus Name"
Stop
What do you mean by Else End Then? Do you mean to finish the IF statement?
Now you can do it how you like of course but it's best to stick with what most people do, that way it's easier to share your ideas! Commonly we use END IF (I like to use capitals to make it obvious it's a control structure or statement but you don't have to)..
That is to say an IF control structure would look like-
IF condition THEN
...
[ELSE]
...
END IF
Of course the ELSE is optional (hence square brackets [])..
You are parsing (that is reading information) from a file. So you will need some sort of indication of a loop.
BEGIN
Open file
FOR EACH Record in file
...
NEXT Record
END
And then for each record you need to decide if it is a bus major and in the specified year, easy enough-
IF Record.Major = "Bus" THEN
IF Record.Year = 1984 THEN
Print Record.Number, Record.Name
END IF
END IF
Now that was essentially what you had, but I changed the syntax to what I usually use. Seeing as we have a loop for each Record, you can use Record.Whatever to show you are getting 'Whatever' from that particular record. The algorithm can be however you like, it doesn't have to be terribly specific but just show what has to happen so that the programmer can worry about all that other stuff and just make sure it follows those directions.
You can see how if you put both of those together you will only do something with the record (that is, print the number and name) if it is a bus major and from 1984. If it isn't, or once it has printed that record it'll move onto the next one.
So putting that together it'll be-
BEGIN
Open file
FOR EACH Record in file
IF Record.Major = "Bus" THEN
IF Record.Year = 1984 THEN
Print Record.Number, Record.Name
END IF
END IF
NEXT Record
END
Note how I've indented the contents of each control structure, this makes it easier to read.
Also notice how I've only used quotes on strings, that is on things with actual letters. This helps 1 to indicate it is a string, and 2 because pretty much all programming languages require it so most people do it. Numbers however always mean numbers and rarely or never are a reserved word in a programming language and thus can be written as numbers without quotes. Just in case you didn't know. :)
I hope this helps.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.