0% found this document useful (0 votes)
3 views9 pages

Chapter 4 Ex AI

The document outlines pseudocode for various programs, including one that checks student GPAs and identifies those below 2.0, and another that calculates call costs based on input parameters. It includes loops for continuous input until a sentinel value is reached, and conditions to display specific outputs based on the input data. Additionally, it describes the structure of flowcharts corresponding to the pseudocode logic.

Uploaded by

Nwe Nwe Soe
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views9 pages

Chapter 4 Ex AI

The document outlines pseudocode for various programs, including one that checks student GPAs and identifies those below 2.0, and another that calculates call costs based on input parameters. It includes loops for continuous input until a sentinel value is reached, and conditions to display specific outputs based on the input data. Additionally, it describes the structure of flowcharts corresponding to the pseudocode logic.

Uploaded by

Nwe Nwe Soe
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Chapter (4)

3.(a)

START

DECLARE num idNumber

DECLARE string firstName, lastName, major

DECLARE num gpa

// Accept input

INPUT idNumber, firstName, lastName, major, gpa

// Check GPA

IF gpa < 2.0 THEN

OUTPUT "Student with low GPA: "

OUTPUT idNumber, firstName, lastName, major, gpa

ELSE

OUTPUT "Student is in good outstanding."

ENDIF

STOP

3. (b)

START

DECLARE STRING studentID, firstName, lastName, major

DECLARE REAL gpa

DECLARE LIST OF RECORDS LowGPAStudents

OUTPUT "Enter student ID (or ZZZ to stop):"


INPUT studentID

WHILE studentID IS NOT "ZZZ"

OUTPUT "Enter first name:"

INPUT firstName

OUTPUT "Enter last name:"

INPUT lastName

OUTPUT "Enter major:"

INPUT major

OUTPUT "Enter GPA:"

INPUT gpa

IF gpa < 2.0 THEN

// Create a record/object for the student and add to the list

CREATE StudentRecord WITH ID=studentID, FirstName=firstName, LastName=lastName,


Major=major, GPA=gpa

ADD StudentRecord TO LowGPAStudents

END IF

OUTPUT "Enter next student ID (or ZZZ to stop):"

INPUT studentID

END WHILE

// Display results for students below 2.0 GPA

OUTPUT "--- Students on Academic Probation (GPA < 2.0) ---"


IF LowGPAStudents IS EMPTY THEN

OUTPUT "No students found with GPA below 2.0"

ELSE

FOR EACH StudentRecord IN LowGPAStudents

OUTPUT "ID: " + [Link] + ", Name: " + [Link] + " " +
[Link] + ", GPA: " + [Link]

END FOR

END IF

OUTPUT "--- End of Program ---"

STOP

3. c.

START

// Initialize

Set sentinelValue = "EXIT"

PRINT "Enter Student Name (or 'EXIT' to quit):"

READ studentName

WHILE studentName != sentinelValue

PRINT "Enter Major:"

READ major

PRINT "Enter GPA:"

READ gpa
// Check conditions: English major AND GPA >= 3.5

IF major == "English" AND gpa >= 3.5 THEN

PRINT "Eligible Student: " + studentName

ENDIF

// Get next input

PRINT "Enter Student Name (or 'EXIT' to quit):"

READ studentName

ENDWHILE

PRINT "Program Ended"

END

4.(a) START

// Variable Declarations

DECLARE String custAreaCode, custPhoneNum

DECLARE String callAreaCode, callPhoneNum

DECLARE Integer callTimeMinutes

DECLARE Float price

// Input Data

DISPLAY "Enter Customer Area Code (3 digits):"

INPUT custAreaCode

DISPLAY "Enter Customer Phone Number (7 digits):"

INPUT custPhoneNum
DISPLAY "Enter Called Area Code (3 digits):"

INPUT callAreaCode

DISPLAY "Enter Called Number (7 digits):"

INPUT callPhoneNum

DISPLAY "Enter Call Time in Minutes (4 digits):"

INPUT callTimeMinutes

// Calculate Price (Example: $0.10 per minute)

price = callTimeMinutes * 0.10

// Display Results

DISPLAY "--- Call Report ---"

DISPLAY "Calling Number: (" + custAreaCode + ") " + custPhoneNum

DISPLAY "Called Number: (" + callAreaCode + ") " + callPhoneNum

DISPLAY "Call Duration: " + callTimeMinutes + " minutes"

DISPLAY "Price of Call: $" + price

END

(b) START

// Variable Declaration

STRING custAreaCode, custPhone

STRING callAreaCode, callPhone

INTEGER callMinutes

REAL price

// Input
DISPLAY "Enter customer area code (3 digits):"

INPUT custAreaCode

DISPLAY "Enter customer phone number (7 digits):"

INPUT custPhone

DISPLAY "Enter called area code (3 digits):"

INPUT callAreaCode

DISPLAY "Enter called number (7 digits):"

INPUT callPhone

DISPLAY "Enter call time in minutes:"

INPUT callMinutes

// Processing: Calculate Price (Assume $0.13 per minute)

SET price = callMinutes * 0.13

// Output Results

DISPLAY "Calling Number: (" + custAreaCode + ") " + custPhone

DISPLAY "Called Number: (" + callAreaCode + ") " + callPhone

DISPLAY "Call Time (minutes): " + callMinutes

DISPLAY "Price of Call: $" + price

END

(c) START

DECLARE callingAreaCode AS STRING

DECLARE calledAreaCode AS STRING

DECLARE duration AS INTEGER

DECLARE SENTINEL = "999"


OUTPUT "Enter calling area code (or " + SENTINEL + " to quit):"

INPUT callingAreaCode

WHILE callingAreaCode <> SENTINEL

OUTPUT "Enter called area code:"

INPUT calledAreaCode

OUTPUT "Enter call duration in minutes:"

INPUT duration

IF callingAreaCode = "212" AND calledAreaCode = "704" AND duration > 20 THEN

OUTPUT "Match Found: " + callingAreaCode + " to " + calledAreaCode + " (" + duration + "
mins)"

ENDIF

OUTPUT "Enter next calling area code (or " + SENTINEL + " to quit):"

INPUT callingAreaCode

ENDWHILE

END

Flowchart Description

1. Start

2. Input callingAreaCode

3. Decision: callingAreaCode = "999"?

 Yes: End

 No: Input calledAreaCode, Input duration

4. Decision: callingAreaCode == "212" AND calledAreaCode == "704" AND duration > 20?
 Yes: Output call details

 No: Continue

5. Loop: Return to Step 2.

 PL & D, Ch-4,6thedition | PDF | Computing - Scribd

b. A program that continuously accepts data about phone. calls until a sentinel value is entered,
and displays all the. details on...

Scribd

 [Solved] Develop a program flowchart AND pseudocode to establish the logic for a
program where users can input 20 numbers and...

Oct 7, 2024 — The sentinel value (-999) is entered.

CliffsNotes

 The Summerville telephone company charges 10 cents per ...

Feb 15, 2024 — The pseudocode shared starts with the declaration of necessary variables for
both input and calculations. It then takes user input...

Brainly

(d ) START

DECLARE callingAreaCode AS STRING


DECLARE calledAreaCode AS STRING

DECLARE duration AS INTEGER

DECLARE SENTINEL = "999"

OUTPUT "Enter calling area code (or " + SENTINEL + " to quit):"

INPUT callingAreaCode

WHILE callingAreaCode <> SENTINEL

OUTPUT "Enter called area code:"

INPUT calledAreaCode

OUTPUT "Enter call duration in minutes:"

INPUT duration

IF callingAreaCode = "212" AND calledAreaCode = "704" AND duration > 20 THEN

OUTPUT "Match Found: " + callingAreaCode + " to " + calledAreaCode + " (" + duration + "
mins)"

ENDIF

OUTPUT "Enter next calling area code (or " + SENTINEL + " to quit):"

INPUT callingAreaCode

ENDWHILE

END

You might also like