Coder Social home page Coder Social logo

swift-unit-conversions-immersive-alum's Introduction

Swift — Unit Conversions

Objectives

  1. Write functions that solve the problem of converting values between different systems of measure.

Instructions

Open the swift-unit-conversions.xcworkspace file. Navigate to the Sandbox.swift file to write your functions.

You can run the tests using U, but you will need to declare all six functions in order to get the build to succeed. If you would like to write your functions one-at-a-time, you may call them with your own test data from the AppDelegate.swift file inside the application:didFinishLaunchingWithOptions: method and running the scheme with R. Use the print() function to send your results to the Console Output viewer.

I. Temperature

The United States still widely uses the Fahrenheit system for measuring temperature on a casual basis (weather-related) instead of the more widely-adopted Celsius scale. Both were developed in the 18th Century but calibrate themselves in slightly different ways.

  1. The freezing point of water is:
  • 32 degrees Fahrenheit and
  • 0 degrees Celsius.
  1. The boiling point of water is:
  • 212 degrees Fahrenheit and
  • 100 degrees Celsius.

fahrenheitFromCelsius(_:)

Write a function named fahrenheitFromCelsius(_:) which converts a Double argument in degrees Celsius to a Double result in degrees Fahrenheit.

celsiusFromFahrenheit(_:)

Write another function named celsiusFromFahrenheit(_:) which converts a Double argument in degrees Fahrenheit to a Double result in degrees Celsius.

Hint: The means that there is a 32 degree (Fahrenheit) offset between the systems, and ratio of 180 degrees Fahrenheit to 100 degrees Celsius—this ratio reduces to the fraction 9/5.

II. Circles

Circular arcs can be measured in either angular degrees or in radians. There are 360 angular degrees in a full circle and 2pi radians in a full circle (which in decimal form is about 6.283~). The Swift Foundation has access to C's math.h library which includes the 48-decimal-point-value of pi accessible as M_PI.

radiansFromDegrees(_:)

Write a function named radiansFromDegrees(_:) which converts a Double argument in angular degrees to a Double result in radians.

degreesFromRadians(_:)

Write another function named degreesFromRadians(_:) which converts a Double argument in radians to a Double result in angular degrees.

Hint: degrees / 180 * pi = radians

III. Distance

The United States, Liberia, and Burma are the only three countries in the world which still use Imperial Units in favor of the Metric System to measure distance. Miles (mi) and Kilometers (Km) are similarly scaled measures of distance across the two systems.

milesFromKilometers(_:)

Write a function named milesFromKilometers(_:) which converts a Double argument in Kilometers (Km) to a Double result in miles (mi).

kilometersFromMiles(_:)

Write another function named kilometersFromMiles(_:) which converts a Double argument in miles (mi) to a Double result in kilometers (Km).

Hint: There are approximately 1.60934 Kilometers in one mile. View this lesson on Learn.co

swift-unit-conversions-immersive-alum's People

Contributors

markedwardmurray avatar misterfifths avatar

Watchers

 avatar James Cloos avatar Mat Balez avatar Victoria Thevenot avatar  avatar Joe Cardarelli avatar Taranjyot Singh avatar Sara Tibbetts avatar The Learn Team avatar Sophie DeBenedetto avatar  avatar Antoin avatar Nicole Kroese  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.