1

1) (10 pts) A class has n students, and the ith student has taken si tests....

Question

1) (10 pts) A class has n students, and the ith student has taken si tests....

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

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 first line has the value of n and the following n lines have information about each student. On the ith of these lines, the first value is si. This is followed by si integers, all in between 0 and 100, inclusive, representing the test scores. Here is a sample file: 4 10 100 80 90 100 90 90 95 80 100 95 3 87 93 90 5 100 90 90 100 90 8 90 90 90 90 80 80 85 85 Write a segment of code that reads in this information from standard input (assuming file redirection on the command prompt as shown in class) into an array of arrays that is dynamically allocated to have precisely the correct number of slots to store the data. Name your array studentscores. All necessary variables have been declared for you below. Please use only these in your solution. Note: you are ONLY allocating the memory and reading in the information. No need to do anything else. Also, the way this is written, you wouldn't have stored the length of each separate array, but don't worry about that for the purposes of this question. int** studentscores; int i, j, numStudents, numScores;

Answers

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


Similar Solved Questions

1 answers
2. An object is placed a distance of 25.0 cm from a converging lens having a...
2. An object is placed a distance of 25.0 cm from a converging lens having a focal length of 10.0 cm. (a) What is the distance of the image from the lens? (b) What is the magnification of the image? (c) Draw a (somewhat to scale) ray diagram showing the lens, object, and image. (d) Is the image real...
1 answers
IP The patient in the figure(Figure 1) is to receive an intravenous injection of medication. In...
IP The patient in the figure(Figure 1) is to receive an intravenous injection of medication. In order to work properly, the pressure of fluid containing the medication must be 109 kPa at the injection point. If the fluid has a density of 1050 kg/m3 , find the height at which the bag of fluid must be...
1 answers
Two charges of ±6.00 µC on the x-axis. the negative charge is at -5 cm and...
Two charges of ±6.00 µC on the x-axis. the negative charge is at -5 cm and the positive one is at 5 cm. Find the magnitude of the electric field at point P on the y-axis, which is 7.00 cm from each charge.   ...
1 answers
ThreePoint Sports Inc. manufactures basketballs for the Women’s National Basketball Association (WNBA). For the first 6...
ThreePoint Sports Inc. manufactures basketballs for the Women’s National Basketball Association (WNBA). For the first 6 months of 2020, the company reported the following operating results while operating at 80% of plant capacity and producing 119,900 units. Amount Sales $4,676,100 ...
1 answers
Please advise James and Maria as to whether their situations qualify for the Business Use of...
Please advise James and Maria as to whether their situations qualify for the Business Use of Home Deduction and write them a memo/or memos. James and Maria moved into a new home at the beginning of the year and James set up a home office in one of the rooms for his business. James works as a busines...
1 answers
Match the QuickBooks form on the left with the customer scenario on the right that is,...
Match the QuickBooks form on the left with the customer scenario on the right that is, when would you use each QuickBooks form). Sales Order Target You want to remind your customer about the outstanding invoices they still owe you for invoices they st IL Invoice Target Customer received goods and pa...
1 answers
0 m CALCULATOR PRINTER VERSION BACK NEXT Multiple Choice Question 76 The following information is available...
0 m CALCULATOR PRINTER VERSION BACK NEXT Multiple Choice Question 76 The following information is available for completed Job No. 402: Direct materials, $120000; direct labor, 5180000; manufacturing overhead applied, $110000 units produced, 8000 units units sold, 5000 units. The cost of the finished...
1 answers
Any substance that produces a change in function when administered to living organisms.
any substance that produces a change in function when administered to living organisms....
1 answers
An endothermic aqueous reaction occurs by a two-step mechanism, shown below. Step 1: A2X2 +Y---> A2X...
An endothermic aqueous reaction occurs by a two-step mechanism, shown below. Step 1: A2X2 +Y---> A2X +XY (slow) Step 2: A2X2 +XY --->A2X + X2 + Y (fast) -write the overall reaction. -In this reaction the intermediate is _____, and the catalyst is _____. -Sketch the reaction profile for the ove...
1 answers
The given answer is (d) (i) 15.18 kW (ii) 3.08 However, I don't know how can...
The given answer is (d) (i) 15.18 kW (ii) 3.08 However, I don't know how can I solve this question. Could anyone please help me? Thank you d) A freezer maintains a temperature of -18°C inside the cabinet, while the room temperature is at 24°C. If the electrical power consumed by the ref...
1 answers
3. Suppose X is a metric space with a sequence of points Xn e X with...
3. Suppose X is a metric space with a sequence of points Xn e X with the property that for each n + m we have d(Xn, Xm) = 1. Prove that no subsequence of xn converges, and that therefore X is not compact. Hint: You could use the previous problem....
1 answers
Can you answer that for me and explain why? 24. A Company recorded the following cash...
Can you answer that for me and explain why? 24. A Company recorded the following cash transactions for the year: Paid $90,000 for salaries. Paid $40,000 to purchase office equipment. Paid $10,000 for utilities. Paid $4,000 in dividends. Collected $140,000 from customers. Recorded $3,000 in depreciat...
1 answers
2) Define the term “margin of safety.” If Revere Company expects to sell 1,250 units of...
2) Define the term “margin of safety.” If Revere Company expects to sell 1,250 units of its product at $12 per unit, and break-even sales for the product are $13,200, what is the margin of safety ratio?...
1 answers
Draw the major product TH"]/HEAT H0 (excess) 1 MBH, in THF 22 °C/1h 2) 3M NaOH(aq)/30%...
draw the major product TH"]/HEAT H0 (excess) 1 MBH, in THF 22 °C/1h 2) 3M NaOH(aq)/30% H2O Na+/-OOH/50-50 c/1h =-18.6 (73% yield) ()* -pinene BH, in THE o "C/2h (m)" (2.0 equiv) (n) (3.0 equiv) 1) BH, in THF O "C/2h 2) 0 °C/3M NaOH(aq.) 30% H,0/1h [Na/ "OOH H.C. Brown....
1 answers
A 2.5-kg object attached to an ideal spring with a force constant (spring constant) of 15...
A 2.5-kg object attached to an ideal spring with a force constant (spring constant) of 15 N/m oscillates on a horizontal, frictionless track. At time t = 0.00 s, the cart is released from rest at position x = 8 cm from the equilibrium position. (a) What is the frequency of the oscillations of the ob...
1 answers
Akiko Hamaguchi is a manager at a small sushi restaurant in Phoenix, Arizona, Akiko is concerned...
Akiko Hamaguchi is a manager at a small sushi restaurant in Phoenix, Arizona, Akiko is concerned that the weak economic environment has hampered foot traffic in her area, thus causing a dramatic decline in sales. In order to offset the decline in sales, she has pursued a strong advertising campaign....

-- 0.036643--