|
|
DT249-1 Programming and Algorithms
Week 02
Learning Outcomes:
Upon completion of this class, you should be able to:
- Declare variables of many different data types.
- Explain the difference between different data types.
- Explain how ASCII codes represent data characters.
- Perform operations on variables of many data types.
- Perform type casts and conversions.
- Justify the requirement to perform type casts and conversions.
- Comment code effectively.
Tasks
|
1. |
Complete the tasks from
last week. |
|
2. |
Download the code for
this week's notes. Go through all the code, compiling and running
each program separately. If you have any problems, ask the lab
supervisor for help, or take a note of the problem and we can
discuss it in next week's class. The code is bundled into a ZIP
file. This is a compressed file which contains all the separate
source code files. To open this file and extract the contents, you
can use the WinZip tool which is available in the lab, and is
available for free download here.
Make sure to put all your code into a folder named week_2
in your programming folder on your u: drive.
|
|
3. |
Write a program which reads in four numbers from the
user, and prints them in reverse order. Call this program
paa_ex_02_01.c and put it in your week_2 folder.
See sample solution here.
|
|
4. |
Suppose that v1, v2 and v3 are three floating point
numbers of values 5.0, -4.5 and 11.259, write a printf(...)
statement in a program to display the following: v1 = 5 v2 =
-4.5 v3 = 11.26
Call this program paa_ex_02_02.c and put it in your week_2
folder.
See sample solution here.
|
|
5. |
Assuming that the human heart beats 75 times per
minute, write a computer program that prompts the user for their age
in years, and prints the number of times their heart has beat so far
in their lives.
Call this program paa_ex_02_03.c and put it in your week_2
folder.
See sample solution here.
|
|
6. |
Write a program which prompts the user to enter a
temperature in degrees Fahrenheit and prints out the temperature in
degrees Celsius. The formula is C = (F - 32) * 5 / 9.
Be careful with type conversions in this program. Remember that
the literal 5 is automatically an int, while the literal 5.0 is
automatically a float. 5 / 9 = 0, whereas 5.0 / 9.0 = 0.555.
Call this program paa_ex_02_04.c and put it in your week_2
folder.
See sample solution here.
|
|
7. |
Comment all your code, and ensure that you use neat a
programming style. If you wish, you can attempt other tasks from
chapters 2, 3 and 4 of the book.
|
Further Reading
Chapters 2, 3 and 4 of
Paul Kelly book.
|