Cop 1500 intro computer science number systems project


Computer Science Number Systems Project Assignment

In this assignment you will add on to the source code from the Number Systems Lab in file "numberSystes.py". In the lab we defined a function for converting a character digit to its numeric value and laid out code that would simulate the Positional Notation method of converting numbers from any base to decimal. We will add to this the functionality to perform the Long Division method of converting a decimal to another base.

First take the code that you wrote that simulates Positional Notation and put it in a new function named "toDecimal". It will need to accept a character number and an integer base as parameters, and will return an integer decimal value.

Then define a function that can convert a number value to a character digit. For right now we will just assume we have valid values, so a zero through nine will convert to "0" through "9", and then a ten through fifteen will convert to "A" through "F".

Now create a function that simulates the long division method of converting a decimal to another base. It will need to receive an integer decimal value, and an integer base to convert it to, and will need to return a string value representing the converted value.

Remember that the long division method takes a decimal and divides it by the base to convert to. Each remainder of the division is the next digit in the result reading right to left. Each quotient from the division is used as the next dividend, until the quotient is zero.

A run of the program should prompt the user to enter a number, the base of the number, and the base to convert to the number to, and then print the results of converting the number to decimal, and then the decimal to the output base.

So a general process flow is:

  • Ask for number to convert
  • Ask for base of number
  • Ask for base to convert to
  • Set decimal to return of "toDecimal" passing the number-in and base-in
  • Print message number-in base base-in is decimal decimal-value
  • Set number-out to return of "fromDecimal" passing decimal and base-out
  • Print message decimal is number-out in base base-out

Outline of the fromDecimal function:

  • Define a string number-out and initialize it to an empty string, i.e. '' or "" (this will allow us to concatenate digits to it in a loop)
  • Set a quotient variable to the decimal passed in
  • Create while loop that checks for quotient great than zero
  • Set a remainder variable to quotient mod base-out
  • Set next-digit to return of valueToDigit passing in the remainder
  • Set a new-quotient variable to quotient integer-division base-out
  • Print this loop as: quotient / base-out = new-quotient , next-digit
  • Append next digit to front of number-out (e.g. sNumberOut = nextDigit + sNumberOut)
  • Set quotient to new-quotient
  • (Loop will continue till quotient is zero)
  • Return number-out

Attachment:- Assignment Files.rar

Request for Solution File

Ask an Expert for Answer!!
Python Programming: Cop 1500 intro computer science number systems project
Reference No:- TGS02665416

Expected delivery within 24 Hours