24 write a program using parallel arrays to represent the following student database

2
#24 Write a program using parallel arrays to represent the following student database. char id[10][5]  stores the ID nos. of 10 s tudents. char stud[10][15]  stores the names of 10 students each of which has a maximum length 15. int year[10]  stores the year level of all 10 students. char course[10]  stores the courses of all 10 s tudents. float score[10][2]  stores the scores of 2 quizzes of all 10 students. float grade[10]  stores the grades of all 10 s tudents based on the 2 quizzes. The program will present to the user the following choices/tasks: 1. Create a new student record.  Input all necessary data fields for one student record, namely id[i]   ID no. of new student stud[i]  name of new student year[i]  year level of new student course[i]  course of new student 2. Input Scores of 2 Quizzes for one existing student.  Input the ID no. of the existing student,   Find array index i whose ID matches the input ID.   Input the score of Quiz 1 and assign to score[i][1],  Input the score of Quiz 2 and assign to score[i][2]. 3. Compute the grade of one student.  Input the ID no. of the existing student,   Find array index i whose ID matches the input ID.   If array index i has values for the 2 Quizzes score[i][1] and score[i][2], then proceed to compute the grade using the formula: grade[i] = 0.4 * (5  4 * score[i][1] / total) + 0.6 * (5  4 * score[i][2] / total) where total is the total points of each quiz and declare it as a global constant. 4. Compute grades of all students. 5. View all student records of year level y - Display all student records (all data fields) 6. View all student records of course co - Display all student records (all data fields) 7. View the student record (all data fields) with the highest grade. 8. View the student record (all data fields) with the lowest grade. The program allows the user to repeat (choose another task after making one). One student record: id=”00221” name=”juan cruz” year=2 course=”cpe” score1=70, score2=83 grade=??? id[0]=”00221” 0-id[0][0] 0-id[0][1] 2- id[0][2] stud[0]=”juan cruz” j -stud[0][0] year[0]=2 course[0]=”cpe” score[0][0]=70, score[0][1]=83 grade[0] scanf(“%d”,&co); for (i=0;i < totalStud;i++) { if (course[i]==co) { display id[i],stud[i],year[i],course[i],score[ i][0],score[i][1],grade[i] } } id: stud: year course score grade [0] [1] [0] =”00221” [0]=”juan” [0]=2 [0]=”cpe” [0]=80 78 [0] [1] =”00222” [1]=”pedro” [1]=3 [1]=”ee” [1]=74 79 [1] [2] =”00223” [2]=”maria” [2]=2 [2]=”cpe” [2] [2] .. scanf(“%s”,idx); for (i=0;i<totalStud;i++) { if (id[i]==idx ) { printf(“Enter score of Quiz#1 :”); scanf(“%f”,&score[i][0]); score[i][1] = } }  #27 Redo #24. This time declare a structure type student with fields given below. This program can accept a maximum of 10 students. Use a structure variable and a structure pointer to refer to a structure's data fields. Retrieve existing student records from a text file everytime the program starts to run and save to the same text file all student records (if updated) before the program ends. s truct student { char id[5]; char name[15]; int year; char course; float score[2]; float grade; }; mao ng duha kbuok kuya alex . unya wla jud koy nhemu maski isa ana wla ko ksbot na.

Upload: genesis-react

Post on 04-Jun-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

 

#24 Write a program using parallel arrays to represent the following student database.

char id[10][5] – stores the ID nos. of 10 students.

char stud[10][15] – stores the names of 10 students each of which has a maximum length 15.

int year[10] – stores the year level of all 10 students.

char course[10] – stores the courses of all 10 students.

float score[10][2] – stores the scores of 2 quizzes of all 10 students.

float grade[10] – stores the grades of all 10 students based on the 2 quizzes.

The program will present to the user the following choices/tasks:

1. Create a new student record. – Input all necessary data fields for one student record, namely id[i] – ID no. of

new student stud[i] – name of new student year[i] – year level of new student course[i] – course of new student

2. Input Scores of 2 Quizzes for one existing student. – Input the ID no. of the existing student, – Find array

index i whose ID matches the input ID. – Input the score of Quiz 1 and assign to score[i][1], – Input the score of

Quiz 2 and assign to score[i][2].

3. Compute the grade of one student. – Input the ID no. of the existing student, – Find array index i whose ID

matches the input ID. – If array index i has values for the 2 Quizzes score[i][1] and score[i][2], then proceed to

compute the grade using the formula: grade[i] = 0.4 * (5 – 4 * score[i][1] / total) + 0.6 * (5 – 4 * score[i][2] / total)

where total is the total points of each quiz and declare it as a global constant. 4. Compute grades of all

students.

5. View all student records of year level y - Display all student records (all data fields)

6. View all student records of course co - Display all student records (all data fields)

7. View the student record (all data fields) with the highest grade.

8. View the student record (all data fields) with the lowest grade. The program allows the user to repeat

(choose another task after making one).

One student record: id=”00221” name=”juan cruz” year=2 course=”cpe” score1=70, score2=83 grade=???

id[0]=”00221” 0-id[0][0] 0-id[0][1] 2-id[0][2] stud[0]=”juan cruz” j-stud[0][0] year[0]=2 course[0]=”cpe”

score[0][0]=70, score[0][1]=83 grade[0] scanf(“%d”,&co); for (i=0;i < totalStud;i++) { if (course[i]==co) { display

id[i],stud[i],year[i],course[i],score[i][0],score[i][1],grade[i] } } id: stud: year course score grade [0] [1] [0] =”00221”

[0]=”juan” [0]=2 [0]=”cpe” [0]=80 78 [0] [1] =”00222” [1]=”pedro” [1]=3 [1]=”ee” [1]=74 79 [1] [2] =”00223”

[2]=”maria” [2]=2 [2]=”cpe” [2] [2] .. scanf(“%s”,idx); for (i=0;i<totalStud;i++) { if (id[i]==idx ) { printf(“Enter score

of Quiz#1 :”); scanf(“%f”,&score[i][0]); score[i][1] = } } 

#27 Redo #24. This time declare a structure type student with fields given below. This program can accept a

maximum of 10 students. Use a structure variable and a structure pointer to refer to a structure's data fields.

Retrieve existing student records from a text file everytime the program starts to run and save to the same text

file all student records (if updated) before the program ends. struct student { char id[5]; char name[15]; int year;

char course; float score[2]; float grade; };

mao ng duha kbuok kuya alex . unya wla jud koy nhemu maski isa ana wla ko ksbot na.