Question: Adequate facilities for defining data types and structures aids readability. E.g. Early FORTRAN had no record/struct construct, so the fields of an object could not

Adequate facilities for defining data types and structures aids readability. E.g. Early FORTRAN had no record/struct construct, so the "fields" of an "object" could not be encapsulated within a single structure (that could be referred to by one name). Later this semester, we will look at various categories of data types and look at design issues and design choices of common languages.. Records are among the simplest, most basic data structures.

2. Write the same program in the same language without using structs.

3. Submit the code and output of both programs with a brief (at least 100 words) on which program better meets readability and why (or if you believe both are equal that's ok too; be sure to justify your answer).

#include

#include

// define a struct to store student information

struct student{

// char array to store first name

char fname[20];

// char array to store last name

char lname[20];

// store age of the student

int age;

float GPA;

char grade_level[20];

};

int main()

{

int n, i;

printf("Enter the size of array ");

// scan n

scanf("%d",&n);

printf(" ");

// dynamically create an array of size n

struct student *arr = (struct student *)malloc(n * sizeof(struct student));

for( i = 0 ; i < n ; i++ )

{

printf("For student %d ... ", i + 1);

printf("Enter the name of the student ");

// scan the name of the student

scanf("%s%s",&arr[i].fname,&arr[i].lname);

printf("Enter the age of the student ");

// scan the name of the student

scanf("%d",&arr[i].age);

printf("Enter the GPA of the student ");

// scan the name of the student

scanf("%f",&arr[i].GPA);

printf("Enter the grade level of the student ");

// scan the name of the student

scanf("%s",&arr[i].grade_level);

printf(" ");

}

printf(" Student Record ... ");

for( i = 0 ; i < n ; i++ )

{

printf("For student %d ... ", i + 1);

printf("Name : %s %s ",arr[i].fname,arr[i].lname);

printf("Age : %d ",arr[i].age);

printf("GPA : %f ",arr[i].GPA);

printf("Grade Level : %s ",arr[i].grade_level);

printf(" ");

}

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!