Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Must compile on Visual studio 2015 Goals (Requirements) - No Change The program

ID: 3708388 • Letter: M

Question

Must compile on Visual studio 2015 Goals (Requirements) - No Change The program will help a student to submit a homework assignment as a text file. The file should contain the name of the assignment, name of the student and the actual content of the assignment as multiline text. The teacher should be able to open the submitted file and assign a numerical score to it A new file should then be created and saved that contains the name of the assignment name of the student, the score of the assignment followed by the content of the assignment. Student should be able to see the graded assignment Development Strategy (Removed from Project 3, moved to Project4) 1. We will split the code into .h and.c files 2. We will learn how to build two application from a single common code. Phase 1: 1. Split the code into two assignmentgrading3.h, assignmentgrading3.c like illustrated in the class. Phase 2: 2. Create two applications, one for student and the other for teacher. Your student and teacher applications must be fully functional. Ask for help if you are confused Bonus [10 points]: Deliver a library for assignmentgrading.h with proper README.txt file.

Explanation / Answer

// File Name: AssignmentGrading.h
#ifndef ASSIGNMENTgRADING_H
#define ASSIGNMENTgRADING_H

// Maximum column for matrix
#define MAXC 1000
// Maximum row for matrix
#define MAXR 20

// Prototype of functions
int readFile(char fileName[], char fileContents[][MAXC]);
void writeFile(char fileName[], char fileContents[][MAXC], int len, int gradeStatus);
void displayFile(char fileContents[][MAXC], int len, int gradeStatus);

#endif

-----------------------------------------------------------------------------------

// File Name: AssignmentGrading.c
#include<stdio.h>
#include<stdlib.h>
#define MAXC 1000
#define MAXR 20

/*
* Function to read the contents to a file and store it in matrix
* char fileName[]: file to read the data from
* char fileContents[][MAXC]: matrix which will store the data read from file
*/
int readFile(char fileName[], char fileContents[][MAXC])
{
// File pointer declared
FILE *fileRead;
// To store number of rows
int row = 0;

// Opens the file for reading and checks whether it can be opened or not
if ((fileRead = fopen(fileName, "r")) == NULL)
{
// If unable to open shows error message
printf("Error! in opening file for reading %s", fileName);
// Program exits if the file pointer returns NULL.
exit(1);
}// End of if condition

// Loops till end of file
while(!feof(fileRead))
{
// Extracts a line and stores it in matrix fileContents row index position
fgets(fileContents[row], MAXC, fileRead);
// Increase the row counter by one
row++;
}// End of while condition

// Closes the file
fclose(fileRead);
// Returns number of lines in the file
return row;
}// End of function

/*
* Function to write the contents to a file
* char fileName[]: file to write the data
* char fileContents[][MAXC]: matrix that contents the data
* int len: number of rows in the matrix
* int gradeStatus: if grade status is zero then don't write the grade, otherwise write the grade
*/
void writeFile(char fileName[], char fileContents[][MAXC], int len, int gradeStatus)
{
// File pointer declared
FILE *fileWrite;
// Row counter
int row = 0;

// Opens the file for writing and checks whether it can be opened or not
if ((fileWrite = fopen(fileName, "w")) == NULL)
{
// If unable to open, shows error message
printf("Error! in opening file for writing %s", fileName);
// Program exits if the file pointer returns NULL.
exit(1);
}// End of if condition

// Writes the assignment name
fprintf(fileWrite, "%s ", "HW1");
// Writes the candidate name
fprintf(fileWrite, "%s ", "Pyari Mohan");

// Checks if the grade status is not zero
if(gradeStatus != 0)
{
// Write the grade assigned by the teacher to file
fprintf(fileWrite, "%d ", gradeStatus);
// Set the row counter to 2
row = 2;
}// End of if condition

// Loops till number of rows
for(; row < len; row++)
// Writes the contents of the fileContents row index position data to file
fprintf(fileWrite, "%s", fileContents[row]);
// Close the file
fclose(fileWrite);
}// End of function

/*
* Function to display the contents of matrix
* char fileContents[][MAXC]: matrix that contents the data
* int len: number of rows in the matrix
* int gradeStatus: if grade status is zero then don't write the grade, otherwise write the grade
*/
void displayFile(char fileContents[][MAXC], int len, int gradeStatus)
{
// Row counter
int row = 0;
// Displays assignment name
printf(" Assignment Name: %s", fileContents[row++]);
// Displays candidate name
printf(" Name: %s", fileContents[row++]);

// Checks if the grade status is not zero
if(gradeStatus != 0)
// Display the score
printf(" Score: %s", fileContents[row++]);
printf(" Assignment: ");
// Loops till number of rows
for(; row < len; row++)
// Displays each row contents
printf("%s", fileContents[row]);
}// End of function

// main function definition
int main()
{
// Declares a matrix to store data
char fileContents[MAXR][MAXC];
// To store number of rows
int numberOfRows;
// To store grade status
int gradeStatus = 0;
// Loop variable
int c;

// Calls the function to read "Assignment.txt" file contents and store it in matrix
numberOfRows = readFile("Assignment.txt", fileContents);

// Calls the function to write the contents of fileContents to "Submission.txt" file without score
writeFile("Submission.txt", fileContents, numberOfRows, gradeStatus);

// Calls the function to read "Submission.txt" file contents and store it in matrix
numberOfRows = readFile("Submission.txt", fileContents);

// Calls the function to display data without score
displayFile(fileContents, numberOfRows, gradeStatus);

// Accepts the score
printf(" Please assign a numerical score: ");
scanf("%d", &gradeStatus);

// Calls the function to write the contents of fileContents to "GradeAssignment.txt" file with score entered by the teacher
writeFile("GradeAssignment.txt", fileContents, numberOfRows, gradeStatus);

// Calls the function to read "GradeAssignment.txt" file contents and store it in matrix
numberOfRows = readFile("GradeAssignment.txt", fileContents);

// Calls the function to display data with score
displayFile(fileContents, numberOfRows, gradeStatus);
}// End of main function

Sample Output:

Assignment Name: HW1

Name: Pyari Mohan

Assignment:
This is a sample text of a multiline assignment.
This is the second line of the assignment.
This is the third line of the assignment.
Thre program should be able to read assignments of length up to 1000 characters and arbitrary numbr of lines.
Please assign a numerical score: 88

Assignment Name: HW1

Name: Pyari Mohan

Score: 88

Assignment:
This is a sample text of a multiline assignment.
This is the second line of the assignment.
This is the third line of the assignment.
Thre program should be able to read assignments of length up to 1000 characters and arbitrary numbr of lines.

Assignment.txt file contents

This is a sample text of a multiline assignment.
This is the second line of the assignment.
This is the third line of the assignment.
Thre program should be able to read assignments of length up to 1000 characters and arbitrary numbr of lines.

Submission.txt file contents

HW1
Pyari Mohan
This is a sample text of a multiline assignment.
This is the second line of the assignment.
This is the third line of the assignment.
Thre program should be able to read assignments of length up to 1000 characters and arbitrary numbr of lines.

GradeAssignment.txt file contents

HW1
Pyari Mohan
88
This is a sample text of a multiline assignment.
This is the second line of the assignment.
This is the third line of the assignment.
Thre program should be able to read assignments of length up to 1000 characters and arbitrary numbr of lines.