0% found this document useful (0 votes)
53 views4 pages

Practical 9

Uploaded by

Desmond
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views4 pages

Practical 9

Uploaded by

Desmond
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

DEPARTMENT OF COMPUTER SCIENCE AND INFORMATICS

CSIS 1534 – Practical 9

DATE: 10 May 2023


DUE DATE: End of practical sessions

 All files must include your name and student number at the very top of every file
(The ve concept). Marks will be subtracted for every missing occurrence.
 Your program must run.
 Code that is commented out is not marked.
 You must use comments to separate your program login. In other words, use
comments to mark the different sections of your code.
 Read through the whole document before starting to get an overview of the practical

Develop a Console (.NET Framework) application and name it CompositionOfMoney. Write a


console application that will calculate the composition of an amount of money such that the
smallest number of coins or notes is used (See Figure 1). The following units are available: 1c,
5c, 50c, R1, R10, R100.

Figure 1: Program example


Methods
- Create a method named GetDecimal to validate the amount entered by the user. The
method must return a bool and accept a string prompt. The method should also return
the validated user amount as a decimal through a parameter. The purpose of the method
is to display the prompt and check the user’s input. You may not use try-catch.

- Create a method named DisplayUnits that does not return anything and accepts a
string prompt, the cents to convert, and a unit value as a whole number.
o Unit values refer to the money units that the amount entered can broken down
into.
1
The formal cents paramter and actual cents parameter must refer to the same memory
location. This method should determine how many units the cents can convert to, display
the result (See Figure 3), and get the remaining cents to use in the next unit conversions.

- Create a method called isAnotherOne that returns a bool. This method should prompt
the user for another conversion (See Figure 4) and return the bool result of the user’s
response.

Main() method:
- Use an appropriate loop to run the program at least once before prompting the user for
another conversion.
o The loop should be controlled by the state of one of your custom methods (See
Figure 5 and Figure 6).

- Call the GetDecimal method (Hint: remember it returns a bool) to prompt the user for
an amount and check that the user input is valid.
o If the user’s input is not valid, display a message as in Figure 6 and allow the
user start again. You may not repeat code to allow the user to start again. Call
an existing method instead.
o If the user’s input is valid, convert the amount entered by the user to cents and
call the DisplayUnits method for each unit value and provide prompts for each
unit value as in Figure 3.

Figure 2: Initial screen

Figure 3: Amount entered is broken up into specified units.

2
Figure 4: User is prompted to complete another
conversion.

Figure 5: The user has selected ‘Y’ and is


prompted for new amount.

Figure 6: The user has selected ‘N’ and is


allowed to exit the program.

3
Figure 7: User error detected – message is
displayed and user is prompted to enter
amount again.

Additional test data:

Submission checklist
 I have added a comment block with my information before the using directives.
 I have used comments to separate my program logic.
 I have zipped my entire solution folder and named it correctly: Surname (Student
number) where Surname and Student number is replaced with my own surname and
student number.
 I have downloaded my zipped folder to check that I have submitted the correct project
folder (You must submit the entire project folder, not just the .sln file).

You might also like