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?  My code! #include #include //MAIN METHOD int main() { //Declare file pointers FILE *fin,*fpass,*ffail,*finvalid; //Declare variablef to store filename char str[30]; //Declare variables: option and ch int option,ch; //Read file name printf("Enter File Name: "); scanf("%s",str); //Open input file in read mode. fin = fopen(str,"r"); //Open Output file in write mode. fpass= fopen("passed.txt","w"); ffail = fopen("failed.txt","w"); finvalid = fopen("invalid.txt","w"); //Display error message if input file is not opened. if(fin == NULL) { printf("Error in opening %s!",str); exit(1); } //Read first integer from input file fscanf(fin,"%d",&ch); //Use While loop, to read all integers from file and place them in respective output files. while (!feof(fin)) { //if integer is with in 70-100 then put them in passed.txt file. if(ch<=100 && ch>=70) { fprintf(fpass,"%d\n",ch); } //If integer is with in 0-69 then put them in failed.txt file. else if(ch<70 && ch>=0) { fprintf(ffail,"%d\n",ch); } //otherwise put the integer in invalid.txt file else{ fprintf(finvalid,"%d\n",ch); } //read next integer from file fscanf(fin,"%d",&ch); } printf("\nAll grades are evaluated and stored in their respective files."); //Close all file pointers fclose(fpass); fclose(ffail); fclose(finvalid); //Display File menu printf("\nDISPLAY FILE MENU"); printf("\n[1] Passing\n[2] Failing\n[3] Invalid\nOption:\nPassing Grades: "); //Read option from user scanf("%d",&option); //Use switch, to display respective file content based on user choice switch(option) { case 1: //If case-1, Display passed.txt file information. //Open file in read mode fpass= fopen("passed.txt","r"); //Use while loop, to display all integers in passed.txt file. fscanf(fpass,"%d",&ch); while (!feof(fpass)) { printf("%d, ",ch); fscanf(fpass,"%d",&ch); } break; case 2: //If case-2, Display failed.txt file information. //Open file in read mode ffail = fopen("failed.txt","r"); //Use while loop, to display all integers in failed.txt file. fscanf(ffail,"%d",&ch); while (!feof(ffail)) { printf("%d, ",ch); fscanf(ffail,"%d",&ch); } break; case 3: //If case-3, Display invalid.txt file information. //Open file in read mode finvalid = fopen("invalid.txt","r"); //Use while loop, to display all integers in invalid.txt file. fscanf(finvalid,"%d",&ch); while (!feof(finvalid)) { printf("%d, ",ch); fscanf(finvalid,"%d",&ch); } break; default: printf("Invalid Option"); } }

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? 

My code!

#include<stdio.h>
#include<stdlib.h>

//MAIN METHOD
int main()
{
//Declare file pointers
FILE *fin,*fpass,*ffail,*finvalid;
//Declare variablef to store filename
char str[30];
//Declare variables: option and ch
int option,ch;

//Read file name
printf("Enter File Name: ");
scanf("%s",str);

//Open input file in read mode.
fin = fopen(str,"r");
//Open Output file in write mode.
fpass= fopen("passed.txt","w");
ffail = fopen("failed.txt","w");
finvalid = fopen("invalid.txt","w");

//Display error message if input file is not opened.
if(fin == NULL)
{
printf("Error in opening %s!",str);
exit(1);
}

//Read first integer from input file
fscanf(fin,"%d",&ch);
//Use While loop, to read all integers from file and place them in respective output files.
while (!feof(fin))
{
//if integer is with in 70-100 then put them in passed.txt file.
if(ch<=100 && ch>=70)
{
fprintf(fpass,"%d\n",ch);
}
//If integer is with in 0-69 then put them in failed.txt file.
else if(ch<70 && ch>=0)
{
fprintf(ffail,"%d\n",ch);
}
//otherwise put the integer in invalid.txt file
else{
fprintf(finvalid,"%d\n",ch);
}
//read next integer from file
fscanf(fin,"%d",&ch);
}

printf("\nAll grades are evaluated and stored in their respective files.");
//Close all file pointers
fclose(fpass);
fclose(ffail);
fclose(finvalid);

//Display File menu
printf("\nDISPLAY FILE MENU");
printf("\n[1] Passing\n[2] Failing\n[3] Invalid\nOption:\nPassing Grades: ");
//Read option from user
scanf("%d",&option);
//Use switch, to display respective file content based on user choice
switch(option)
{
case 1:
//If case-1, Display passed.txt file information.
//Open file in read mode
fpass= fopen("passed.txt","r");
//Use while loop, to display all integers in passed.txt file.
fscanf(fpass,"%d",&ch);
while (!feof(fpass))
{
printf("%d, ",ch);
fscanf(fpass,"%d",&ch);
}
break;
case 2:
//If case-2, Display failed.txt file information.
//Open file in read mode
ffail = fopen("failed.txt","r");
//Use while loop, to display all integers in failed.txt file.
fscanf(ffail,"%d",&ch);
while (!feof(ffail))
{
printf("%d, ",ch);
fscanf(ffail,"%d",&ch);
}
break;
case 3:
//If case-3, Display invalid.txt file information.
//Open file in read mode
finvalid = fopen("invalid.txt","r");
//Use while loop, to display all integers in invalid.txt file.
fscanf(finvalid,"%d",&ch);
while (!feof(finvalid))
{
printf("%d, ",ch);
fscanf(finvalid,"%d",&ch);
}
break;
default:
printf("Invalid Option");

}


}

