Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-21-2013, 03:19 PM   PM User | #1
legend2nr
New to the CF scene

 
Join Date: Jan 2013
Posts: 7
Thanks: 4
Thanked 0 Times in 0 Posts
legend2nr is an unknown quantity at this point
I need guidance with some coding assignment please help

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
legend2nr is offline   Reply With Quote
Old 01-21-2013, 05:23 PM   PM User | #2
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,224
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
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.
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Old 01-21-2013, 06:04 PM   PM User | #3
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
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?
__________________

I code C hash-tag .Net
Reference: W3C W3CWiki .Net Lib
Validate: html CSS
Debug: Chrome FireFox IE
alykins is offline   Reply With Quote
Old 01-21-2013, 07:56 PM   PM User | #4
legend2nr
New to the CF scene

 
Join Date: Jan 2013
Posts: 7
Thanks: 4
Thanked 0 Times in 0 Posts
legend2nr is an unknown quantity at this point
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 is offline   Reply With Quote
Old 01-21-2013, 07:59 PM   PM User | #5
legend2nr
New to the CF scene

 
Join Date: Jan 2013
Posts: 7
Thanks: 4
Thanked 0 Times in 0 Posts
legend2nr is an unknown quantity at this point
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..
legend2nr is offline   Reply With Quote
Old 01-21-2013, 08:17 PM   PM User | #6
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
Here is a hint- this is what I would call C# pseudo code

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?
__________________

I code C hash-tag .Net
Reference: W3C W3CWiki .Net Lib
Validate: html CSS
Debug: Chrome FireFox IE

Last edited by alykins; 01-21-2013 at 08:21 PM..
alykins is offline   Reply With Quote
Users who have thanked alykins for this post:
legend2nr (01-21-2013)
Old 01-21-2013, 08:36 PM   PM User | #7
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
Also from your code.... (from what I can see, corrections in red)

Code:
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
Code:
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
Code:
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)
__________________

I code C hash-tag .Net
Reference: W3C W3CWiki .Net Lib
Validate: html CSS
Debug: Chrome FireFox IE

Last edited by alykins; 01-21-2013 at 08:45 PM..
alykins is offline   Reply With Quote
Users who have thanked alykins for this post:
legend2nr (01-21-2013)
Old 01-21-2013, 08:37 PM   PM User | #8
legend2nr
New to the CF scene

 
Join Date: Jan 2013
Posts: 7
Thanks: 4
Thanked 0 Times in 0 Posts
legend2nr is an unknown quantity at this point
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 is offline   Reply With Quote
Old 01-21-2013, 08:41 PM   PM User | #9
legend2nr
New to the CF scene

 
Join Date: Jan 2013
Posts: 7
Thanks: 4
Thanked 0 Times in 0 Posts
legend2nr is an unknown quantity at this point
i am now seeing the correction post and i do understand that part. Thanks alot
legend2nr is offline   Reply With Quote
Old 01-21-2013, 08:44 PM   PM User | #10
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
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...

Code:
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
__________________

I code C hash-tag .Net
Reference: W3C W3CWiki .Net Lib
Validate: html CSS
Debug: Chrome FireFox IE
alykins is offline   Reply With Quote
Users who have thanked alykins for this post:
legend2nr (01-21-2013)
Old 01-21-2013, 11:24 PM   PM User | #11
legend2nr
New to the CF scene

 
Join Date: Jan 2013
Posts: 7
Thanks: 4
Thanked 0 Times in 0 Posts
legend2nr is an unknown quantity at this point
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
legend2nr is offline   Reply With Quote
Old 01-22-2013, 01:22 PM   PM User | #12
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
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:
Code:
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
Code:
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
Code:
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)
__________________

I code C hash-tag .Net
Reference: W3C W3CWiki .Net Lib
Validate: html CSS
Debug: Chrome FireFox IE
alykins is offline   Reply With Quote
Users who have thanked alykins for this post:
legend2nr (01-23-2013)
Old 01-23-2013, 10:09 AM   PM User | #13
legend2nr
New to the CF scene

 
Join Date: Jan 2013
Posts: 7
Thanks: 4
Thanked 0 Times in 0 Posts
legend2nr is an unknown quantity at this point
thanks alot
my teacher accepted the pseudocode
legend2nr is offline   Reply With Quote
Old 01-28-2013, 05:13 AM   PM User | #14
sukumar923
New to the CF scene

 
Join Date: Jan 2013
Location: dhaka
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
sukumar923 is an unknown quantity at this point
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?
sukumar923 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 11:04 AM.


Advertisement
Log in to turn off these ads.