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 Language - C Sprint 8:36 AM 100% Goals (Requi

ID: 3737301 • Letter: M

Question

Must compile on Visual studio 2015 Language - C Sprint 8:36 AM 100% Goals (Requirements): 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 Functional Specifications Student's Interaction 1. We will assume that student has some text written in an arbitrary text file and wants to submit it as an assignment. The text file only has the content of the work due, it does not contain the name of the assignment or the name of the student Example: (any filename) This is a sample text ofa multiline assignment. This is the second line of the assignment.

Explanation / Answer

SOurceCode:

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

int submitAssignment( char * assignmentName, char* studentName, char * fileName){

char ch, file_name[25];

FILE *fp,*fptr;

fp = fopen(fileName, "r"); // read mode

fptr = fopen("submission.txt", "w");

if (fp == NULL || fptr == NULL)

{

printf("Error while opening the file. ");

return 0;

}

fprintf(fptr,"%s ", assignmentName);

fprintf(fptr,"%s ", studentName);

while((ch = fgetc(fp)) != EOF){

fprintf(fptr,"%c", ch);

}

  

fclose(fp);

fclose(fptr);

return 1;

}

int getAssignment(char * assignmentName, char* studentName, char * assignment){

char c[51],ch;

FILE *fp;

fp = fopen("submission.txt", "r");

if (fp == NULL)

{

printf("Error while opening the file. ");

return 0;

}

//printf("done");

int f1 = 0,f2 = 0,i=0;

while((ch = fgetc(fp)) != EOF){

if(f1==0){

if(ch == ' '){

assignmentName[i] = '';

f1 =1;

i=0;

}

assignmentName[i] = ch;

i++;

}

else if(f2 == 0){

if(ch == ' '){

studentName[i] ='';

f2 =1;

i=0;

}

studentName[i] = ch;

i++;

}

else{

  

assignment[i] = ch;

i++;

}

}

fclose(fp);

//normal adjustments to print the varibles

assignmentName[0] = ' ';

assignment[0] = ' ';

studentName[0] = ' ';

assignment[i]='';

return 1;

}

void test(){

char ch, file_name[50],studentName[50],assignmentName[50];

char assignment[1000];

int i=0;

printf("Enter fileaname : ");

gets(file_name);

printf(" Enter your name : ");

gets(studentName);

printf(" Enter assignment name : ");

gets(assignmentName);

int val1 = submitAssignment(assignmentName,studentName,file_name);

int val2 = getAssignment(assignmentName,studentName,assignment);

  

printf(" Assignment:%s",assignmentName);

printf(" Name:%s",studentName);

printf(" Assignment:");

for(i=0; assignment[i]!=''; i++){

printf("%c",assignment[i]);

}

}

int main()

{

test();

return 0;

}

Sample input and output:

input.txt:

hii this is a file
this is second line
and it is a test file
this is 3rd line
to test the assignment
provided by student.

submission.txt:

rj23
saneeep
hii this is a file
this is second line
and it is a test file
this is 3rd line
to test the assignment
provided by student.