IPC144 – Computations Solved

$ 20.99
Category:

Description

Workshop 2 (out of 10 marks – 2% of your final grade)

In this workshop, you will code and execute a C-language program that accepts numerical values from the user, stores the values in variables of appropriate data type, performs calculations on the stored variables and casts from one data type to another.
LEARNING OUTCOMES
Upon successful completion of this workshop, you will have demonstrated the abilities:
• to declare variables of integral and floating point types
• to code a simple calculation using C operators and expressions
• to accept a numerical value from the user using scanf
• to cast a value from one data type to another

SUBMISSION POLICY
All your work (all the files you create or modify) must contain your name, Seneca email and student number.
You are responsible to back up your work regularly.

Late submission penalties:
– In-lab portion submitted late, with at-home portion: 0 for in-lab. Maximum of 70/70 for at-home and reflection
– If any of in-lab, at-home or reflection portions is missing the mark will be zero.

IN_LAB: DONE IN CLASS (30%)
Download or clone workshop 2 (WS02) from https://github.com/Seneca-144100/IPCWorkshops
In the in_lab directory of workshop 2, right-click on the file in_lab.vsxproj and select the “Open With” context menu item then select “Microsoft Visual Studio 2017” to open the workshop in Visual Studio.
In the Visual Studio solution explorer panel, open and write your code in cashRegister.c for workshop 2.
Please enter the amount to be paid: $
Assume the user enters 8.68, this is what the screen should look like:
(<ENTER> means hitting the enter key)
Please enter the amount to be paid: $ 8.68 <ENTER>
Loonies required: 8, balance owing $0.68 Quarters required: 2, balance owing $0.18 Execution and Output Example:
Please enter the amount to be paid: $8.68
Loonies required: 8, balance owing $0.68
Quarters required: 2, balance owing $0.18
IN_LAB SUBMISSION:
To test and demonstrate execution of your program use the same data as the output example above.
If not on matrix already, upload your cashRegister.c to your matrix account. Compile and run your code and make sure everything works properly.

AtThePrompt> gcc -Wall cashRegister.c –o ws<ENTER>

-Wall activates the display of warnings in GCC compiler.
-o sets the executable name (ws)
Then run the following script from your account: (replace profname.proflastname with your professors Seneca userid)

~profname.proflastname/submit 144_w2_lab <ENTER>

and follow the instructions.

AT_HOME: (30%)
After completing the in_lab section, edit and upgrade cashRegister.c to add the GST to the total entered by the user.
Problem: 8.68 * .13 is equal to 1.1284, which should be rounded up to 1.13, and the format specifier %.2lf will display as 1.13, but the number will be truncated to 1.12 on a C standard compiler, such as matrix, if we multiply by 100 and cast to an int, which we must do at some point in the program.
To find the correct value for GST do the following:
GST = amountOwing * .13 + .005; (result is 1.1334 which will resolve to 1.13 when either rounded or truncated)
After Calculating the number of loonies required, subtract the number of loonies from the amountOwing, then cast the remaining decimal portion to an int. The subsequent operations must be done using integer division and modulus. Although the answer can be derived without using the modulus operator, failure to use modulus will result in a grade of 0 for the At_Home portion of the workshop.
Hints:
– Read about casting, division and modulus in the notes
– 0.35 * 100 = 35
– You can output the value 5, stored in an int variable as $0.05 like this: printf(“$%1.2f”, (float)intBalance/100);
Execution and Output Example:
Please enter the amount to be paid: $8.68
GST: 1.13
Balance owing: $9.81
Loonies required: 9, balance owing $0.81
Quarters required: 3, balance owing $0.06
Dimes required: 0, balance owing $0.06
Nickels required: 1, balance owing $0.01
Pennies required: 1, balance owing $0.00 AT-HOME REFLECTION (40%)
Please provide brief answers to the following questions in a text file named reflect.txt.
1- What do think is the most important thing you learned in this workshop?
2- Why must you add .005 to the value derived when calculating the GST owing?
3- What is the result of a casting operation?
4- Why do you think you were required to use the modulus operator in this workshop?
Note: when completing the workshop reflection it is a violation of academic policy to cut and paste content from the course notes or any other published source, or to copy the work of another student.

AT_HOME SUBMISSION:
To test and demonstrate execution of your program using the same data as the output example above.
If not on matrix already, upload your cashRegister.c and reflect.txt to your matrix account. Compile and run your code and make sure everything works properly.

AtThePrompt> gcc -Wall cashRegister.c –o ws <ENTER>
Then run the following script from your account: (replace profname.proflastname with your professors Seneca userid)
~profname.proflastname/submit 144_w2_home <ENTER>
and follow the instructions.

Reviews

There are no reviews yet.

Be the first to review “IPC144 – Computations Solved”

Your email address will not be published. Required fields are marked *