CS 205 ­ Programming for the Sciences Spring 2011 ­ Programming Assignment 3 20 points Out: January 28, 2011

advertisement
CS 205 ­ Programming for the Sciences
Spring 2011 ­ Programming Assignment 3
20 points
Out: January 28, 2011
Due: February 2, 2011 (Wednesday)
The purpose of this assignment is to continue practicing creating C# programs using MS Visual Studio. Please name the project files and program files exactly as given in the assignment, and please write your name in a comment at the top of the program file Problem Statement
The Mathusian model to estimate the number of grams of a radioactive isotope left after t years is given by the formula:
remaining material= originalmaterial e  t
where  is the decay constant (always less than 0) for a particular isotope.
We would like a program that prompts the user for the original amount of material, the number of years of decay, and the decay constant for the material, reads in these values from the console, then computes and displays the amount of remaining material.
Assignment
Create a C# console project named IsotopeDecayProgram. Rename file "Program.cs" to "IsotopeDecay.cs" (and the class "Program" to "IsotopeDecay").
Write a C# program that implements a solution to this problem. It must meet the following specifications:
It must define a method GetInput. This method prompts the user for the original amount of material, the decay constant for the material, and a (whole) number of years of decay, and reads this input from the console. It passes back this data to the method caller in numeric form as two real numbers and an integer. This method does not return a value Note: just as double.Parse() is used to convert a user input string into a real number value, int.Parse() does the same for integer values.
● It must define a method ComputeDecay. This method receives two real number values and one integer value: the original amount of material, the decay constant, and the number of years of decay, respectively. It computes (using the above formula) and returns the amount of remaining material. Note: the value ex may be computed using pre­defined method Math.Exp(x).
● It must define a method DisplayResults. This method displays the original amount of material, the number of years of decay, and the remaining amount of material on the console. I.e., this method will receive two real values and an integer. This method does not return a value The real number results should be formatted in fixed notation with a precision of 2 and labeled as shown below. Note: the format specifier for an integer is D.
● To complete this assignment, the Main method must solve this problem by calling these methods.
●
01/27/2011
Page 1 of 2
D. Hwang
The program output might look like:
Please enter the amount of radioactive material (in grams): 100
Please enter the decay rate (should be < 0): -0.00012
Please enter the (whole) number of years of decay: 1000
The original amount of radioactive material was 100.00 grams.
After 1000 years of decay, the amount remaining is 88.69 grams.
What to turn in
Make sure your name is in a comment at the top of the program file. Create a zipfile of your entire IsotopeDecayProgram project folder and submit it using the submission system as explained in the handout Submission Instructions for CS 205.
01/27/2011
Page 2 of 2
D. Hwang
Download