Exercises: Intrinsic Functions

Exercise 20.1: String Function Basics

Write a program that accepts a customer name (up to 40 characters) and: 1. Displays it in UPPER-CASE and LOWER-CASE 2. Displays the REVERSE of the trimmed name 3. Displays the LENGTH of the full field and the trimmed content 4. Extracts and displays the first character using reference modification with FUNCTION LENGTH to verify it is within bounds

Exercise 20.2: Numeric Conversion Pipeline

Write a program that processes a batch of 10 alphanumeric amount strings (some valid, some invalid). For each string: 1. Use TEST-NUMVAL-C to validate before conversion 2. Convert valid strings using NUMVAL-C with "$" as the currency symbol 3. Track and display: count of valid conversions, count of invalid strings, total of all valid amounts

Test data should include: "$1,234.56"`, `"$0.99", "INVALID", "-$500.00"`, `"$1,000,000.00", etc.

Exercise 20.3: Mathematical Functions

Write a program that: 1. Accepts a positive number and displays its SQRT, LOG, LOG10, and EXP 2. Accepts an integer 0-12 and displays its FACTORIAL 3. Computes and displays the value of e (using FUNCTION EXP(1)) and pi (using FUNCTION PI if available, or 4 * FUNCTION ATAN(1) if your compiler has ATAN) 4. Validates all inputs before passing to functions (e.g., SQRT of negative number)

Exercise 20.4: Statistical Analysis

Write a program that loads 20 exam scores into a table and computes: 1. MEAN, MEDIAN, VARIANCE, STANDARD-DEVIATION 2. MIN, MAX, RANGE 3. The position of the highest and lowest scores (ORD-MAX, ORD-MIN) 4. A letter grade for each score based on distance from the mean (A = above mean + 1 SD, B = above mean, C = within 1 SD below mean, D = below mean - 1 SD, F = below mean - 2 SD)

Exercise 20.5: Financial Calculator

Build an interactive financial calculator that: 1. Accepts a loan principal, annual interest rate, and term in years 2. Computes monthly payment using FUNCTION ANNUITY 3. Computes total interest paid over the life of the loan 4. Computes present value of the payment stream using FUNCTION PRESENT-VALUE 5. Displays a comparison of two different loan terms (e.g., 15 vs. 30 years)

Exercise 20.6: Date Arithmetic

Write a program that: 1. Displays the current date and time using FUNCTION CURRENT-DATE 2. Computes the day of the year (1-366) from the current date 3. Computes the number of days until December 31 of the current year 4. Accepts two dates (YYYYMMDD) and computes the number of days between them 5. Adds 90 days to a given date using INTEGER-OF-DATE and DATE-OF-INTEGER

Exercise 20.7: Combined Functions — Data Cleansing

Write a data cleansing program that processes customer records with potentially messy data: 1. Trim and upper-case all name fields 2. Validate and convert all amount fields using TEST-NUMVAL-C / NUMVAL-C 3. Validate date fields using INTEGER-OF-DATE (invalid dates cause runtime errors) 4. Produce a clean output file and an error report

Exercise 20.8: Statistical Process Control

Simulate a quality control system. Load 50 measurement values into a table, then: 1. Compute the mean and standard deviation 2. Determine Upper Control Limit (mean + 3SD) and Lower Control Limit (mean - 3SD) 3. Flag any measurement outside the control limits 4. Compute the percentage of measurements within limits 5. Display a simple text-based control chart (asterisks for each value relative to the limits)

Exercise 20.9: GlobalBank Interest Calculator

Write a CD interest calculator for GlobalBank that: 1. Accepts principal, annual rate, and term (months) 2. Computes simple interest: Principal * Rate * (Term/12) 3. Computes compound interest: Principal * ((1 + Rate/12) ^ Term - 1) using EXP and LOG 4. Computes the present value of the maturity amount 5. Displays all results formatted as currency

Exercise 20.10: Challenge — Function-Based Report Generator

Build a comprehensive statistical report generator that reads a file of numeric data and produces: 1. Descriptive statistics (count, mean, median, mode, variance, SD, skewness) 2. Percentile calculations (25th, 50th, 75th percentiles) 3. Outlier detection (values beyond 2 standard deviations) 4. A frequency distribution (divide the range into 10 equal bins and count values in each) 5. Use only intrinsic functions and reference modification — no external libraries