[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Critique my pseudocode. Remember, I'm just a beginner.
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 26
Thread images: 2
File: pseudocode-flowcharts-10-638.jpg (76 KB, 638x479) Image search: [Google]
pseudocode-flowcharts-10-638.jpg
76 KB, 638x479
Critique my pseudocode. Remember, I'm just a beginner. I wouldn't mind recommendations.


start
Declarations
string name
string size
string cost
num FISH_SIZE_ONE = 9.00
// the price of daily fish care fee of those under 10"
num FISH_SIZE_TWO = 11.00
// the price of daily fish care fee of those 10" to 20"
num FISH_SIZE_THREE = 13.00
// the price of daily fish care fee of those up to 30"
num FISH_SIZE_FOUR= 15.00
// the price of daily fish care fee of those greater than 30"
stop

housekeeping()
output "This program calculates the daily fish care fee based on the fish's size in inches"
output "Enter customer's name"
output "Enter fish name"
output "Enter fish species"
input name
return

detailLoop()
output "Enter fish length in inches"
input size
if size <= FISH_SIZE_ONE then
cost = 9.00
if size = FISH_SIZE TWO then
cost = 11.00
if size = FISH_SIZE_THREE then
cost = 13.00
if size = FISH_SIZE_FOUR
cost = 15.00
return

finish()
output "Daily fish care fee by size is now calculated"
return
>>
Sorry about the tabbing. It didn't show up.
>>
Why can't you just have a x,y array with prices for each inch and ask the customer to enter inch to nearest inch or round it off?
>>
>>55051883
I honestly don't know. It's programming logic and we are only 4 chapters in. We haven't been taught anything like that yet desu.


Here was the original question if you are curious:
1. There is a fish day care center called Fish-O-Rama.
They need pseudocode for a program that will calculate the daily fish care fee based on a fish's size.
The program must accept the following from the user: Customer Name, Fish Name, Fish Species, and Fish Length (in inches).
Once the data has been entered, the program should display all of the entered data, as well as the daily fish care fee, calculated as follows:
$9 for fish under 10", $11 for fish 10" to 20" inclusive, $13 for fish greater than 20" and up to 30", and $15 for fish greater than 30".
HINTS AND NOTES: Use only NAMED_CONSTANTS (see p. 46) for every constant in the problem.
Be sure to prompt the user for all input. This problem is best solved with nested decisions (see figure 4-20). Don't ask any unnecessary questions (see paragraph at bottom of p. 160).
>>
>>55051831
You can handle all the logic with one statement.

Price = fishSize < 10 ? FISH_SIZE_ONE : ( 10 <= fishSize AND fishSize < 20 ) ? FISH_SIZE_TWO : ( 20 <= fishSize AND fishSize < 30 ) ? FISH_SIZE_THREE : 30 <= fishSize ? FISH_SIZE_FOUR : FISH_SIZE_FOUR ;
>>
My bad I hope this posts comes out alright

a. You can use code tags, or a pastebin for proper formatting

b. Usually there's no need to add declarations in pseudocode

c. those constants seem to have bad names. Why not FISH_FEE_UNDER10, FISH_FEE_10TO20 etc. This way you don't need the comments

d. This is way too verbose
>output "This program calculates the daily fish care fee based on the fish's size in inches"
>output "Enter customer's name"
>output "Enter fish name"
>output "Enter fish species"

Say something like
>output program introduction and prompt the user to input the required information

e. All the outputs in general seem pretty verbose.

f. The ifs are alright I guess, but I would use a switch instead

Overall it's way too verbose, the idea of pseudocode is brevity, you should be able to read the pseudocode of a program like that in 10 seconds or so.

>>55052134
Ternary operators are shit for that, I hope you're trolling.
>>
>>55051831
>if size = FISH_SIZE TWO then
>cost = 11.00
This ain't gonna work at all
>>
>>55052134
I don't think he allows certain syntax format yet. We will be working with Python sometime over the course though. I haven't seen the use of colons or semicolons taught by the course as of yet. This chapter just literally touched on the use of AND and OR... that parenthesis can be used and that these can be used by most modern programming languages... =, >, <,>=,<=, and <>
>>
>>55052271
><>
Are they seriously teaching that as standard? I mean damn I knew the book or whatever you're using was shit from the problem exercise but that's shittier than I thought
>>
>>55052161
Thanks for the suggestions. Did you look at the original question when adding your input? I pasted it later on.

How would you output all those questions on a single line? My Programming Logic textbook shows all the outputs like that... I was actually more worried about my ifs actually. The throwing out the comments does sound like a good idea but he had us use those in our 2nd assignment. This is literally just assignment 4. I don't think he would've minded if they were thrown out in this case in exchange for your constants.

I know comments are still very important, especially with expansive program coding.
>>
>>55052295
Yes, they are. It's in there but to their credit, it did say it was pretty useless since there are much better ways of saying "not equal to"
>>
>>55052383
Comments aren't nearly as important as you think. Code should be first and foremost self documented.

The if statements won't work, you're basically asking is the input equal to 9? Then print 9
Is the input equal to 11? Then print 11
And so on.

If size < 10
Cost= fishsizeone
Else if size >= 10 && size < 20
Cost = fishsizetwo
Etc

Also there's a problem because the user may input either a negative integer or a character or an empty string, etc in which case you should prompt him to type a proper input
>>
File: how_do_i_code_tag.png (23 KB, 317x314) Image search: [Google]
how_do_i_code_tag.png
23 KB, 317x314
>>55051854
Write your code like this:
int main(int argc, char **argv) {
printf("Fagots\n");
return 0;
}
>>
>>55052456
Thanks for the pointer. Were the two &&'s for a purpose or in my case since we just learned AND make more sense for this assignment? I haven't been told I could use a & yet either.
>>
>>55052560
It depends on the language. Some support &&, some only and. You probably should just type in and for brevity and to not make your code too fancy for a beginner
>>
>>55051831
>disadvantages are just the other method's advantages reworded
Disgusting. Absolutely disgusting.
>>
>>55051831
Use a switch statement for the fish size
>>
Just out of curiosity, what do you guys think of pseudo code? I've never used it in my life and it sounds like some serious retarded shit especially when you don't know how syntax or programming actually works.
Now with some background knowledge of python/c/js, it's understandable.. Is this taught extensively in all CS courses?
>>
>>55055044
I've used it once in my intro to algorithm class, I didn't like how loose the language is and never actually executed any pseudo code program because apparently there's no compiler for it. So yes it is retarded
>>
>>55055044

>Just out of curiosity, what do you guys think of pseudo code?

I think it's nonsense, people should just put it down in C, Java or Python.

On the other hand, the big plus I see is that in pseudo code you can write stubs for complex stuff like:

a = calculate the sum of squares for all numbers that in A


>Is this taught extensively in all CS courses?

We had it a lot in "combinatorial optimization", but it's really a pain in the ass IMHO. Often I just looked at the actual algorithm instead of the pseudo code to understand it.


>>55051831

Good beginner code.
But I think this:
>if size = FISH_SIZE TWO then
cost = 11.00

..should be:
>if size =< FISH_SIZE TWO then
cost = 11.00

Right?


Personally I'd put the Fish sizes in an array:
fishsize[0] = 9.0;
fishprice[0] = 9.0;

fishsize[1] = 11.0;
fishprice[0] = 11.0;

fishsize[2] = 13.0;
fishprice[0] = 13.0;

fishsize[3] = 15.0;
fishprice[3] = 15.0;

currentFish = getSice();

for (i=0 ; i<4 && currentFish<fishsize[i] ; i++) (){
}

cost = fishprice[i];


You could even use a sorted map for that, but that would be a littel bit overengineering IMHO.
>>
>>55055403

Sorry, of course I meant:

fishprice[0]
fishprice[1]
fishprice[2]
fishprice[3]
>>
>>55055403
>I think it's nonsense
That reply is just as stupid as the code you posted.
Pseudo is good, GOOD GOOD GOOD. But only if you know how to write it.
Btw one of the best books on algorithmms is entirely in pseudocode.
>>
>>55055440

> as stupid as the code you posted

How rude..
What' wrong with my code?

You just iterate until you get to the highest weight (or meet the highest index). That's the easiest and most robust way I can think of.

>Pseudo is good, GOOD GOOD GOOD.

Keep telling yourself that.

There is literally no need for pseudo code, once you can code.
If you commetn properly (and you do, anon, right.. !?) you should even be able to read code in a unknown programming language fluently.
>>
>>55055493
You're retarded
>>
>>55055511

Go poo in loo, ktnxbye.
>>
>>55055511
Nice job supporting your argument Pajeet
Thread replies: 26
Thread images: 2

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.