From e2f11c7a273005e1d00526a147c093001a9a14a8 Mon Sep 17 00:00:00 2001 From: Jenessy Lustre Date: Tue, 15 Oct 2024 10:47:00 -0700 Subject: [PATCH] qe2 --- lab-2/LANGUAGE.md | 18 ++++++++++- lab-2/quadratic-snippet.cbl | 63 +++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/lab-2/LANGUAGE.md b/lab-2/LANGUAGE.md index 12553e2..5dbe42c 100644 --- a/lab-2/LANGUAGE.md +++ b/lab-2/LANGUAGE.md @@ -1,3 +1,19 @@ # Language Proposal -TODO Detail language here +### 1. Hello World + + +### 2. Quadratic Function +- Note: code needs to be formatted +- credit to [Marco Biagini](https://www.quora.com/What-is-a-COBOL-program-that-will-solve-a-quadratic-equation) +- a quadratic equation of the form **ax^2 + bx + c = 0** + + #### Input + User will be prompted for a, b, and c (ex. 1, 5, 6) + #### Output + Program will display the real roots or if there are no real roots (ex. -2, -3) + + +### 3. Integer Sort + +### 4. Language Features diff --git a/lab-2/quadratic-snippet.cbl b/lab-2/quadratic-snippet.cbl index e69de29..86598aa 100644 --- a/lab-2/quadratic-snippet.cbl +++ b/lab-2/quadratic-snippet.cbl @@ -0,0 +1,63 @@ + /*code from https://www.quora.com/What-is-a-COBOL-program-that-will-solve-a-quadratic-equation + + IDENTIFICATION DIVISION. + + PROGRAM-ID. QuadraticSolver. + + DATA DIVISION. + + WORKING-STORAGE SECTION. + + 77 a PIC S9(5)V9(5) COMP-3. + + 77 b PIC S9(5)V9(5) COMP-3. + + 77 c PIC S9(5)V9(5) COMP-3. + + 77 discriminant PIC S9(5)V9(5) COMP-3. + + 77 root1 PIC S9(5)V9(5) COMP-3. + + 77 root2 PIC S9(5)V9(5) COMP-3. + + 77 square-root-discriminant PIC S9(5)V9(5) COMP-3. + + PROCEDURE DIVISION. + + DISPLAY "Enter the coefficients of the quadratic equation (a, b, c): ". + + ACCEPT a + + ACCEPT b + + ACCEPT c + + COMPUTE discriminant = (b ** 2) - (4 * a * c) + + IF discriminant > 0 + + COMPUTE square-root-discriminant = FUNCTION SQRT(discriminant) + + COMPUTE root1 = (-b + square-root-discriminant) / (2 * a) + + COMPUTE root2 = (-b - square-root-discriminant) / (2 * a) + + DISPLAY "The equation has two distinct real roots: " + + DISPLAY "Root 1: " root1 + + DISPLAY "Root 2: " root2 + + ELSE IF discriminant = 0 + + COMPUTE root1 = -b / (2 * a) + + DISPLAY "The equation has one real root: " + + DISPLAY "Root: " root1 + + ELSE + + DISPLAY "The equation has no real roots." + + STOP RUN. \ No newline at end of file