Guest User

Untitled

a guest
Dec 14th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.57 KB | None | 0 0
  1. /* CS261- Assignment 1 - Q1.c
  2.  * Sean McGlothlin
  3.  * 10/2/12
  4.  * Solution description:
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <math.h>
  10. #include <time.h>
  11.  
  12. struct student{
  13.     int id;
  14.     int score;
  15. };
  16.  
  17. struct student* allocate(){
  18.  
  19.     struct student *stptr = malloc(sizeof(struct student) * 10); // allocates enough memory for 10 student structures
  20.  
  21.     return stptr;
  22. }
  23.  
  24. void generate(struct student* students){
  25.  
  26.     int i, j = 0;
  27.  
  28.     for(i = 0; i < 10; i++) {
  29.         students[i].score = rand() % 101;
  30.     }
  31.  
  32.     for(i = 0; i < 10; i++) {
  33.         srand(i);
  34.         students[i].id = rand() % 10 + 1;
  35.     }
  36.  
  37.         /*for(j = 0; j < 10; j++) {
  38.             if(students[i].id == students[j].id)  {
  39.                 students[i].id = rand() % 10 + 1;
  40.             }
  41.         } */
  42.     /*Generate random ID and scores for ten students, ID being between 1 and 10, scores between 0 and 100*/
  43.  
  44. }
  45.  
  46. void output(struct student* students){
  47.  
  48.     /*Output information about the ten students in the format:*/
  49.     for(int i = 0; i < 10; i++) {
  50.         printf("ID#: %d \nScore: %d \n", students[i].id, students[i].score);
  51.     }
  52. }
  53.  
  54. void summary(struct student* students){
  55.      /*Compute and print the minimum, maximum and average scores of the ten students*/
  56.  
  57. }
  58.  
  59. void deallocate(struct student* stud){
  60.      /*Deallocate memory from stud*/
  61. }
  62.  
  63. int main(){
  64.  
  65.     struct student* stud = NULL;
  66.  
  67.     srand(time(NULL));
  68.  
  69.     stud = allocate();
  70.  
  71.     generate(stud);
  72.  
  73.     output(stud);
  74.  
  75.     /*call summary*/
  76.  
  77.     /*call deallocate*/
  78.  
  79.     return 0;
  80. }
Add Comment
Please, Sign In to add comment