Question

In: Computer Science

Write a program that gathers input from the user and writes the information out to a...

Write a program that gathers input from the user and writes the information out to a file (output.txt).  

Your main method should gather the input, calculate the average, and write the output. You should have a separate method that writes the output to a file. You can have other methods as well if you choose. However, you MUST have at least one other method in addition to the main method.

Inputs:
Student Number
Name
Class name
Grades 1-5 (5 individual grades)

Output: Student Number: [student number]
Student Name: [student name]
Class: [class name]
Grade 1: [grade 1]
Grade 2: [grade 2]
Grade 3: [grade 3]
Grade 4: [grade 4]
Grade 5: [grade 5]
Average: [grade average]


Example output.txt file:
Student Number: 12345
Student Name: Marty McFly
Class: Music Theory
Grade 1: 90
Grade 2: 85
Grade 3: 70
Grade 4: 99
Grade 5: 96
Average: 88

Solutions

Expert Solution

Since you havn't mentioned the language i have written it in c, If you have any queries please comment

SOLUTION:

#include <stdio.h>
#include <string.h>
double average(int grades[]){
   double avg=0;
   int i;
   for(i=0;i<5;i++)
   {
       avg+=grades[i];
   }
   return avg/5;
}
int main()
{
   FILE *filePointer;
   int studentNumber,i,j,grades[5];
   char studentName[40];
//So, the file can be opened as
filePointer = fopen("dataFile.txt", "a+");
//Read data Student Number
printf("Student Number ");
   scanf("%d",&studentNumber);
   //Add it to the file by using filePrint operation
   fprintf(filePointer, "%s %d \n", "Student Number ", studentNumber);
   //read studet Name and update it to file
   printf("Student Name ");
   scanf("%s",&studentName);
   fprintf(filePointer, "%s %d \n", "Student Name ", studentName);
   //Read grades and add it to th file as done above
   for(i=0;i<5;i++)
   {
       printf("Enter Grade %d",i);
       scanf("%d",&grades[i]);
       fprintf(filePointer, "%s %d %d \n ", "Grade ",i, grades[i]);
   }
   double avg=average(grades);
   fprintf(filePointer, "%s %d %ld \n ", "Average is ",i, avg);
}

CODE IMAGE :

INPUT :

OUTPUT FILE:


Related Solutions

Write java program that will ask for the user for 2 input lines and print out...
Write java program that will ask for the user for 2 input lines and print out all words that occur 1 or more times on both lines (case sensitive). Write this without arrays and method. Here is a sample run: <Output> Enter two lines to process. The quick brown fox jumps over a lazy dog The fox hound outruns the lazy dog The words that occur on both lines are: The fox lazy dog
Write a short C++ program that takes all the lines input to standard input and writes...
Write a short C++ program that takes all the lines input to standard input and writes them to standard output in reverse order. That is, each line is output in the correct order, but the ordering of the lines is reversed. Please use vector datatype standaard library #include <vector> Thanks
Write a program that takes a string input from the user and then outputs the first...
Write a program that takes a string input from the user and then outputs the first character, then the first two, then the first three, etc until it prints the entire word. After going up to the full word, go back down to a single letter. LastNameUpDown. Input: Kean Output: K Ke Kea Kean Kea Ke K
Write a program that prompts the user to input their first name from the keyboard and...
Write a program that prompts the user to input their first name from the keyboard and stores them in the variable "firstName". It does the same for last name and stores it in the variable "lastName". It then uses strcat to merge the two names, separates them by a space and stores the full name into a string variable called "fullName". In the end, the program must print out the string stored within fullName. ANSWER IN C LANGUAGE ! You...
Write a C++ Program Write a program that prompts the user to input a string. The...
Write a C++ Program Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning...
Write a program that prompts the user to input a string. The program then uses the...
Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning of your program and...
PYTHON Write a program that accepts a range of input from the user and checks whether...
PYTHON Write a program that accepts a range of input from the user and checks whether the input data is sorted or not. If the data series is already sorted your program should print “True” or should print “False” otherwise. You should not use any sort function for this program. Input: How many numbers you want to input: 3 # user input 3 Input the number: 5 Input the number: 2 Input the number: 7 Output: False
2) Write a C++ program that accepts a sentence as an input from the user. Do...
2) Write a C++ program that accepts a sentence as an input from the user. Do the following with the sentence. Please use C++ style string for this question. 1) Count the number of letters in the input 2) Change all lower case letters of the sentence to the corresponding upper case
Write a program that accept an integer input from the user and display the least number...
Write a program that accept an integer input from the user and display the least number of combinations of 500s, 100s, 50s, 20s, 10s, 5s, and 1s. Test your solution using this samples] a. Input: 250 Output: 1x200s, 1x50s b. Input: 1127 Output: 5x200s, 1x100s, 1x20s, 1x5s, 2x1s c. Input: 1127 Output: 5x200s, 1x100s, 1x20s, 1x5s, 2x1s d. Input: 19 Output: 1x10s, 1x5s, 4x1s ​[Hints] o Use division to determine the number of occurrence of each element (i.e. 200, 100)...
Need this program in python. The data must be taken from user as input. Write a...
Need this program in python. The data must be taken from user as input. Write a program that prompts the user to select either Miles-to-Kilometers or Kilometers-to-Miles, then asks the user to enter the distance they wish to convert. The conversion formula is: Miles = Kilometers X 0.6214 Kilometers = Miles / 0.6214 Write two functions that each accept a distance as an argument, one that converts from Miles-to-Kilometers and another that converts from Kilometers-to-Miles The conversion MUST be done...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT