Question

Write a complete C program to get data from file name DATA.TXT one line at a...

Write a complete C program to get data from file name DATA.TXT one line at a time until there is no more data in that file. The following is one sample line in DATA.TXT ( have as many record as you wish in DATA.TXT)

Name     SSN                           quiz         mid         assignments      participation     final

LISA         111-11-1111      100         100         100                           100                           100

Jack        222-22-2222      80            80            100                           90                              100

Note that the first line is no in DATA.txt.

Your program should create a file name RESULT.txt that reports Name, SSN and a letter grade according to the following rules:

Total= 15% quiz + 15 %mid +40% assignments + 10% Participation+ 20%final

If total >= 90 then A else if total>=80 then B….

You can print same output to screen as well as RESULT.txt.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C Program:

/* C Program that reads student data from file, calculates grade and writes result to Console and file */

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

//Main function
int main()
{
//File Pointers
FILE *fin, *fout;

char grade;
char name[10], SSN[15];
int quiz, mid, assignments, participation, finalScore;
float total;

//Opening file for reading
fin = fopen("DATA.txt", "r");

//Opening file for writing
fout = fopen("RESULT.txt", "w");

//Read entire data is processed
while(!feof(fin))
{
//Reading data about single student
fscanf(fin, "%s %s %d %d %d %d %d ", name, SSN, &quiz, &mid, &assignments, &participation, &finalScore);

//Calculating total
total = ( ( (15/100.0) * quiz ) + ( (15/100.0) * mid ) + ( (40/100.0) * assignments ) + ( (10/100.0) * participation ) + ( (20/100.0) * finalScore ) );

//Finding grade
if(total >= 90)
grade = 'A';
else if(total >= 80)
grade = 'B';
else if(total >= 70)
grade = 'C';
else if(total >= 60)
grade = 'D';
else
grade = 'F';

//Writing result to file
fprintf(fout, "\n %s %s %c ", name, SSN, grade);

//Writing result to console
printf("\n %s %s %c ", name, SSN, grade);
}

//Closing file pointers
fclose(fin);
fclose(fout);

printf("\n\n");
return 0;
}

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

Sample Output:

CTCstudentResults binl DebuglstudentResults.exe LISA 111-11-1111 A Jack 222-22-2222 A Process returned 0 (0x0) execution time

Add a comment
Know the answer?
Add Answer to:
Write a complete C program to get data from file name DATA.TXT one line at a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that reads a series of words (one word per line) from a file...

    Write a program that reads a series of words (one word per line) from a file named data.txt. Each word in the file should have each of its characters shifted by 1 character value in the ASCII table (incremented) and then that new word with its characters shifted should be printed to a new file named result.txt. Each word from data.txt should be reprinted with its new encoding in result.txt. Your program should not have any knowledge of how many...

  • In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, t...

    In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, then present a menu to the user, and at the end print a final report shown below. You may(should) use the structures you developed for the previous assignment to make it easier to complete this assignment, but it is not required. Required Menu Operations are: Read Students’ data from a file to update the list (refer to sample...

  • 2. In a file called passfail.py, write a Python program to solve the following problem: Given...

    2. In a file called passfail.py, write a Python program to solve the following problem: Given a file students.txt with the following information for a stu dent: student number, average quiz mark, average assignment mark, midterm exam mark, and final exam mark (where each mark is recorded out of 100), de termine if the student has passed or failed based on the following information A student will pass the course if they have a passing mark (50% or higher) for...

  • For this assignment, you are to write a program that does the following: • read exam scores from a file name data.txt into an array, and • after reading all the scores, output the following to the mon...

    For this assignment, you are to write a program that does the following: • read exam scores from a file name data.txt into an array, and • after reading all the scores, output the following to the monitor: the average score and the total number of scores. In addition, the program must use the following functions: //precondition: fileName is name of the file to open, inFile is the input file 2 of 2 //postcondition: inFile is opened. If inFile cannot...

  • Within this C program change the input to a file instead of individual input from the...

    Within this C program change the input to a file instead of individual input from the user. You must take the input file name on the command line. Be sure to have simple error checking to be sure the file exists and was successfully opened. The input file will have the following format: First line: Number of students Second Line: Number of grades Third Line: Student Names, space delimited Fourth+ Line(s): Grades for all students for one assignment, space delimited....

  • python question 2. In a file called passfail.py, write a Python program to solve the following...

    python question 2. In a file called passfail.py, write a Python program to solve the following problem: Given a file students.txt with the following information for a stu dent: student number, average quiz mark, average assignment mark, midterm exam mark, and final exam mark (where each mark is recorded out of 100), de termine if the student has passed or failed based on the following information: • A student will pass the course if they have a passing mark (50%...

  • Write a program that processes a data file of names in which each name is on...

    Write a program that processes a data file of names in which each name is on a separate line of at most 80 characters. Here are two sample names: Hartman-Montgomery, Jane R. Doe, J. D. Strings On each line the surname is followed by a comma and a space. Next comes the first name or initial, then a space and the middle initial. Your program should scan the names into three arrays— surname , first , and middle_init . If...

  • Write a C++ menu driven Payroll program. Must be user friendly.   Menu 1. Check data file  ...

    Write a C++ menu driven Payroll program. Must be user friendly.   Menu 1. Check data file   2. Read Data file 3. Process payroll for one employee 4. Process payroll for all employees 5. Print out to a text or an HTML file 6. Exit You must use the following Payroll classes, structures, pointers, arrays, enum, vector, recursive, advance file I/O, STL, iterators and containers. The program to process an input file below to calculate tax of 28% and output it...

  • C++ programming language Write a program that asks the user for a file name. The file...

    C++ programming language Write a program that asks the user for a file name. The file contains a series of scores(integers), each written on a separate line. The program should read the contents of the file into an array and then display the following content: 1) The scores in rows of 10 scores and in sorted in descending order. 2) The lowest score in the array 3) The highest score in the array 4) The total number of scores in...

  • Program in C Student Data using Structs In this assignment you will create a program (using...

    Program in C Student Data using Structs In this assignment you will create a program (using multiple .c files) to solve the following problem: You have been hired by the university to create a program that will read in input from a .txt file. This input will contain a student name, student id #, their age and their current gpa. You should use the following struct for your student data: struct Student{                 char name[50];                 int id;                 float...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT