Example Assignment 1

# Example Assignment 1 - Example Assignment 1 TUTORIAL MATTER...

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

Example Assignment 1 TUTORIAL MATTER: Chapters 4 to 7 and 9 of the Study Guide Chapters 4 (section 4.6), 5 (section 5.5), 6 and 9 (excluding the optional parts of section 9.2) of Savitch Answer all the questions. Submit all the programs you are required to write, as well as the input and output of all programs. Copy the programs and the required input and output to ONE word processor file. WE DO NOT ACCEPT ANY FLOPPIES, STIFFIES OR CDs. Question 1 Write a program that will calculate the circumference of a figure. The program must use two overloaded functions, each named calcCircumference. The first function must calculate the circumference of a circle, and will have one parameter of type double that represents the radius of the circle. The second function will have two parameters of type double representing the length and width of a rectangle. Both functions must calculate the circumference and return the value as type double. The main function should request the user to specify whether the circumference of a rectangle or a circle must be calculated, and depending on the answer, the user must either be prompted to enter the radius of the circle, or the length and the width of the rectangle. The main function should then call the correct overloaded function and display the circumference. Define a double constant variable PI with the value of 3.14285 to use for the calculation of the circumference of the circle. Question 2 Write a program that converts a date (dd mm) to julian format. The julian format is the day of the year the ‘dd mm’ date represents, e.g. the julian format of ’27 03’ (i.e. the 27th of March) is 31 + 28 + 27 , i.e. 31 days in January plus 28 days in February plus 27, which gives a julian date of 86. Use the following definition for the number of days in each month: int daysPerMonth[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; You can ignore leap years. The program must ask for 2 dates – read the day and month of each date separately. It must then convert both dates to their julian format, display them, and then display the number of days difference between the two dates. The program must check which is the smaller date before subtracting – the user may enter the dates in any order. Verify that the dates entered are legitimate dates, using the assert function and the above defined array, e.g. 31 6 is not a valid date.

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

View Full Document
Question 3 The quality control team of a sweets factory wants to check if the packets of lollies contain the amount of lollies that they are supposed to contain according to the standards. There are small packets that should contain 50 lollies and large packets that should contain 100 lollies. Every morning a random number of packets are selected, opened and the lollies counted. A file is used to keep record of the number of lollies in each of the randomly selected packets together with an indicator to say whether it is a small or large packet. A different number of packets is selected every day, so that the
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 20

Example Assignment 1 - Example Assignment 1 TUTORIAL MATTER...

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

View Full Document
Ask a homework question - tutors are online