Question

1) (10 pts) A class has n students, and the ith student has taken si tests. This information is stored in a file where the fi

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

I have also implemened storing lengths of each student's scores array, this is useful in printing the input data and verify whether data has been properly read and stored. The code highlighted in YELLOW is not required for this question. Since, it has been mentioned only input reading and storing is required and storing lengths is not required.

I have used malloc for dynamically allocating memory.

I have included my code and screenshots in this answer. In case, there is any indentation issue due to editor, then please refer to code screenshots to avoid confusion.

------------------main.c-----------

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

int main()
{
   int **studentscores; //similar to two dimensional array for storing scores of all studemts
   int i, j, numStudents, numScores;
   scanf("%d", &numStudents); //read numnber of students

   int *lengths; /* to store lengths of students marks araray (This is not required for this question)
   but i did it to print the entered data and verify if data is insert properly) */

   studentscores = (int **)malloc(numStudents * sizeof(int *)); //allocate space for numStudents
   lengths = (int *)malloc(numStudents * sizeof(int)); //allocate space for numStudents sized array

   for(i = 0; i < numStudents; i++) //for each student
   {
       scanf("%d", &numScores); //read number of scores
       lengths[i] = numScores; //store number of scores as length for ith student
       studentscores[i] = (int *)malloc(numScores * sizeof(int)); //get space for storing marks for each student
       for(j = 0; j < numScores; j++)
           scanf("%d", &studentscores[i][j]); //read each score
   }

   printf("\nData read successfully....\n");
   for(i = 0; i < numStudents; i++) //print each student's data
   {
       printf("Student %d scores are : \n", i+1);
       for(j = 0; j < lengths[i]; j++)
           printf("%d ", studentscores[i][j]);
       printf("\n\n");
   }
  
   return 0;
}

------------------Screenshot main.c-----------

-/c/temp/main.c - Sublime Text (UNREGISTERED) 2:56 PM * main.c input.txt #include <stdio.h> #include <stdlib.h> #include <str

------------------Output----------

/c/temp/input.txt - Sublime Text (UNREGISTERED) 2:52 PM 1 2 3 4 5 6 main.c. X input.txt 4 10 100 80 90 100 90 90 95 80 100 95

2:52 PM vs@ubuntu: -/c/temp vs@ubuntu:-/c/temps gcc main.c vs@ubuntu:-/c/temp$ ./a.out < input.txt Data read successfully....

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

I hope this helps you,

Please rate this answer if it helped you,

Thanks for the opportunity

Add a comment
Know the answer?
Add Answer to:
1) (10 pts) A class has n students, and the ith student has taken si tests....
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
  • C++ Redo PROG8, a previous program using functions and/or arrays. Complete as many levels as you...

    C++ Redo PROG8, a previous program using functions and/or arrays. Complete as many levels as you can. Level 1: (20 points) Write FUNCTIONS for each of the following: a) Validate #students, #scores. b) Compute letter grade based on average. c) Display student letter grade. d) Display course average. Level 2: (15 points) Use ARRAYS for each of the following. e) Read a student's scores into array. f) Calculate the student's average based on scores in array. g) Display the student's...

  • The Computer Science Instructor has just completed compiling all the grades for the C++ Programming class....

    The Computer Science Instructor has just completed compiling all the grades for the C++ Programming class. The grades were downloaded into a file titled ‘studentGrades.txt’ (attached). Write a C++ Program that reads this file and calculates the following as described : The final semester numeric and letter grade (using 10 point scale) Calculated as follows: Labs 1-6 (worth 50% of final grade) Lab 7 is extra credit (worth 2 % of final grade OR replaces lowest lab grade – Select...

  • C++ program that reads students' names followed by their test scores (5 scores) from the given...

    C++ program that reads students' names followed by their test scores (5 scores) from the given input file, students.txt. The program should output to a file, output.txt, each student's first name, last name, followed by the test scores and the relevant grade. All data should be separated by a single space. Student data should be stored in a struct variable of type StudentType, which has four components: studentFName and studentLName of type string, an array of testScores of type int...

  • Please help me with this program.You are to write a C++ program that will read in...

    Please help me with this program.You are to write a C++ program that will read in up to 15 students with student information and grades. Your program will compute an average and print out certain reports. Format: The information for each student is on separate lines of input. The first data will be the student�s ID number, next line is the students name, next the students classification, and the last line are the 10 grades where the last grade is...

  • Write the definition of the class Tests such that an object of this class can store...

    Write the definition of the class Tests such that an object of this class can store a student's first name, last name, five test scores, average test score, and grade. (Use an array to store the test scores.) Add constructors and methods to manipulate data stored in an object. Among other things, your class must contain methods to calculate test averages, return test averages, calculate grades, return grades, and modify individual test scores. The method toString must return test data...

  • C++: Create a grade book program that includes a class of up to 20 students each...

    C++: Create a grade book program that includes a class of up to 20 students each with 5 test grades (4 tests plus a Final). The sample gradebook input file (CSCI1306.txt) is attached. The students’ grades should be kept in an array. Once all students and their test scores are read in, calculate each student’s average (4 tests plus Final counts double) and letter grade for the class. The output of this program is a tabular grade report that is...

  • c++ implement a student class Determine the final scores, letter grades, and rankings of all students...

    c++ implement a student class Determine the final scores, letter grades, and rankings of all students in a course. All records of the course will be stored in an input file, and a record of each student will include the first name, id, five quiz scores, two exam scores, and one final exam score. For this project, you will develop a program named cpp to determine the final scores, letter grades, and rankings of all students in a course. All...

  • Please help. I need a very simple code. For a CS 1 class. Write a program...

    Please help. I need a very simple code. For a CS 1 class. Write a program in Java and run it in BlueJ according to the following specifications: The program reads a text file with student records (first name, last name and grade). Then it prompts the user to enter a command, executes the command and loops. The commands are the following: "printall" - prints all student records (first name, last name, grade). "firstname name" - prints all students with...

  • THIS IS FINAL COURSE ASSIGNMENT, PLEASE FOLLOW ALL REQUIREMENTS. Hello, please help write program in JAVA...

    THIS IS FINAL COURSE ASSIGNMENT, PLEASE FOLLOW ALL REQUIREMENTS. Hello, please help write program in JAVA that reads students’ names followed by their test scores from "data.txt" file. The program should output "out.txt" file where each student’s name is followed by the test scores and the relevant grade, also find and print the highest test score and the name of the students having the highest test score. Student data should be stored in an instance of class variable of type...

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
ADVERTISEMENT