Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions