as4-5 - Introduction to Computer Science I Using C CSC 1253...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction to Computer Science I Using C ++ CSC 1253 Louisiana State University Perfect Numbers—Programming Assignment 4 A perfect number is an integer p > 1 such that the sum of the positive divisors of p equals p . For ex- ample, 6 is a perfect number since 1+2+3 = 6; 28 is a perfect number since 1+2+4+7+14 = 28. Write a complete C ++ program to write to the file perfect.out all perfect num- ber s between 1 and a specified named integer constant LIMIT . For the purposes of the assignment, set the value of LIMIT to 10000. The program is to define and use the following two functions: int sum_of_positive_divisors(int number) that calculates and returns the sum of all positive divisors of the integer ar- gument number ; candidate divisors of number range from 1 to number / 2 . sum of positive divisors() will only be called by is perfect() . bool is_perfect(int number) is a predicate (a boolean-valued function) that returns true iff the integer argu- ment number is a perfect number and false otherwise. is perfect() will call sum of positive divisors() ; is perfect() will only be called by main() . Making Change—Programming Assignment 5 Write a complete C ++ program to do the following: 1. Read a single input record from the text file transactions.dat containing the initial number of each coin and currency type in a till from which change for purchases in a shop is to be made. Echo this information to the text file change.out . 2. Read an arbitrary number of input records from the same file, each con- taining shop transactions consisting of a purchase cost followed by the 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
amount tendered by the customer to pay for the purchase. For each trans- action, print to the text file change.out the following information: (a) the cost (b) the payment (c) the change and the number of each coin and banknote in the change (d) the resulting till contents (the number of each respective coin or cur- rency type remaining in the till after the transaction is completed). As a simplifying assumption the total amount tendered by the cus-
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

as4-5 - Introduction to Computer Science I Using C CSC 1253...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online