In GO Lang Now edit the file hw1.go so it is in package main a function CalcPressure that takes 3 parameters: v, n, t, which represent volume, amount (also called molarity) and temperature of an ideal gas and returns the pressure the gas is under the parameters and return type are all of type float64 the pressure is calculated by the ideal gas law: p = nRt/v, where R is the Ideal Gas Constant volume is in cubic meters, amount is in moles, temperature is in degrees Kelvin and pressure is in pascals (newtons per square meter). This makes R = 8.3144598 https://sciencetrends.com/in-pvnrt-what-is-the-r-constantLinks to an external site. has what seems to be a decent explanation (I have the limited understanding that comes from high school chemistry and a year of physics in college.) An example result: CalcPressure(1.0, 1.0, 298.15) should return approximately 2478.9562 pascals You can get more results from one of the many online calculators. Ideal Gas Law Calculator [pv=nrt] - [100% Free] - Calculators.ioLinks to an external site. is one example where the ads did not seem too bad. It makes sense to test the function with simple values so you can easily check if you have a correct answer, but the type really does need to be of type float64. The grader will expect this A function Decode that takes 2 parameters: e and c and uses the code c to return the decrypted version of e The encrypted text e and the return type are []byte, but the code c is a map of byte to byte The decrypted text is the string e mapped by the code, so to decrypt ‘a’, just replace it with the byte c[‘a’] If the code map does not contain the byte, just use the byte. For example, the standard substitution ciphers that replace letters with other letters leave spaces and punctuation alone. Ex: suppose c[‘e’] = ‘u’, c[‘h’] = ‘f’, c[‘l’] = ‘n’, c[‘o’] = ‘y’. Then Decode([]byte(“hello”), c) should return the slice of bytes [‘f’, ‘u’, ‘n’, ‘n’, ‘y’] Note that strings must be explicitly cast to arrays of bytes and vice versa – they are not the same type The quotes, single and double are the Unicode characters for left and right quotes, as a word processor like Word will produce. If you copy-and-paste these to your code, you will have to replace them by the quotes that programming languages use A function OddParity that takes a slice of ints and returns two values. The first return value is true if the list has an odd number of 1’s, false if it has an even number of 1’s. The second return value is true if all values are 0’s or 1’s, false if there are any other values (like a 52). This function gives you a reason to use a loop Ex: OddParity([]int{0,1,1,1}) should return true, true   Write main() to demonstrate that your functions work as desired. You should have two calls for each function to prevent yourself from hard-coding the wrong things as well as to capture different cases. The OddParity cases should cover both true and false for both return values.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter9: Records (struct)
Section: Chapter Questions
Problem 2PE
icon
Related questions
Question

In GO Lang

Now edit the file hw1.go so it is in package main

  1. a function CalcPressure that takes 3 parameters: v, n, t, which represent volume, amount (also called molarity) and temperature of an ideal gas and returns the pressure the gas is under
  • the parameters and return type are all of type float64
  • the pressure is calculated by the ideal gas law: p = nRt/v, where R is the Ideal Gas Constant
  • volume is in cubic meters, amount is in moles, temperature is in degrees Kelvin and pressure is in pascals (newtons per square meter). This makes R = 8.3144598
    • https://sciencetrends.com/in-pvnrt-what-is-the-r-constantLinks to an external site. has what seems to be a decent explanation (I have the limited understanding that comes from high school chemistry and a year of physics in college.)
  • An example result: CalcPressure(1.0, 1.0, 298.15) should return approximately 2478.9562 pascals
    • You can get more results from one of the many online calculators. Ideal Gas Law Calculator [pv=nrt] - [100% Free] - Calculators.ioLinks to an external site. is one example where the ads did not seem too bad.
  • It makes sense to test the function with simple values so you can easily check if you have a correct answer, but the type really does need to be of type float64. The grader will expect this
  1. A function Decode that takes 2 parameters: e and c and uses the code c to return the decrypted version of e
  • The encrypted text e and the return type are []byte, but the code c is a map of byte to byte
  • The decrypted text is the string e mapped by the code, so to decrypt ‘a’, just replace it with the byte c[‘a’]
  • If the code map does not contain the byte, just use the byte. For example, the standard substitution ciphers that replace letters with other letters leave spaces and punctuation alone.
  • Ex: suppose c[‘e’] = ‘u’, c[‘h’] = ‘f’, c[‘l’] = ‘n’, c[‘o’] = ‘y’. Then Decode([]byte(“hello”), c) should return the slice of bytes [‘f’, ‘u’, ‘n’, ‘n’, ‘y’]
    • Note that strings must be explicitly cast to arrays of bytes and vice versa – they are not the same type
    • The quotes, single and double are the Unicode characters for left and right quotes, as a word processor like Word will produce. If you copy-and-paste these to your code, you will have to replace them by the quotes that programming languages use
  1. A function OddParity that takes a slice of ints and returns two values. The first return value is true if the list has an odd number of 1’s, false if it has an even number of 1’s. The second return value is true if all values are 0’s or 1’s, false if there are any other values (like a 52).
  • This function gives you a reason to use a loop
  • Ex: OddParity([]int{0,1,1,1}) should return true, true

 

  1. Write main() to demonstrate that your functions work as desired. You should have two calls for each function to prevent yourself from hard-coding the wrong things as well as to capture different cases. The OddParity cases should cover both true and false for both return values.
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Reference Types in Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT