...

View Full Version : I need guidance with some coding assignment please help



legend2nr
01-21-2013, 03:19 PM
hello coding forum users

I am having alot of difficulty writing pseudo code for an assignment. I have started a degree in computing about 2 months ago. I have done the assignment 3 times only to have it rejected 3 times by my lecturer who seems to understand coding but we are having trouble communicating with each other.Anyway i have to write pseudo code for this problem i am hoping someone can help me as the assignment it is due monday...If any can help please pm and i will send my version(s) of the solution there as i dont want to post it up because of fear of turnitin..my plagarism checker. will pick it .if i infact use my solution with the same variable names and such.
The problem is

develop a program that takes in two numbers in any of the following
formats:
decimal
binary
hexadecimal
The program should then convert both numbers to decimal (if they are not already in decimal format), add
the two numbers together and display the result as a decimal value.

I am not trying to cheat or anything i have solutions which i will provide but my teacher is not seeing my insight and is not helping in guiding me. If anyone can help please do

Spookster
01-21-2013, 05:23 PM
How about you show us what your lecturer has already rejected so that we can maybe shed light on why they did not accept it.

alykins
01-21-2013, 06:04 PM
is the problem that you are submitting pseudo code when the assignment states you need to submit a program? Also if you are to submit a program, then copy/pasting pseudo code will not count as plagarism as pseudo code will not compile and thus can not be the final submission. AND! since it is an assignment, no one will just give you the answer, we will help you figure it out on your own though. If you are the one who figures it out, then how is it plagarism if they find your own post of it online?

legend2nr
01-21-2013, 07:56 PM
its not a program its pseudocode. Im new to the whole plagarism stuff so im not sure but im really not asking for a hand out. I'm really trying to wrap my head around this. The lecturer says i have the main body correct..which is this...the functions i need clarification with how it works.

num1 as a string
num2 as a string
base1 as a whole number
base2 as a whole number
dec1 as a whole number
dec2 as a whole number
sum as whole number

Set dec1 = 0
Set dec2 = 0

“Please enter the first number”
Read num1
“Please enter the second number”
Read num2
“Please enter the base of the first number
Read base1
“Please enter the base of the second number
Read base2
If base1 = 10 then
Convert to integer -48
num1 = dec1
Otherwise
If base1 = 2 then
dec1= Call GeneralF ( num1, base1)
Otherwise
If base1 = 16 then
dec1 = Call GeneralF (num1,base1)
Otherwise
End If

If base2 = 10 then
Convert to integer - 48
num2 = dec2
If base2 = 2 then
dec2 = Call GeneralF ( num2, base2)
Otherwise
If Sbase2 = 16 then
dec2 = Call GeneralF (num2, base2)
Otherwise End If

Sumdec = Call AddTwoNumbers ( Fdec1, Sdec2)
Output “ The sum of the two numbers in decimal format “ + “ “ Sumdec



The function Gfunction checks the base of the numbers and contains subfunctions of if statements to convert the number from hex to dec asciii and from binary to decimal asciii then sends the answer back to the Gfunction. Gfunction then uses loops using string manipulation and arrays to convert to decimal..my lecturer wants us to write one general function to handle the two numbers but i wrote one set of functions for each number..num1 and num2...as each time i call the gfunction i call its parameters num1 and base1...i do not understand how i would write only one set if i have four parameters paired off..num1 base1..num2..base2...

legend2nr
01-21-2013, 07:59 PM
also i have the correct functions (i think) but how im getting the functions generalized for two numbers one after each other is beyond me..

alykins
01-21-2013, 08:17 PM
Here is a hint- this is what I would call C# pseudo code



string tmpNum;
string tmpBase;
int base;

main()
{
int[] dec = new int[3];

for(int i=0; i < 2; i++)
{
"please enter the" + (i+1) + "number"
tmpNum = read
"please enter the numbers format"
tmpBase = read
base = convert.ToInt(tmpBase)
dec[i] = FormatNumber(tmpNum, base)
}

dec[2] = dec[0] + dec[1]
"the output of the two numbers in decimal is " + dec[2]
}

function FormatNumber(string s, int format) //returns int
{
switch(format)
case 10:
return convert.ToDecimal(s) // a fxn that converts from string to decimal
case 2:
return convert.FromBinary(s) // a fxn that converts string to binary, then to dec
case 16:
return convert.FromHex(s) // a fxn that converts string to hex, then to dec
default:
throw new exception
}


Edit: I am not sure if that matches what your lecturer wants for criteria... You should be looking to consolidate code whereever you can. Also case statements are a lot nicer than multiple if statements

Edit Edit: What language are you learning?