#include<stdio.h>
2
#include<stdlib.h>
LAST RUN On 3/28/2021, 9:42:38 PM
3
Check 1 passed
// ΜAIN ΜΕTHOD
int main()
{
//Declare file pointers
FILE *fin,*fpass,*ffail,*finvalid;
//Declare variablef to store filename
char str[30];
//Declare variables: option and ch
int option,ch;
4
Check 2 failed
Output:
7
Enter File Name:
8
All grades are evaluated and stored in their respective files.
DISPLAY FILE MENU
10
11
[1] Passing
12
[2] Failing
13
[3] Invalid
//Read file name
printf("Enter File Name: ");
scanf("%s",str);
14
15
Option:
16
Passing Grades: 50, 0, 69, 1,
17
Expected:
//Open input file in read mode.
fin = fopen (str,"r");
//Open Output file in write mode.
fpass= fopen ("passed.txt","w");
ffail = fopen ("failed.txt","w");
finvalid = fopen ("invalid.txt","w");
18
Enter File Name:
19
20
All grades are evaluated and stored in their respective files.
21
#include<stdio.h>
[1] Passing
DISPLAY FILE MENU
22
2
#include<stdlib.h>
[2] Failing
[1] Passing
23
[3] Invalid
// ΜAIN ΜΕTHOD
int main()
{
//Declare file pointers
FILE *fin,*fpass,*ffail,*finvalid;
//Declare variablef to store filename
char str[30];
//Declare variables: option and ch
int option,ch;
24
[2] Failing
4
Option:
//Display error message if input file is not opened.
if(fin == NULL)
{
printf("Error in opening %s!",str);
exit(1);
}
25
[3] Invalid
26
Invalid Grades: 101, -1,
Option:
27 v
7
Check 4 failed
28
Failing Grades: 50, 0, 69, 1,
8
Output:
29
Check 3 failed
9
30
10
Enter File Name:
Output:
31
11
All grades are evaluated and stored in their respective files.
Enter File Name:
//Read first integer from input file
fscanf(fin,"%d",&ch);
//Use While loop, to read all integers from file and place them in res
while (!feof(fin))
32
12
DISPLAY FILE MENU
33
All grades are evaluated and stored in their respective files.
13
[1] Passing
//Read file name
printf("Enter File Name: ");
scanf ("%s",str);
34
14
DISPLAY FILE MENU
35
15
[2] Failing
[1] Passing
{
//if integer is with in 70-100 then put them in passed.txt file.
if(ch<=100 && ch>=70)
{
36 -
16
[3] Invalid
37
[2] Failing
17
Option:
//Open input file in read mode.
fin = fopen (str,"r");
//Open Output file in write mode.
fpass= fopen("passed.txt","w");
ffail = fopen ("failed.txt","w");
finvalid = fopen ("invalid.txt","w");
38
[3] Invalid
18
39 -
19
Passing Grades: Invalid option
Option:
40
fprintf(fpass,"%d\n",ch);
20
Expected:
Passing Grades: 101,
21
Enter File Name:
0% (1:17)
22
Expected:
הרeuישיeיקEXד
All grades are evaluated and stored in their respective files.
23
#include<stdio.h>
2
#include<stdlib.h>
Enter File Name:
24
DISPLAY FILE MENU
//Display error message if input file is not opened.
if(fin == NULL)
{
printf("Error in opening %s!",str);
exit(1);
}
25
All grades are evaluated and stored in their respective files.
[1] Passing
26
/ / ΜAIN ΜΕTHOD
int main()
4
DISPLAY FILE MENU
27
[2] Failing
[1] Passing
28
[3] Invalid
{
//Declare file pointers
FILE *fin,*fpass,*ffail,*finvalid;
//Declare variablef to store filename
char str[30];
//Declare variables: option and ch
int option,ch;
29
7
[2] Failing
Option:
30
8
[3] Invalid
Invalid Option
31
Option:
Check 5 failed
//Read first integer from input file
fscanf(fin,"%d",&ch);
//Use While loop, to read all integers from file and place them in res
while (!feof(fin))
{
//if integer is with in 70-100 then put them in passed.txt file.
if(ch<=100 && ch>=70)
{
32
10
11
Invalid Grades: 101, -1,
33
Output:
34
12
Check 4 failed
Enter File Name: Error in opening grade.txt!
35
13
Output:
36 v
Expected:
14
//Read file name
Enter File Name:
37
Enter File Name:
printf("Enter File Name: ");
scanf("%s",str);
15
All grades are evaluated and stored in their respective files.
38
The file can’t be open. File does not exists.
16
39 v
17
DISPLAY FILE MENU
40
fprintf(fpass,"%d\n",ch);
//Open input file in read mode.
fin = fopen(str,"r");
//Open Output file in write mode.
fpass= fopen ("passed.txt","w");
ffail = fopen ("failed.txt","w");
finvalid = fopen ("invalid.txt","w");
18
[1] Passing
Show diff
19
0% (1:17)
[2] Failing
20
21
[3] Invalid
22
Option:
23
Passing Grades: Invalid Option
24
Expected:
//Display error message if input file is not opened.
if(fin == NULL)
{
printf("Error in opening %s!",str);
exit(1);
}
25
26
Enter File Name:
27
All grades are evaluated and stored in their respective files.
28
29
DISPLAY FILE MENU
30
[1] Passing
31
[2] Failing
//Read first integer from input file
fscanf(fin,"%d" ,&ch);
//Use While loop, to read all integers from file and place them in res
while (!feof (fin))
{
//if integer is with in 70-100 then put them in passed.txt file.
if(ch<=100 && ch>=70)
{
32
[3] Invalid
33
34
Option:
35
Invalid Option
36 .
Check 5 failed
37
38
Output:
39 -
Enter File Name: Error in opening grade.txt!
40
fprintf(fpass,"%d\n",ch);
Expected:
0% (1:17)
C
Enter File Name:
Transcribed Image Text:#include<stdio.h> 2 #include<stdlib.h> LAST RUN On 3/28/2021, 9:42:38 PM 3 Check 1 passed // ΜAIN ΜΕTHOD int main() { //Declare file pointers FILE *fin,*fpass,*ffail,*finvalid; //Declare variablef to store filename char str[30]; //Declare variables: option and ch int option,ch; 4 Check 2 failed Output: 7 Enter File Name: 8 All grades are evaluated and stored in their respective files. DISPLAY FILE MENU 10 11 [1] Passing 12 [2] Failing 13 [3] Invalid //Read file name printf("Enter File Name: "); scanf("%s",str); 14 15 Option: 16 Passing Grades: 50, 0, 69, 1, 17 Expected: //Open input file in read mode. fin = fopen (str,"r"); //Open Output file in write mode. fpass= fopen ("passed.txt","w"); ffail = fopen ("failed.txt","w"); finvalid = fopen ("invalid.txt","w"); 18 Enter File Name: 19 20 All grades are evaluated and stored in their respective files. 21 #include<stdio.h> [1] Passing DISPLAY FILE MENU 22 2 #include<stdlib.h> [2] Failing [1] Passing 23 [3] Invalid // ΜAIN ΜΕTHOD int main() { //Declare file pointers FILE *fin,*fpass,*ffail,*finvalid; //Declare variablef to store filename char str[30]; //Declare variables: option and ch int option,ch; 24 [2] Failing 4 Option: //Display error message if input file is not opened. if(fin == NULL) { printf("Error in opening %s!",str); exit(1); } 25 [3] Invalid 26 Invalid Grades: 101, -1, Option: 27 v 7 Check 4 failed 28 Failing Grades: 50, 0, 69, 1, 8 Output: 29 Check 3 failed 9 30 10 Enter File Name: Output: 31 11 All grades are evaluated and stored in their respective files. Enter File Name: //Read first integer from input file fscanf(fin,"%d",&ch); //Use While loop, to read all integers from file and place them in res while (!feof(fin)) 32 12 DISPLAY FILE MENU 33 All grades are evaluated and stored in their respective files. 13 [1] Passing //Read file name printf("Enter File Name: "); scanf ("%s",str); 34 14 DISPLAY FILE MENU 35 15 [2] Failing [1] Passing { //if integer is with in 70-100 then put them in passed.txt file. if(ch<=100 && ch>=70) { 36 - 16 [3] Invalid 37 [2] Failing 17 Option: //Open input file in read mode. fin = fopen (str,"r"); //Open Output file in write mode. fpass= fopen("passed.txt","w"); ffail = fopen ("failed.txt","w"); finvalid = fopen ("invalid.txt","w"); 38 [3] Invalid 18 39 - 19 Passing Grades: Invalid option Option: 40 fprintf(fpass,"%d\n",ch); 20 Expected: Passing Grades: 101, 21 Enter File Name: 0% (1:17) 22 Expected: הרeuישיeיקEXד All grades are evaluated and stored in their respective files. 23 #include<stdio.h> 2 #include<stdlib.h> Enter File Name: 24 DISPLAY FILE MENU //Display error message if input file is not opened. if(fin == NULL) { printf("Error in opening %s!",str); exit(1); } 25 All grades are evaluated and stored in their respective files. [1] Passing 26 / / ΜAIN ΜΕTHOD int main() 4 DISPLAY FILE MENU 27 [2] Failing [1] Passing 28 [3] Invalid { //Declare file pointers FILE *fin,*fpass,*ffail,*finvalid; //Declare variablef to store filename char str[30]; //Declare variables: option and ch int option,ch; 29 7 [2] Failing Option: 30 8 [3] Invalid Invalid Option 31 Option: Check 5 failed //Read first integer from input file fscanf(fin,"%d",&ch); //Use While loop, to read all integers from file and place them in res while (!feof(fin)) { //if integer is with in 70-100 then put them in passed.txt file. if(ch<=100 && ch>=70) { 32 10 11 Invalid Grades: 101, -1, 33 Output: 34 12 Check 4 failed Enter File Name: Error in opening grade.txt! 35 13 Output: 36 v Expected: 14 //Read file name Enter File Name: 37 Enter File Name: printf("Enter File Name: "); scanf("%s",str); 15 All grades are evaluated and stored in their respective files. 38 The file can’t be open. File does not exists. 16 39 v 17 DISPLAY FILE MENU 40 fprintf(fpass,"%d\n",ch); //Open input file in read mode. fin = fopen(str,"r"); //Open Output file in write mode. fpass= fopen ("passed.txt","w"); ffail = fopen ("failed.txt","w"); finvalid = fopen ("invalid.txt","w"); 18 [1] Passing Show diff 19 0% (1:17) [2] Failing 20 21 [3] Invalid 22 Option: 23 Passing Grades: Invalid Option 24 Expected: //Display error message if input file is not opened. if(fin == NULL) { printf("Error in opening %s!",str); exit(1); } 25 26 Enter File Name: 27 All grades are evaluated and stored in their respective files. 28 29 DISPLAY FILE MENU 30 [1] Passing 31 [2] Failing //Read first integer from input file fscanf(fin,"%d" ,&ch); //Use While loop, to read all integers from file and place them in res while (!feof (fin)) { //if integer is with in 70-100 then put them in passed.txt file. if(ch<=100 && ch>=70) { 32 [3] Invalid 33 34 Option: 35 Invalid Option 36 . Check 5 failed 37 38 Output: 39 - Enter File Name: Error in opening grade.txt! 40 fprintf(fpass,"%d\n",ch); Expected: 0% (1:17) C Enter File Name:
Expert Solution
steps

Step by step

Solved in 2 steps with 2 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