CSCI 261 - Programming Concepts - Maynooth 2022

Lab 2A - Procedural Programming with Functions

This lab is due by Friday, July 01, 2022, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.


Instructions


Loops help prevent duplicated code by repeating a given code block some number of times. Functions also help prevent duplicated code by calling a given code block some number of times. Functions have the added benefit of reuseability across projects by being modular.

A common task in programming is to generate a random value within some min-max range. We'll create two functions to assist with this process:

  1. Name: generate_random_integer
    Input: minimum value, maximum value
    Output: a random integer value within the inclusive range [minimum, maximum]

  2. Name: generate_random_float
    Input: minimum value, maximum value
    Output: a random float value within the inclusive range [minimum, maximum]

Write a program that performs the following tasks demonstrating that the functions work properly:

  1. Seed the RNG
  2. Prompt the user for the minimum value
  3. Prompt the user for the maximum value
  4. Print 10 random integers within the range
  5. Print 10 random floats (displaying 3 decimal places) within the range

Extra Credit


Modify both functions to take two additional parameters. These parameters are both booleans and denote whether each of the min/max values should be inclusive or exclusive. Allow the user to enter if each of the minimum and/or maximum values are inclusive or not.


Lab Submission


Submit your main.cpp, Makefile file(s).

You will submit your solution to this lab with the rest of Set2. Detailed instructions for doing this are posted in Assignment 2.


This lab is due by Friday, July 01, 2022, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.