1. include include LAST RUN on 328/2021, 349 40 PM include int main(){ int temp, opt; int a[10]; FILE fp2, fp3, fp4; // open file FILE myFile = fopen("grades.txt", "r"); // if opening file fails, print eror message and exit 1 if (myFile==NULL){ perror ("Error: Failed to open file."); exit(1); 3 Check 1 failed 4. Output: 5 6 7 [1] Passing [2] Failing 9 [3] Invalid 10 11. Option: 12 Invalid Option 13 Expected: 14 Enter File Name: //read values from file until EOF is returned by fscanf for (int i=0;i=70){ 25 Check 2 failed 26 Output: 27 28 [1] Passing 29 . 30- [2] Failing 31 putw(a[1], fp2); [3] Invalid 32 Option: else if(a[i]>=0||a<7®){ putw(a[i],fp3); 33 - 34 Invalid Option 35 Expected: else if(a[i]<0||a>100){ putw(a[i],fp4); 36 . Enter File Name: 37 All grades are evaluated and stored in their respective files. 38 39 DISPLAY FILE MENU fclose(fp2); fclose(fp3); fclose(fp4); printf("\n[1] Passing\n[2] Failing\n[3] Invalid\n0ption: "); 40 [1] Passing 41 [2] Failing 42 [3] Invalid 43 44 scanf("%d",&opt): Option: Failing Grades: 5e, e, 69, 1, e (1:18) 35 Check 3 failed else if(a[i]<0[|a>100){ putw(a[i], fp4); 36 - Output: 37 38 39 [1] Passing fclose(fp2); fclose (fp3); fclose (fp4); printf("\n[1] Passing\n[2] Failing\n[3] Invalid\n0ption: "); scanf("%d", &opt); int x; if(opt==1){ 40 [2] Failing 41 [3] Invalid 42 43 Option: 44 Invalid Option 45 Expected: 46. Enter File Name: printf("\nPassing Grades: "); fp2=fopen("passed. txt","r"); while(x!=-1){ 47 48 All grades are evaluated and stored in their respective files. 49. DISPLAY FILE MENU x=fgetc(fp2); if(x<=®) printf(""); else printf("%d ",x); 50 [1] Passing 51 52 [2] Failing 53 [3] Invalid 54 Option: 55 Invalid Grades: 101, -1, 56 printf("\n"); 57 Check 4 failed else if(opt==2){ 58. Output: printf("\nFailing Grades: "); fp3=fopen("failed.txt","r"); 59 60 [1] Passing 61 - while(x!=-1){ 62 [2] Failing x=fgetc(fp3); if(x<=®) printf(""); else{ printf("%d ",x); 63 [3] Invalid 64 Option: 65 . Invalid Option 66 67 Expected: 68 Enter File Name: 69 printf("\n"); All grades are evaluated and stored in their respective files. 70 71. else if(opt==3){ DISPLAY FILE MENU 72 printf("\nInvalid Grades: "); [1] Passing 73 fp4=fopen("invalid.txt","r"); while(x!=-1){ [2] Failing 74 . [3] Invalid 75 x=fgetc(fp3); printf("%d ",x); 76 Option: 77 Invalid Option 78 printf("\n"); Check 5 failed es (1:18) Output: DISPLAY FILE MENU printf("\n[1] Passing\n[2] Failing\n[3] Invalid\n0ption: "); scanf ("id", &opt); int x; if(opt==1){ 43 [1] Passing 45 [2] Failing [3] Invalid printf("\nPassing Grades: "); fp2=fopen("passed. txt","r"); while(x:=-1){ 47 Option: 48 49. Invalid Grades: 101, -1, x=fgetc(fp2); if(x<=®) printf(""); else 50 Check 4 failed 51 Output: 52 53 54 printf("id ",x); [1] Passing 55 [2] Failing 56 printf("\n"); [3] Invalid 57 else if(opt==2){ Option: 58- printf("\nFailing Grades: "): fp3=fopen("failed.txt","r"); while(x:=-1){ 59 Invalid Option 60 Expected: 61- Enter File Name: x=fgetc(fp3); if(x<=0) printf(""); else{ printf("id ",x); 62 63 All grades are evaluated and stored in their respective files. 64 DISPLAY FILE MENU 65. [1] Passing 66 [2] Failing 67 68 [3] Invalid 69 printf("\n"); Option: 70 Invalid Option else if(opt==3){ 71- printf("\nInvalid Grades: "); fp4=fopen ("invalid.txt","r"); while(x:=-1){ 72 Check 5 failed 73 Output: 74 - x=fgetc(fp3) ; printf("%d ",x); 75 [1] Passing 76 77 [2] Failing 78 printf("\n"); [3] Invalid 79 Option: else{ printf("\nInvalid Option\n"); 80 - 81 Invalid Option 82 Еxpected: 83 return e; Enter File Name: 84 The file can't be open. File does not exists. AK Show diff * (1:18)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write a C program that will get 10 grades of the student from a file named grades.txt. The program will check each grade if its passing, failing or invalid. Passing grade is 70-100. Failing grade is 0-69. Other value will be considered invalid. Store all the passing grade to an output file named passed.txt. Store all the failing grades to an output file named failed.txt. And store all the invalid grades to another output file named invalid.txt. The program must comply with the given sample output below:

NOTE:
Filename to read: grades.txt
Filename to write: passed.txt, failed.txt, invalid.txt
NOTE:
Your source code must display any of the given sample output below.
It means your source code should be flexible enough to meet any of the given sample output.
Your source code output must be identical to any of the given sample output.
It means you have to strictly follow what are the displayed text, labels, casing of characters in the sample output.
Strictly follow the naming of file.
Sample OUTPUT1:
Enter File Name: grades.txt
All grades are evaluated and stored in their respective files.
DISPLAY FILE MENU
[1] Passing
[2] Failing
[3] Invalid
Option: 1
Passing Grades: 100, 90, 70, 99,
Sample OUTPUT2:
Enter File Name: grades.txt
All grades are evaluated and stored in their respective files.
DISPLAY FILE MENU
[1] Passing
[2] Failing
[3] Invalid
Option: 2
Failing Grades: 50, 0, 69, 1,
Sample OUTPUT3:
Enter File Name: grades.txt
All grades are evaluated and stored in their respective files.
DISPLAY FILE MENU
[1] Passing
[2] Failing
[3] Invalid
Option: 3
Invalid Grades: 101, -1,
Sample OUTPUT4:
Enter File Name: grades.txt
All grades are evaluated and stored in their respective files.
DISPLAY FILE MENU
[1] Passing
[2] Failing
[3] Invalid
Option: 4
Invalid Option
Sample OUTPUT5:
Enter File Name: grade.txt
The file can’t be open. File does not exists.

PLEASE HELP! 

How to fix my code? please look at the expected results I'll rate! 

My code

#include <stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
int temp,opt;
int a[10];
FILE *fp2,*fp3,*fp4;
// open file
FILE *myFile = fopen("grades.txt", "r");
// if opening file fails, print error message and exit 1
if (myFile==NULL){
perror("Error: Failed to open file.");
exit(1);
}
//read values from file until EOF is returned by fscanf
for(int i=0;i<10;++i){
// assign the read value to variable (tek), and enter it in array (radica)
if(fscanf(myFile,"%d",&temp) == 1) {
a[i]=temp;
}
else{
break;
}
}
fclose(myFile);
fp2=fopen("passed.txt","w");
fp3=fopen("failed.txt","w");
fp4=fopen("invalid.txt","w");
for (int i=0;i<10;++i){
if(a[i]>=70){
putw(a[i],fp2);
}
else if(a[i]>=0||a<70){
putw(a[i],fp3);
}
else if(a[i]<0||a>100){
putw(a[i],fp4);
}
}
fclose(fp2);
fclose(fp3);
fclose(fp4);
printf("\n[1] Passing\n[2] Failing\n[3] Invalid\nOption: ");
scanf("%d",&opt);
int x;
if(opt==1){
printf("\nPassing Grades: ");
fp2=fopen("passed.txt","r");
while(x!=-1){
x=fgetc(fp2);
if(x<=0)
printf("");
else
printf("%d ",x);
}
printf("\n");
}
else if(opt==2){
printf("\nFailing Grades: ");
fp3=fopen("failed.txt","r");
while(x!=-1){
x=fgetc(fp3);
if(x<=0)
printf("");
else{
printf("%d ",x);
}
}
printf("\n");
}
else if(opt==3){
printf("\nInvalid Grades: ");
fp4=fopen("invalid.txt","r");
while(x!=-1){
x=fgetc(fp3);
printf("%d ",x);
}
printf("\n");
}
else{
printf("\nInvalid Option\n");
}
return 0;
}

