Print the results of 5 simple math operations to the screen; then answer a few questions related to variables.
Textbook: 2.1 - 2.3
Part A01a [3 points]
Create a class named UsernameA01a in a file named
First, create (that is, declare and initialize) two
First number: 5 Second number: 2
Now print the results of using these two variables in five different math expressions using the +, -, *, /, and % operators. Don't just print out the result though; also print out what the expression is. So your final output should now look like this:
First number: 5 Second number: 2 5 + 2 = 7 5 - 2 = 3 5 * 2 = 10 5 / 2 = 2 5 % 2 = 1
In all your calculations and printing, use the two variables you declared at the beginning of your program. So, for example, in producing the above output, the number '5' and the number '2' each occur only once in my code--when I initialize my two variables. You can check you have this correct by changing the initial value of your variables to 7 and 3 and all your output should change appropriately. (Change them back to 5 and 2 when you're done though.)
You may use more than just two variables if you like. For instance, you might want a variable named
Part A01b [3 points]
Now that you have written your program, change the values assigned to your two variables in order to answer the following questions. Remember to recompile each time you change your code. You may also need to look in your book to learn more.
When you are done answering these questions, set your two variables back to 5 and 2, so that your program produces output as above.
What to Submit
Part A01a: Upload your
Part A01b: Paste your answers to the five (or six) questions into the body of an email to me. Do not attach any files. Remember to follow the email submission policies--particularly regarding the subject line.
Grading [6 points]
|~ztomasze Index :
TA Details: ICS111:
|Last Edited: 03 Sep 2008|
©2008 by Z. Tomaszewski.