[Solved] COMP1400 Lab8- Working with functions

$25

File Name: COMP1400_Lab8-_Working_with_functions.zip
File Size: 348.54 KB

SKU: [Solved] COMP1400 Lab8- Working with functions Category: Tag:
5/5 - (1 vote)

Prime Factors: Any integer above 1 is either a Prime Number, or can be made by multiplying Prime Numbers together. For example:

  • = 2 x 2 x 2 x 2 = (2^4)
  • = (17^1)
  • = 2 x 3 x 3 = (2^1) x (3^2)

After reading an integer number from the user, named num, and given the first prime number 2, your program logic will:

  1. Determine and display how many times this prime number will occur in After finding each prime number, the value of num should be updated by dividing num to the found prime number. For example, after looking for the first prime number of 2 in the input num of 12, num will change to 3 (12 / (22)).
  2. Then the program will determine what is the next prime number, and go back to step a.
  3. Steps a. and b. will continue until the value of num is equal to 1.

Note: Your program should implement at least the following 3 functions (procedures):

  • readNum()to take a valid number (greater than 1) from the user. This function has no input and returns a valid integer number entered by the user.
  • IsPrime() to check if a number is a prime. This function has one integer variable as an input, named prime, and a boolean variable as an output, named p_flag.
  • findPrimeCount() to count the number of a given prime in the input number and display the result in the format of (prime^freq). This function has two integer variables of num and prime as an input and returns the updated num. For example, calling findPrimeCount(12,2)returns the updated number of 3. Hint: The attached findPrimeCount.png provides a solution for this function.

A Sample interaction is as follow:

Enter a valid number (>1): 18
18 = 1 x (2^1) x (3^3)Enter a valid number (>1): 0
Invalid number.Enter a valid number (>1):19 = 1 x (19^1) 19

Part A: RAPTOR Exercise

  1. Understand more about RAPTOR by watching the video about Creating Procedures/Functions.
  2. Start RAPTOR and create the flowchart of Prime Factors.
  3. Save the flowchart to a file named primeFactor.rap in the working directory on the PC you are using.
  4. Demonstrate the primeFactor.rap file to GA/TAs and run with different input values.

Hint: The mode of your Raptor should be Intermediate to be able to add a procedure.

Part B: C Programming Exercise

  1. Implement the algorithm as represented by primeFactor.rap, and write an equivalent C program that accomplishes what the flowchart does.
  2. Save your program to a file named primeFactor.c in the working directory on the PC you are using.
  3. Demonstrate the primeFactor.c file to GA/TAs and run with different input values.

EVALUATION:

You need to show your GA/TA the complete programs at the end of this lab, or at the beginning of your next lab. The marks you will receive for this lab are made of two parts: Lab work marks 10 and attendance marks 5. Total 15 marks.

Lab Work Mark: Your C code will be evaluated based on your solutions for the problems based on the following scheme:

  1. Does the code run and meet specifications?
    • Is input adequate and input data type properly validated?
    • Is processing adequate?
    • Is output correct and adequate?
    • Is the code compliable? Is the code run properly?
  2. Is the code properly commented?
    • Is the program title, programmers first and last name, and the date posted at the top in a multi-line comment?
    • Is each significant step of the program properly commented?
    • Are comments added to clarify details?
    • Are comments clear, accurate, neatly formatted, and have no misspellings?
  3. Is the code properly formatted?
    • Are blocks of code indented according to their parent-child relationship?
    • Do curly braces line up vertically?
    • Is there an empty line between significant steps (blocks) of the program?
    • Is the width of the code contained within a reasonable limit so that minimal horizontal scrolling is required (with 800 x 600 monitor resolution), and there is minimal linewrapping when printed?
    • Is camel-case notation used for variable, e.g. employeeLastName?

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] COMP1400 Lab8- Working with functions
$25