In this lab you will create some simple programs to practice what you've learned about:
You should pay special attention to using good coding style so that your code is readable, consistant, and easy to understand.
Ideally, both of the programs you create in this assignment should accept user input from the keyboard to get the initial data needed to do their work. You can read in a single integer value and store it in a variable with the following two lines of code:
int example;
scanf("%d", &example);
However, at this stage of the course we have not learned enough about C to fully understand how this code works. If you are uncomfortable using this code, feel free to provide your "input" data as hard-coded symbolic constants instead, eg:
#define INPUT 1324
Write a program that calculates the acceleration of the weights in an Atwood machine. The weights are connected by a massless cable that runs through an ideal pulley and are under the influence of gravity, such that the acceleration is given by the equation:
Assume that g, the acceleration due to gravity, is exactly 9.806 m/s2.
The masses of the two weights are the inputs to your program, and should be expressed as positive integers. The unit of measurement is irrelevant due to the structure of this formula (although the same unit must be used for both).
Your program should print the acceleration in m/s2 to standard output, with a minimum of 2 decimal places of precision.
Write a program that converts a pool of loose change into bills and coins using the largest possible denominations. The program should take a total value of cash in cents as input, and print the number of $10 bills, toonies ($2 coins), quarters (25¢), dimes (10¢), and pennies (1¢) that together total that value as output.
Your program should be written in a way that allows code for new denominations to be added (or existing denominations to be removed) without substantially changing the code for other bills and coins. For example, it should be easy to add output for $20 bills, loonies ($1), or nickles (5¢).
Your approach should be something like:
For example, given an input of 3049 cents, your output might look like:
3 $10 bills 0 toonies 1 quarters 2 dimes 4 pennies
Completing all tasks in this lab should result in 2 separate C files within a single folder named like LastnameFirstname_lab1. Compress the folder into a ZIP archive and upload it to the D2L assignment.
The marks for this lab are heavily weighted towards good coding practice and style. Pay attention to your code formatting, use comments to clarify your code, and make sure you are using symbolic constants and variables effectively.
NOTE: This assignment is to be done individually. You can help one another with problems and questions, but in the end everyone must write and submit their own code.
Criteria | Marks |
---|---|
Programs compile and run without error | 3 |
Good coding style | 3 |
Task requirements met or exceeded | 3 |
Learning Outcomes achieved | 3 |
Total | 12 |