Question

In: Computer Science

1. To understand the value of records in a programming language, write a small program in...

1. To understand the value of records in a programming language, write a small program in a C-based language that uses an array of structs that store student information, including name, age, GPA as a float, and grade level as a string (e.g., “freshmen, junior, senior” etc.). Also, write the same program in the same language without using structs.

Note: Code and with output screenshots

Solutions

Expert Solution

#include<stdio.h>
#include<string.h>
//struct to store student info
struct student
{
   char name[20];
   int age;
   float GPA;
   char grade_level[20];  
};
int main()
{
   //now creating array of structs to store student data;
   struct student s[2];//to store two student details
   strcpy(s[0].name,"Surya");
   s[0].age=24;
   s[0].GPA=8;
   strcpy(s[0].grade_level,"Senior");
   strcpy(s[1].name,"Gopi");
   s[1].age=23;
   s[1].GPA=7;
   strcpy(s[1].grade_level,"Junior");
   //displaying output
   printf("Using structs\n");
   for(int i=0;i<2;i++)
   {
       printf("Student %d details",i+1);  
       printf("Name:%s\nAge:%d\nGPA:%f\nGrade_level:%s\n",s[i].name,s[i].age,s[i].GPA,s[i].grade_level);
   }
  
   //now with out using structs
   char name[2][20];
   int age[2];
   float GPA[2];
   char grade_level[2][20];
   //storing data
  
   strcpy(name[0],"Surya");
   age[0]=24;
   GPA[0]=8;
   strcpy(grade_level[0],"Senior");
   strcpy(name[1],"Gopi");
   age[1]=23;
   GPA[1]=7;
   strcpy(grade_level[1],"Junior");
  
   //displaying output
   printf("Without using structs\n");
       for(int i=0;i<2;i++)
   {
       printf("Student %d details",i+1);  
       printf("Name:%s\nAge:%d\nGPA:%f\nGrade_level:%s\n",name[i],age[i],GPA[i],grade_level[i]);
   }
  
   return 0;
}

output:


Related Solutions

GPA calculator in C language To understand the value of records in a programming language, write...
GPA calculator in C language To understand the value of records in a programming language, write a small program in a C-based language that uses an array of structs that store student information, including name, age, GPA as a float, and grade level as a string (e.g., “freshmen,” etc.). Note:Code and Output Screenshots
LISP Programming Language Write a Bubble Sort program in the LISP Programming Language called “sort” that...
LISP Programming Language Write a Bubble Sort program in the LISP Programming Language called “sort” that sorts the array below in ascending order.  LISP is a recursive language so the program will use recursion to sort. Since there will be no loops, you will not need the variables i, j, and temp, but still use the variable name array for the array to be sorted.             Array to be sorted is 34, 56, 4, 10, 77, 51, 93, 30, 5, 52 The...
Programming Language C++ Task 1: Write a program to calculate the volume of various containers. A...
Programming Language C++ Task 1: Write a program to calculate the volume of various containers. A base class, Cylinder, will be created, with its derived classes, also called child classes or sub-classes. First, create a parent class, Cylinder. Create a constant for pi since you will need this for any non-square containers. Use protected for the members. Finally, create a public function that sets the volume. // The formula is: V = pi * (r^2) * h Task 2: Create...
In programming C language, write a program that creates a binary tree of words to be...
In programming C language, write a program that creates a binary tree of words to be used as a spell checking device for various text files. The list of words will come from a file “words.txt”. Your program is to read through the “words.txt” file and insert the word on that line into the tree in lexicographic order (also known as Dictionary order). Words in the file will be separated by spaces. Once this is done, your program should then...
In programming C language, write a program that creates a binary tree of words to be...
In programming C language, write a program that creates a binary tree of words to be used as a spell checking device for various text files. The list of words will come from a file “words.txt”. Your program is to read through the “words.txt” file and insert the word on that line into the tree in lexicographic order (also known as Dictionary order). Words in the file will be separated by spaces. Once this is done, your program should then...
Lab 1 Write a program in the C/C++ programming language to input and add two fractions...
Lab 1 Write a program in the C/C++ programming language to input and add two fractions each represented as a numerator and denominator. Do not use classes or structures. Print your result (which is also represented as a numerator/denominator) to standard out. If you get done early, try to simplify your result with the least common denominator. The following equation can be used to add fractions: a/b + c/d = (a*d + b*c)/(b*d) Example: 1/2 + 1/4 = ( 1(4)...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user to enter the three examinations ( test 1, test 2, and test 3), homework, and final project grades then calculate and display the overall grade along with a message, using the selection structure (if/else). The message is based on the following criteria: “Excellent” if the overall grade is 90 or more. “Good” if the overall grade is between 80 and 90 ( not including...
C++ programming language. Write a program that will read in id numbers and place them in...
C++ programming language. Write a program that will read in id numbers and place them in an array.The array is dynamically allocated large enough to hold the number of id numbers given by the user. The program will then input an id and call a function to search for that id in the array. It will print whether the id is in the array or not. Sample Run: Please input the number of id numbers to be read 4 Please...
In C Programming Language Write a program to output to a text log file a new...
In C Programming Language Write a program to output to a text log file a new line starting with day time date followed by the message "SUCCESSFUL". Please screenshot the results.
In C programming language, write the program "3x3" in size, calculating the matrix "c = a...
In C programming language, write the program "3x3" in size, calculating the matrix "c = a * b" by reading the a and b matrices from the outside and writing on the screen?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT