Anda di halaman 1dari 3

CSC180 Assignment 1 Fall 2006

Due: Monday, October 2 by 10:00am

Instructions:
There are 5 problems in this assignment. You need to write a C program and a test plan for each one.
Both your source code files and the test plans with be submitted electronically.

Detailed instructions for electronic submission will be provided on the course website, and you will
practice this in your practicals. You can submit code as many times as you like, so submit early and
submit often. Make sure you submit before the deadline, and please don’t submit corrections after the
deadline (only the last submission counts, so your assignment would be considered late).

Each of your C programs must go in a separate file. Because we will be compiling and running your tests
with automatic scripts, it’s very important that your files are named in a very specific way: the file for
problem 1 should be named a1p1.c, the file for problem 2 should be named a1p2.c, and so on. All letters
in the filenames must be lower-case.

All source code files should start with a comment indicating your name and student number, as well as
the assignment number and problem number. For example:
/* CSC180 Fall 2006, Assignment 1, Problem 3
* Name: Jane Doe
* Student #: 991234567
*/

The test plans for all 5 problems must go in a single text file (plain text – not a word processor file) which
must be named a1testplan.txt. This document does not need to be a fancy report, however it does need to
be clear. See the sample test plan posted on ccnet for a suggested format. Each test plan should be clearly
labeled by problem number. You should also make it easy to tell where one ends and the next begins in
the document – for example, you might draw a line between test plans with dashes or equals signs. Again,
include your name, student number, and the assignment number at the top of the file.

Marking:
This assignment is out of 50. There are three things we award marks for:
Correctness: 30 marks
Test plans: 10 marks
Style: 10 marks

The correctness marks are earned by producing correct results on our tests. Your programs must compile
and run correctly on the ECF system to earn full correctness points.

The style marks are earned by writing your programs with good style. See the style guidelines posted on
ccnet. (As the term progresses, we may add guidelines as they become relevant.)

The test plan marks are earned by submitting thorough and readable test plans.
Problems:

1. Write a program that prompts the user to enter two integers, and then displays the first as a percentage
of the second. Your percentage should be displayed with two decimal places. The following sample run
demonstrates how your program should behave:
First integer: 5
Second integer: 45
5 is 11.11% of 45

2. Despite the elegant neatness of the metric system, some societies remain attached to the quirkier
imperial measurements. Write a program that can be used to convert a speed given in feet per second to
kilometers per hour.

It may help you to know the following conversions:


1 km = 0.621 mi
1 mi = 5280 ft

You may assume the imperial-based speed will be an integer, and the metric-based speed should be
displayed to one decimal place. An example output is:
Enter the speed in ft/s: 580
The metric speed is 636.8 km/h.

3. Not to imply that the imperial system doesn’t have its own charm. It certainly has more creative
names. Consider the measurements that were used by British apothecaries:
20 minims = 1 fluid scruple
24 fluid scruples = 1 fluid ounce

Write a program that allows the user to enter a volume given in minims, and then prints a message
showing the equivalent number of fluid ounces, fluid scruples, and minims. You may assume the user
enters a whole number of minims between 0 and 425 000. All of your reported values should be whole
numbers.

Consider the following sample execution. Your program should be able to reproduce the numbers and the
alignment:
How many minims? 79190
There are: 164 fluid ounces
23 fluid scruples
10 minims

4. Write a program that reads in a double value and prints both the number and its absolute value,
without relying on any library functions. A sample execution looks like:
Enter a number x: -10.782
x = -10.782, |x| = 10.782
5. An integer n is a perfect number if it is equal to the sum of all its proper positive divisors (not
including n itself). For example, the proper positive divisors of 6 are 1, 2, and 3; since 6 = 1 + 2 + 3, 6 is
a perfect number.

Write a program which will determine if numbers entered by the user are perfect or not. The program
should repeatedly prompt the user for input until -1 is entered. A sample execution is as follows:
Enter an integer: 28
28 is a perfect number.
Enter an integer: 1
1 is not a perfect number.
Enter an integer: -1

Anda mungkin juga menyukai