Assignment 2
Assignment 2
Assignment 2
Deadline: 25-Oct-2022 (Tue) 23:59
Objectives
This assignment allows you to practice using:
Console Applications
Methods
Loop Statements
Task
A prime number is a positive integer that is greater than one and has no divisor other than one and itself.
In this assignment, your task is to use Visual Basic to develop a Console Application to read two integers,
namely r1 and r2, from the user and list all the prime numbers in the given range. For example, if r1 = 1
and r2 = 13, the program will output 2, 3, 5, 7, 11, and 13. Note that even if r1 = 13 and r2 = 1, the
program will print the same output. Note that it is possible to have no prime numbers within the range.
You cannot assume that the user input is always valid. If the user input is not valid (e.g., not an integer),
the program will print an appropriate message and ask the user to input again. This process will repeat
until the input is valid (see the Sample Run section for more details).
Hardcoding all possible prime numbers in the program is not allowed. In this assignment, you are
required to define and invoke the following method:
to decide whether n (the parameter) is prime. The function should not print anything, but it will return
True if n is prime and return False if n is not prime. A naive way to test whether n, which is larger than 2,
is prime is to loop through all the numbers between 2 and n – 1 (can this be a smaller number?) and
check whether n is divisible by these numbers. If n is not divisible by all these numbers, it is prime;
otherwise, it is not prime. There are rooms for improvement for this naive method, and you are
welcome to implement a more efficient way for testing whether n is prime.
1
Sample Run
Underlined bold characters in blue are inputs from the user.
Assessment Scheme
Correctness 90%
Program readability (E.g., comments, meaningful variable names) 10%
Testing Platform
Microsoft Visual Studio Community 2022, Windows 10
2
Saving the Project Files
Please use “Save All” to save all the project files in one location but not “Save <file_name>.vb As” to
save some files in other locations. Otherwise, we may not be able to open your submission successfully.
Declaration
As required by the University, please place the following declaration as the comment in the beginning of
your VB source code.
Submission
Please follow the following steps to submit your work.
Step 1: Zip your Visual Basic project folder into a zip file Assg2_<your_student_id>.zip, where
<your_student_id> should be replaced by your student ID (e.g., Assg2_1234567890.zip).
C:\Users\<user_name>\source\repos\<project_name>
Step 2: Go to BlackBoard and login your account by using your OnePass (CWEM) password.
Resubmissions are allowed. But only the latest one will be counted. 10% of your marks will be
deducted for late submission each day after the deadline. Late submissions more than three days will
not be graded.