Saturday, May 22, 2010

Help writing this in C language?

a) Define a struct called Student that includes an ID number (an integer), units (a double), and GPA (a double).



























































b) Declare a 30-element array of Student structs called class.





























c) Write a C statement that will print the GPA of the Student at index 14 of the class array.

















d) Write a function named inputStudent that will enter each field of a Student struct, and then return that struct.

Help writing this in C language?
whitespaces can be very confusing and annoying. I can and do annoy in the opposite way, but it's easier when we can read more than one letter without scrolling.





I'll just put in answers without checking them (on GCC which means I won't be using any nonstandard syntax like conio.h anyhow).





a.


typedef struct student{


int ID;


double units;


double GPA;


} Student;


b.


Student class[30];


c.


printf("The GPA of student 14 is %f.\n", (class[14].GPA));





d.





Student inputStudent(){


Student temp;


int identification;


double Units, Average;





printf("Enter Student ID:");


scanf("%d", %26amp;identification);


printf("Enter Student Units:")


scanf("%f", %26amp;Units);


printf("Enter Student GPA:");


scanf("%f", %26amp;Average);





temp.id=identification;


temp.units=Units;


temp.GPA=Average;





return temp;


}





call with class[i]=inputStudent();

floral design

No comments:

Post a Comment