Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* CS261- Assignment 1 - Q1.c
- * Sean McGlothlin
- * 10/2/12
- * Solution description:
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <time.h>
- struct student{
- int id;
- int score;
- };
- struct student* allocate(){
- struct student *stptr = malloc(sizeof(struct student) * 10); // allocates enough memory for 10 student structures
- return stptr;
- }
- void generate(struct student* students){
- int i, j = 0;
- for(i = 0; i < 10; i++) {
- students[i].score = rand() % 101;
- }
- for(i = 0; i < 10; i++) {
- srand(i);
- students[i].id = rand() % 10 + 1;
- }
- /*for(j = 0; j < 10; j++) {
- if(students[i].id == students[j].id) {
- students[i].id = rand() % 10 + 1;
- }
- } */
- /*Generate random ID and scores for ten students, ID being between 1 and 10, scores between 0 and 100*/
- }
- void output(struct student* students){
- /*Output information about the ten students in the format:*/
- for(int i = 0; i < 10; i++) {
- printf("ID#: %d \nScore: %d \n", students[i].id, students[i].score);
- }
- }
- void summary(struct student* students){
- /*Compute and print the minimum, maximum and average scores of the ten students*/
- }
- void deallocate(struct student* stud){
- /*Deallocate memory from stud*/
- }
- int main(){
- struct student* stud = NULL;
- srand(time(NULL));
- stud = allocate();
- generate(stud);
- output(stud);
- /*call summary*/
- /*call deallocate*/
- return 0;
- }
Add Comment
Please, Sign In to add comment