alykins
01-21-2013, 08:36 PM
Also from your code.... (from what I can see, corrections in red)



num1 as a string
num2 as a string
base1 as a whole number
base2 as a whole number
dec1 as a whole number
dec2 as a whole number
sum as whole number

Set dec1 = 0
Set dec2 = 0

“Please enter the first number”
Read num1
“Please enter the second number”
Read num2
“Please enter the base of the first number
Read base1
“Please enter the base of the second number
Read base2

If base1 = 10 then
Convert to integer -48
//num1 = dec1
dec1 = num1

Otherwise if
If base1 = 2 then
dec1= Call GeneralF ( num1, base1)

Otherwise if
If base1 = 16 then
dec1 = Call GeneralF (num1,base1)

Otherwise
throw exception
End If

If base2 = 10 then
Convert to integer - 48
//num2 = dec2
dec2 = num2

Otherwise If base2 = 2 then
dec2 = Call GeneralF ( num2, base2)

Otherwise If
Sbase2 = 16 then
dec2 = Call GeneralF (num2, base2)

Otherwise
throw exception
End If

//Sumdec = Call AddTwoNumbers ( Fdec1, Sdec2)
Sum = Call AddTwoNumbers ( dec1, dec2)
Output “ The sum of the two numbers in decimal format “ + “ “ Sum // no dec as in Sumdec


The otherwise statements would be the equivilent of doing this


if(...)
//do something
else(...)
//do the other thing.... this ends the if statement
else(...)
//do another thing... there is no paired if(...) compile error
else(...)
// you had no code here, same as above, no if(...) and pointless code as it does nothing, bad codeing skill better to not do, you can just do the if(...) and move on as in


if(something == true)
{
//code
}
else
{
}

output "tada"

could just be
if(something == true)
{
//code
}

output "tada"



You also try to use an/or pass variables you never declare (slightly off, see red comments). Then you have the assignments in the wrong order (also in red)

legend2nr
01-21-2013, 08:37 PM
i believe case statements are outside my scope of course because i see no mention of it..the course is software development techniques..its an introduction of pseudocode no language coding..C+ and java and such would be next year...what we learnt was iteration desk checking selection arrays functions..thats all...the way i wrote it is the exact way i learnt it and she wants it..Thanks for the reply but i dont understand the stuff u wrote as ive never seen it before :(

legend2nr
01-21-2013, 08:41 PM
i am now seeing the correction post and i do understand that part. Thanks alot

alykins
01-21-2013, 08:44 PM
Ok, I thought after the fact that my first reply might be over your head- does my second reply using your code make more sense? Now if she just wants you to use one statement think on this...



num as a string
base as an int
dec as an int array(3)

loop
do something here to ask for num and base
convert the input somehow and then assign to a spot in the dec array (hint you should use 2 spots)
end loop

do something with dec array to show correct output (hint last array spot)


does that help or clarify anything?

Edit: np, glad to help :) post any more Q's

legend2nr
01-21-2013, 11:24 PM
yes this helps alot
so your saying i declare generic variables for the functions such as num and base so when the function calls the first time num1 would equate to num and store the answer in dec1 and the second time num2 would equate to num as well and then store that answer in dec2? I hope this is what your saying :)

alykins
01-22-2013, 01:22 PM
you declare the variables for the function (known as arguments) and then you reference them in the functions code. It will then expect those arguments, of that type, in that order or else throw an exception
Example:


function demo(string s, integer i, boolean b)
{
if(b)
output "the boolean passed was true"
else
output "the boolean passed was false"


loop from 0 to i
output "the string passed is " + s
end loop

}


now you would call it like this


call demo("cat", 4, true)

// output
// "the boolean you passed was true"
// "the string passed is cat" // i = 0
// "the string passed is cat" // i = 1
// "the string passed is cat" // i = 2
// "the string passed is cat" // i = 3


note that this would throw an error


call demo(true, "banana", 99)


you can make different constructors that would handle variables being passed in different orders, as well as more or less arguments- but I think your teacher will go over that (it's more advanced)

legend2nr
01-23-2013, 10:09 AM
thanks alot :)
my teacher accepted the pseudocode

sukumar923
01-28-2013, 05:13 AM
I do not know the situation this someone are usually send pseudo code when the assignment cities you should submit a tool? But also if you're to be able to submit that process, next back up/pasting pseudo code can't count when plagarism when pseudo code will not collect thereby cannot remain the final application. AND! because it was a good assignment, no one can only provide both the answer, we tend to will certainly enable you to character this out on your own although. In case you are the one that figures this can away, next just how is it plagarism as long that they source your own own add regarding that on the market?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum