Programming Problems

Programming Problems

a)      Input names of students from the user, terminated by ”ZZZ”,0,0,0, and create a data file grades with records of the following form:

Student (String), test1 (Integer), test2 (Integer), test3 (Integer)

 

Analysis

Input:

  1. Student                         (string)
  2. Test1                            (Integer 1-100)
  3. Test2                            (Integer 1-100)
  4. Test3                            (Integer 0-100)

 

Process:

  1. Get user input
  2. Create GRADES
  3. Calculate Grade_Total
  4. Create Records

 

Output:

  1. Student                         (string)
  2. Test1, Test2, Test3        (Integer 1-100)
  3. Grade_Total                   (Integer 1-300)

 

Input

Processes

Output

Name:   Student

Type:    String

Range:

1.InputData

 

 

Name:   Student

Type:    String

Range:

Name:   Test1

Type:    Integer

Range:  1-100

 

Name:  Test2

Type:    Integer

Range: 1 -100

 

Name:   Test3

Type:    Integer

Range:  1 -100

 

2.CalculateTotal

 

 

Name:   Grade_Total

Type:    Integer

Range:  1-300

 

 

 

Name:   Student

Type:    String

Range:

 

Name: Test1, Test2, Test3

Type:    Integer

Range:1-100

 

Name:   Grade_Total

Type:    Integer

Range: 1-300

3. DisplayResult

 

 

Name:   Student (Display)

Type:    String

Range:

 

Name:   Test1, Test2, Test3 (Display)

Type:    Integer

Range:  1-100

 

Name:   Grade_Total (Display)

Type:    Integer

Range:  1-300

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

MainModule

            Open GRADES

Declare Student as string

Declare Test1 as integer

Declare Test2 as integer

Declare Test3 as integer

Declare Grade_Total as integer

Close GRADES

 

Call InputData

Call CalculateGradeTotal

Call DisplayResults

End MainModule

 

InputData

Display “Enter Student’s name, ZZZ to quit”

Input Student

While Student < > “ZZZ”

Write Student  to GRADES

Input Test1

Write“Test1” to GRADES

Input Test2

Write “Test2” to GRADES

Input Test3

Write “Test3” to GRADES

Write newline to GRADES

End While

End InputData

 

CalculateTotal

Read Test1 from GRADES

Read Test2 from GRADES

Read Test3 from GRADES

Declare Grade_Total as Integer

Total Score = Test Score1 + Test Score2 + Test Score3

Write “Grade_Total” to GRADES

End CalculateTotal

 

 

 

b)      Display the contents of the file grades created in Part a. Each student’s record should appear on a separate line and include the total score (the sum of the three tests) for that student. For example, a line of output might be as follows:

R. Abrams 76 84 82 242

Input

Processes

Output

Name:   Student

Type:    String

Range:

 

Name: Test1, Test2, Test3

Type:    Integer

Range:1-100

 

Name:   Grade_Total

Type:    Integer

Range: 1-300

3. DisplayResult

 

 

Name:   Student (Display)

Type:    String

Range:

 

Name:   Test1, Test2, Test3 (Display)

Type:    Integer

Range:  1-100

 

Name:   Grade_Total (Display)

Type:    Integer

Range:  1-300

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

DisplayResults

Read Student from GRADES

Read Test1 from GRADES

Read Test2 from GRADES

Read Test3 from GRADES

Read Grade_Total from GRADES

Display Student “test scores” Test1, Test2, Test3 “=” Grade_Total

Write newline to Grades

End DisplayResults

 

Leave a Reply