#include <stdio.h>
#include<stdlib.h>
LAST RUN on 3/28/2021, 3:49:40 PM
#include<string.h>
int main(){
3
Check 1 failed
4 .
Output:
int temp, opt;
int a[10];
FILE *fp2, * fp3,*fp4;
// open file
FILE *myFile = fopen ("grades.txt", "r");
// if opening file fails, print error message and exit 1
if (myFile==NULL){
perror ("Error: Failed to open file.");
exit(1);
}
//read values from file until EOF is returned by fscanf
6
7
[1] Passing
8
[2] Failing
9
[3] Invalid
10
11 -
Option:
12
Invalid Option
13
Expected:
14
Enter File Name:
15
All grades are evaluated and stored in their respective files.
for (int i=0;i<10;++i){
// assign the read value to variable (tek), and enter it in array (radica)
if(fscanf(myFile,"%d",&temp) == 1) {
a[i]=temp;
}
else{
break;
}
}
fclose (myFile);
fp2=fopen ("passed.txt","w");
fp3=fopen ("failed.txt","w");
16 -
17
DISPLAY FILE MENU
18 -
[1] Passing
[2] Failing
19
20
21 -
[3] Invalid
22
Option:
23
Passing Grades: 100, 90, 70, 99,
24
25
Check 2 failed
26
Output:
27
fp4=fopen ("invalid.txt", "w");
for (int i=0;i<10;++i){
if(a[i]>=70){
28
29 -
[1] Passing
30 -
[2] Failing
31
putw(a[i],fp2);
[3] Invalid
32
}
Option:
else if(a[i]>=0||a<7®){
33 -
putw(a[i],fp3);
Invalid Option
34
35
}
Expected:
36 -
else if(a[i] <0|[a>100){
Enter File Name:
37
putw(a[i], fp4);
All grades are evaluated and stored in their respective files.
38
}
DISPLAY FILE MENU
}
fclose (fp2);
fclose (fp3);
fclose (fp4);
printf("\n[1] Passing\n[2] Failing\n[3] Invalid\n0ption: ");
scanf ("%d", &opt);
39
40
[1] Passing
41
[2] Failing
42
[3] Invalid
43
44
Option:
YK
Failing Grades: 50, 0, 69, 1,
0% (1:18)
C
}
else if(a[i]<0||a>100){
35
Check 3 failed
36 -
Output:
37
putw (a[i], fp4);
38
}
[1] Passing
}
fclose (fp2);
fclose (fp3);
fclose (fp4);
printf("\n[1] Passing\n[2] Failing\n[3] Invalid\n0ption: ");
scanf("%d", &opt);
39
40
[2] Failing
41
[3] Invalid
42
43
Option:
44
Invalid Option
45
int x;
Expected:
46 -
if(opt==1){
Enter File Name:
printf("\nPassing Grades: ");
fp2=fopen ("passed.txt",",");
47
48
All grades are evaluated and stored in their respective files.
49 -
while(x!=-1) {
DISPLAY FILE MENU
x=fgetc(fp2);
if(x<=0)
printf("");
50
[1] Passing
51
[2] Failing
52
53
else
[3] Invalid
54
printf("%d ",x);
Option:
55
}
Invalid Grades: 101, -1,
56
printf("\n");
Check 4 failed
}
else if(opt==2){
57
58 -
Output:
printf("\nFailing Grades: ");
fp3=fopen ("failed.txt","r");
while(x!=-1){
59
60
[1] Passing
61 -
[2] Failing
x=fgetc(fp3);
if(x<=0)
62
63
[3] Invalid
printf("");
else{
printf("%d ",x);
}
64
Option:
65 -
Invalid Option
66
67
Expected:
68
}
Enter File Name:
69
printf("\n");
All grades are evaluated and stored in their respective files.
70
}
else if(opt==3){
DISPLAY FILE MENU
71-
printf("\nInvalid Grades: ");
fp4=fopen ("invalid.txt","r");
72
[1] Passing
73
[2] Failing
74 -
while(x!=-1) {
[3] Invalid
75
x=fgetc(fp3);
Option:
printf("%d ",x);
}
76
77
Invalid Option
78
printf("\n");
Check 5 failed
0% (1:18)
Output:
DISPLAY FILE MENU
printf("\n[1] Passing\n[2] Failing\n[3] Invalid\n0ption: ");
scanf("%d", &opt);
int x;
43
44
[1] Passing
45
[2] Failing
46 -
if(opt==1){
[3] Invalid
47
printf("\nPassing Grades: ");
fp2=fopen ("passed.txt","r");
Option:
48
49 -
while(x!=-1){
Invalid Grades: 101, -1,
x=fgetc(fp2);
if(x<=0)
printf("");
50
Check 4 failed
51
Output:
52
53
else
54
printf("%d ",x);
[1] Passing
55
}
[2] Failing
56
printf("\n");
[3] Invalid
}
else if(opt==2){
57
58 -
Option:
printf("\nFailing Grades: ");
fp3=fopen("failed.txt","r");
while(x!=-1){
59
Invalid Option
60
Expected:
61 -
Enter File Name:
x=fgetc(fp3);
if(x<=0)
printf("");
else{
printf("%d ",x);
}
62
63
All grades are evaluated and stored in their respective files.
64
DISPLAY FILE MENU
65 -
[1] Passing
66
[2] Failing
67
68
}
[3] Invalid
69
printf("\n");
Option:
}
else if(opt==3){
70
Invalid Option
71 -
Check 5 failed
printf("\nInvalid Grades: ");
fp4=fopen("invalid.txt","r");
while(x!=-1){
72
73
Output:
74 -
75
x=fgetc(fp3);
[1] Passing
printf("%d ",x);
}
76
77
[2] Failing
78
printf("\n");
[3] Invalid
}
else{
printf("\nInvalid Option\n");
}
79
Option:
80 -
Invalid Option
81
82
Expected:
83
return 0;
Enter File Name:
84
}
The file can't be open. File does not exists.
Show diff
0% (1:18)
Transcribed Image Text:#include <stdio.h> #include<stdlib.h> LAST RUN on 3/28/2021, 3:49:40 PM #include<string.h> int main(){ 3 Check 1 failed 4 . Output: int temp, opt; int a[10]; FILE *fp2, * fp3,*fp4; // open file FILE *myFile = fopen ("grades.txt", "r"); // if opening file fails, print error message and exit 1 if (myFile==NULL){ perror ("Error: Failed to open file."); exit(1); } //read values from file until EOF is returned by fscanf 6 7 [1] Passing 8 [2] Failing 9 [3] Invalid 10 11 - Option: 12 Invalid Option 13 Expected: 14 Enter File Name: 15 All grades are evaluated and stored in their respective files. for (int i=0;i<10;++i){ // assign the read value to variable (tek), and enter it in array (radica) if(fscanf(myFile,"%d",&temp) == 1) { a[i]=temp; } else{ break; } } fclose (myFile); fp2=fopen ("passed.txt","w"); fp3=fopen ("failed.txt","w"); 16 - 17 DISPLAY FILE MENU 18 - [1] Passing [2] Failing 19 20 21 - [3] Invalid 22 Option: 23 Passing Grades: 100, 90, 70, 99, 24 25 Check 2 failed 26 Output: 27 fp4=fopen ("invalid.txt", "w"); for (int i=0;i<10;++i){ if(a[i]>=70){ 28 29 - [1] Passing 30 - [2] Failing 31 putw(a[i],fp2); [3] Invalid 32 } Option: else if(a[i]>=0||a<7®){ 33 - putw(a[i],fp3); Invalid Option 34 35 } Expected: 36 - else if(a[i] <0|[a>100){ Enter File Name: 37 putw(a[i], fp4); All grades are evaluated and stored in their respective files. 38 } DISPLAY FILE MENU } fclose (fp2); fclose (fp3); fclose (fp4); printf("\n[1] Passing\n[2] Failing\n[3] Invalid\n0ption: "); scanf ("%d", &opt); 39 40 [1] Passing 41 [2] Failing 42 [3] Invalid 43 44 Option: YK Failing Grades: 50, 0, 69, 1, 0% (1:18) C } else if(a[i]<0||a>100){ 35 Check 3 failed 36 - Output: 37 putw (a[i], fp4); 38 } [1] Passing } fclose (fp2); fclose (fp3); fclose (fp4); printf("\n[1] Passing\n[2] Failing\n[3] Invalid\n0ption: "); scanf("%d", &opt); 39 40 [2] Failing 41 [3] Invalid 42 43 Option: 44 Invalid Option 45 int x; Expected: 46 - if(opt==1){ Enter File Name: printf("\nPassing Grades: "); fp2=fopen ("passed.txt",","); 47 48 All grades are evaluated and stored in their respective files. 49 - while(x!=-1) { DISPLAY FILE MENU x=fgetc(fp2); if(x<=0) printf(""); 50 [1] Passing 51 [2] Failing 52 53 else [3] Invalid 54 printf("%d ",x); Option: 55 } Invalid Grades: 101, -1, 56 printf("\n"); Check 4 failed } else if(opt==2){ 57 58 - Output: printf("\nFailing Grades: "); fp3=fopen ("failed.txt","r"); while(x!=-1){ 59 60 [1] Passing 61 - [2] Failing x=fgetc(fp3); if(x<=0) 62 63 [3] Invalid printf(""); else{ printf("%d ",x); } 64 Option: 65 - Invalid Option 66 67 Expected: 68 } Enter File Name: 69 printf("\n"); All grades are evaluated and stored in their respective files. 70 } else if(opt==3){ DISPLAY FILE MENU 71- printf("\nInvalid Grades: "); fp4=fopen ("invalid.txt","r"); 72 [1] Passing 73 [2] Failing 74 - while(x!=-1) { [3] Invalid 75 x=fgetc(fp3); Option: printf("%d ",x); } 76 77 Invalid Option 78 printf("\n"); Check 5 failed 0% (1:18) Output: DISPLAY FILE MENU printf("\n[1] Passing\n[2] Failing\n[3] Invalid\n0ption: "); scanf("%d", &opt); int x; 43 44 [1] Passing 45 [2] Failing 46 - if(opt==1){ [3] Invalid 47 printf("\nPassing Grades: "); fp2=fopen ("passed.txt","r"); Option: 48 49 - while(x!=-1){ Invalid Grades: 101, -1, x=fgetc(fp2); if(x<=0) printf(""); 50 Check 4 failed 51 Output: 52 53 else 54 printf("%d ",x); [1] Passing 55 } [2] Failing 56 printf("\n"); [3] Invalid } else if(opt==2){ 57 58 - Option: printf("\nFailing Grades: "); fp3=fopen("failed.txt","r"); while(x!=-1){ 59 Invalid Option 60 Expected: 61 - Enter File Name: x=fgetc(fp3); if(x<=0) printf(""); else{ printf("%d ",x); } 62 63 All grades are evaluated and stored in their respective files. 64 DISPLAY FILE MENU 65 - [1] Passing 66 [2] Failing 67 68 } [3] Invalid 69 printf("\n"); Option: } else if(opt==3){ 70 Invalid Option 71 - Check 5 failed printf("\nInvalid Grades: "); fp4=fopen("invalid.txt","r"); while(x!=-1){ 72 73 Output: 74 - 75 x=fgetc(fp3); [1] Passing printf("%d ",x); } 76 77 [2] Failing 78 printf("\n"); [3] Invalid } else{ printf("\nInvalid Option\n"); } 79 Option: 80 - Invalid Option 81 82 Expected: 83 return 0; Enter File Name: 84 } The file can't be open. File does not exists. Show diff 0% (1:18)
Expert Solution
steps

Step by step

Solved in 4 steps with 8 images

Blurred answer
Knowledge Booster
Constants and Variables
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education