Question

Write the C program, to achieve as shown in the sample code execution, using the given...

Write the C program, to achieve as shown in the sample code execution, using the given struct and using the comments in the given main program below:

typedef struct{
char first[20];

char last[20]; float gpa;
int score;

} student;

int main(void){ student *ptr;

//first name //last name //student gpa //student score

}

//ask a user to enter the number of students, num
//dynamically allocate memory for an array of students of the appropriate size (i.e.

//num that the user just entered)
//read the data from the text file (studentinfo.txt) to initialize the array above
//create a menu (as shown in the sample code execution) and display the requested info.

the file

ordan Young
2.65 6
Landon Evans
2.97 69
Eve Spencer
2.24 5
Angel Morgan
3.00 8
John Brooks
2.01 53
Lucy Morgan
2.14 10
Phoebe Martin
2.77 82
Colton Brown
3.71 82
Ivy Simpson
3.15 73
Eve Brooks
3.18 15
Asher Adams
2.35 66
Sophia Green
3.20 52
Jane Green
3.15 98
Evelyn Perry
3.50 65
Angel Morgan
2.60 81
Easton Young
2.30 46
Landon Young
3.28 44
John Jackson
3.01 83
Jordan Martin
2.57 9
Jordan Brown
3.16 14
Eve Green
2.10 18
John Adams
1.92 40
Mason Doe
2.77 84
Ivy Jones
3.07 81
Jane Jones
2.18 7
Jim Jones
2.45 40
Olivia Green
2.40 53
Anna Scott
3.17 42
Connor Martin
2.09 66
Phoebe Hill   
2.40 63
Jane Martin
2.27 30
Jordan Brooks
1.91 44
Anna Brown
2.77 2
Eve Green
1.96 99
Ethan Jones
2.14 17
Landon Doe
2.68 11
Jane Tripp
2.23 38
Jim Adams
2.91 20
Eve Doe
3.13 49
Landon Perry
1.92 34
Asher Doe
3.34 96
Jordan George
3.14 93
Adrian Brooks
2.48 6
Easton Scott
2.58 74
Amelia Moore
2.45 27
Jim Smith
3.51 43
Landon Wright
3.36 55
James Wright
2.06 95
Ivy Green
2.28 42
John Brooks
2.44 99
Eve Brooks
2.77 31
Mason Hill   
2.18 71
Olivia Jones
2.09 67
Evelyn Wright
2.37 54
Angel Jackson
2.22 70
Adrian Scott
3.54 67
Connor Morgan
3.16 18
Anna Moore
2.99 13
Ivy Street
3.85 100
Colton Jackson
2.58 18
Amelia Thomas
2.43 4
Olivia Scott
2.69 57
Mason Jones
3.57 89
Sophia Simpson
2.25 67
Connor Martin
2.92 20
Angel Jackson
3.16 37
Asher Perry
3.72 47
Eve Jones
2.29 99
Lucy Wright
2.32 16
Jim Brown
2.70 86
Angel Doe
2.74 65
Sophia Doe
2.69 38
Ethan Smith
2.65 20
Angel Jones
2.65 43
Jane Wright
3.05 49
Ethan Jackson
3.02 13
Adrian Wright
2.49 59
James Doe
2.68 23
James Doe
3.96 39
Phoebe Street
3.46 59
Evelyn Jackson
3.03 26
Olivia Street
2.71 30
Angel Scott
3.85 62
Jane Spencer
3.72 27
Mason Wright
3.01 83
Asher Smith
2.80 99
Olivia Evans
2.45 74
Lucy Scott
2.44 35
Asher Evans
3.13 59
Easton Hall   
3.79 11
Connor Young
2.07 91
Grace Doe
1.99 88
Easton Thomas
3.66 82
Lucy Perry
2.53 27
Jane Tripp
3.07 60
Eve Martin
2.25 3
Angel Spencer
3.79 43
Asher Doe
3.44 32
Olivia Jackson
1.84 17
Colton George
2.98 18
Connor Tripp
2.37 43
Asher Jackson
2.58 10
Jane Green
2.89 60
James Green
3.65 48
Asher Young
2.38 70
Asher Brown
3.91 70
Asher Morgan
2.72 64
Jordan Jackson
2.09 4
Mason Thomas
2.21 7
Connor Adams
2.42 32
Easton Thomas
3.38 54
Amelia Jackson
2.09 66
Easton Jones
2.60 41
Grace Young
3.00 82
Sophia Green
2.33 72
Ivy Tripp
2.69 97
Easton Jackson
3.68 54
James Brown
3.29 33
Phoebe Jackson
2.07 11
Grace Jackson
3.35 62
Jane Street
2.17 78
Anna Adams
3.17 43
Adrian Hill   
1.82 10
Connor Street
2.51 27
Ethan Green
2.66 16
Jane George
2.84 29
Amelia Hall   
2.10 45
Colton Martin
3.20 53
Easton Moore
2.71 46
Anna Smith
2.60 88
Connor Hill   
3.31 52
Ethan Adams
2.99 95
Olivia Wright
2.44 64
Easton Evans
2.72 96
Jim Tripp
2.31 25
Jane Smith
2.28 68
Ethan Green
2.84 29
Asher Scott
3.83 68
Jane Green
3.72 70
Jim Tripp
2.31 7
Jane Tripp
2.79 26
Amelia Jones
3.98 23
James Wright
3.03 67
Sophia Hall   
3.60 85
Angel Evans
3.21 35
Eve Jones
2.07 79
Sophia Doe
2.64 68
Angel Evans
2.23 1
Eve Wright
2.44 61
Jim Adams
2.64 39
Adrian Jones
3.26 92
Anna Moore
1.97 1
Olivia Evans
2.96 47
Grace Morgan
3.11 43
Grace Adams
3.52 47
Jim Moore
3.51 78
Jim Street
2.98 33
Jordan Thomas
2.95 79
Connor Wright
3.09 48
Phoebe Spencer
2.19 4
Lucy Thomas
2.53 18
James Hill   
3.16 73
Ethan Thomas
2.65 48
Eve Perry
3.21 16
Ethan Hill   
2.14 35
Jane Smith
2.26 61
Anna Wright
3.10 20
Evelyn George
3.15 74
Landon Hill   
3.81 25
Sophia Street
2.01 92
Easton Perry
2.62 27
Asher Jackson
3.04 77
Connor Martin
2.67 19
Sophia Jackson
1.85 29
Colton Jones
1.95 10
Jim Green
2.39 58
Angel Scott
2.07 69
Connor Tripp
2.36 55
Landon Scott
2.07 43
Connor Smith
3.38 65
Colton Perry
3.71 65
Jane Scott
2.84 68
James Young
2.41 64
Grace Moore
2.46 95
Amelia Hall   
2.20 21
John George
2.44 71
Evelyn George
3.09 24
Jim George
1.99 12
Colton Young
2.53 61
Ethan Hall   
2.08 46
Easton Brown
3.05 46
Olivia Street
2.51 67
Connor Perry
3.50 78
Evelyn Hill   
3.33 36
Grace Spencer
3.36 67
James Spencer
2.87 42
Easton Brooks
3.58 85
Phoebe Green
3.59 84
Landon Hill   
2.66 26
Olivia Brooks
2.58 62
Evelyn Thomas
2.06 59
Adrian Brown
3.13 55
Evelyn Adams
2.64 87
Grace Tripp
3.66 27
John Hill   
3.03 32
Amelia Perry
3.09 12
Mason Brooks
2.87 94
Asher Young
3.73 65
Amelia George
3.98 48
Anna George
3.85 64
Sophia Thomas
2.53 55
Jane Green
2.85 65
Amelia Doe
3.45 55
Asher Thomas
2.61 73
Evelyn Moore
2.76 53
Evelyn Smith
2.48 100
Angel Spencer
2.59 22
Asher Spencer
2.40 11
Grace Adams
2.60 11
Eve Scott
3.32 7
Anna Brown
2.89 41
Ethan Brown
3.03 45
Colton Morgan
3.31 37
John Scott
2.45 77
Jane Spencer
2.97 63
Adrian Doe
3.23 78
Landon Smith
3.34 94
Connor Street
2.19 98
Phoebe Simpson
2.70 20
Angel Green
3.23 14
Jim Brown
3.88 70
Amelia Doe
2.72 10
Jane Adams
3.91 53
Landon Thomas
2.29 54
Grace Morgan
2.58 87
Landon Evans
2.21 49
Adrian Street
2.84 40
Mason Green
2.92 68
Sophia Wright
3.28 75
Connor Scott
3.58 53
Grace Adams
2.10 35
Easton Adams
2.72 15
Eve Adams
2.60 59
Phoebe Doe
1.90 27
Asher Morgan
3.05 5
Mason Morgan
2.36 76
Mason Simpson
3.51 25
Ethan Moore
3.82 45
Sophia Tripp
2.63 69
James Perry
3.41 36
Easton Evans
3.17 74
John Brooks
3.71 40
Landon Street
3.62 69
Olivia Moore
2.61 71
Connor Perry
3.51 45
Sophia Hall   
3.98 2
Connor Martin
2.18 34
Lucy Brown
3.18 43
Amelia Spencer
3.09 28
Easton George
3.26 20
Jane Jones
1.93 83
Jane Martin
2.90 43
Amelia Simpson
3.00 89
Jane Doe
2.59 40
Eve Street
2.15 77
James Jones
2.72 40
Mason Brown
2.97 81
Phoebe Simpson
2.18 76
Evelyn Jackson
2.28 38
Grace Doe
2.32 22
Phoebe Hill   
2.17 80
Adrian Spencer
2.09 95
Ivy Simpson
3.53 33
Jim Moore
2.53 68
Landon George
2.30 44
Asher Adams
2.96 84
Mason George
2.92 77
Jane Perry
2.97 17
Evelyn Spencer
2.25 87
Grace Perry
2.49 99
Jordan Wright
1.91 52
Eve Morgan
2.40 89
Eve Wright
3.55 59
Lucy Thomas
3.48 16
Easton Moore
2.97 20
Ivy Evans
3.93 41
Adrian Wright
3.96 75
Jordan Perry
2.81 83
Landon Smith
2.62 79
Mason Green
3.82 32
Anna Brown
2.44 54
Asher Adams
2.64 9
Lucy Green
2.90 12
Olivia Thomas
1.90 14
Ethan Brown
3.51 68
Asher Brooks
2.39 50
Anna Perry
3.23 19
Jim Brooks
2.29 50
Jim Adams
3.55 15
Mason Spencer
3.45 6

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

// C code

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
typedef struct {
   char first[20];
   char last[20];
   float gpa;
   int score;

} student;

int main()
{
   student* ptr = NULL;
   FILE* fptr;
   //Open file
   fptr = fopen("studentInfo.txt", "r");
   //If file not found...
   if (fptr == NULL)
   {
       printf("cannot open file \n");
       return -1;
   }
   // ask a user to enter the number of students, num
   printf("Enter number of students: ");
   int n;
   scanf("%d", &n);
   //create dynamic array of students...
   ptr = (student*)malloc(n * sizeof *ptr);
   int count = 0;
   //Read students from file
       for (int i = 0; i < n; i++)
       {
           fscanf(fptr, "%s", ptr[count].first);
           fscanf(fptr, "%s", ptr[count].last);
           fscanf(fptr, "%f", &ptr[count].gpa);
           fscanf(fptr, "%d", &ptr[count].score);          
           count++;
       }

   //first name //last name //student gpa //student score
       //Display students.......
       for (int i = 0; i < n; i++)
       {
           printf("Name: %s %s, GPA = %.2f, Score = %d\n", ptr[i].first, ptr[i].last, ptr[i].gpa, ptr[i].score);
       }
       //pause
       system("pause");
       return 0;

}

//studentInfo.txt

//Output

//If you need any help regarding this solution........ please leave a comment..... thanks

Add a comment
Know the answer?
Add Answer to:
Write the C program, to achieve as shown in the sample code execution, using the given...
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
  • CREATE TWO C++ PROGRAMS : Program 1 Write a program that reads in babynames.txt (provided) and...

    CREATE TWO C++ PROGRAMS : Program 1 Write a program that reads in babynames.txt (provided) and outputs the top 20 names, regardless of gender. The file has the following syntax: RANK# BoyName Boy#OfBirths Boy% GirlName Girl#OfBirths Girl% You should ignore the rank and percentages. Compare the number of births to rerank. Output should go to standard out. Program 2 Write a program that reads a text file containing floating-point numbers. Allow the user to specify the source file name on...

  • C++ Create an application that searches a file of male and female first names. A link...

    C++ Create an application that searches a file of male and female first names. A link to the file is provided on the class webpage. "FirstNames2015.txt" is a list of the most popular baby names in the United States and was provided by the Social Security Administration. Each line in the file contains a boy's name and a girl's name. The file is space-delimited, meaning that the space character is used to separate the boy name from the girl name....

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