Question

In: Computer Science

Using Union technique, define two structs employee_record and student_record. The employee_record struct will contain the name...

Using Union technique, define two structs employee_record and student_record. The employee_record struct will contain the name (size 50) and the salary (double) of an employee. The student_record struct will have the name (size 30), Id number (int) of a student, and the grade (int). Include these two structs in a union called 'person'. Using file redirection called input.txt, at first, ask the user for the employee's information and print them from the main() and the size of the union. Then ask the user for the student's information, then check the grade if it is equal or greater than 90; if yes, print all info, the size of the union, and print "Well done" otherwise print "Keep working" with all info.

Solutions

Expert Solution

The c program developed using Standard input for union and structure for employee and student.

for redirected input file use command :

% a.out < input.txt

#include <stdio.h>

//union inside 2 structure employee_record and student_record
union Person{
    struct employee_record
    {
        char name[50];
        double salary;
    }e;
    
    struct student_record
    {
        char name[30];
        int Id;
        int grade;
    }s;
};

// main code
int main()
{
    union Person P;    // assign P as union variable 
    
    printf("Enter the name of Employee: ");
    scanf("%s",P.e.name);
    printf("Enter the salary of Employee: ");
    scanf("%lf",&P.e.salary);
    
    printf( "\nEmployee Name : %s \nEmployee Salary : %lf\n", P.e.name,P.e.salary);
    printf( "\nMemory size occupied by data : %lu \n", sizeof(P));

    printf("\nEnter the name of Student: ");
    scanf("%s",P.s.name);
    printf("Enter the ID of student: ");
    scanf("%d",&P.s.Id);
    printf("Enter the grade of student: ");
    scanf("%d",&P.s.grade);

    printf( "\nStudent Name : %s \nStudent ID : %d", P.s.name,P.s.Id);
    printf( "\nMemory size occupied by data : %lu \n", sizeof(P));
    
    if(P.s.grade >= 90){
        printf("\nWell done");
    }
    else{
        printf("\nKeep working");
    }
    
    
    return 0;
}

Output:


Related Solutions

The task is to sort structs in array. The struct is struct coor{ int x; int...
The task is to sort structs in array. The struct is struct coor{ int x; int y; int z; }; Create an array with 100 coordinates, which are randomly initiated with x between 0 and 30 and y between 5 and 60, and z between 10 and 90. Then modify the Quick Sort algorithm (QuickSort.cpp) to sort coordinated. Comparison of the coordinates should be carried on first x, then y, and z last. It means that if two points has...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to create an array of structs Program Specifications: DESIGN and IMPLEMENT a program that will CREATE and use three different variables of type PERSON. Create a struct using the typedef command for a DATE. Create a struct for a PERSON with the following fields. name [this will be a string] birthdate [this will be a DATE] gender [this will be a char] annualIncome [this will...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to create an array of structs Program Specifications: DESIGN and IMPLEMENT a program that will CREATE and use three different variables of type PERSON. Create a struct using the typedef command for a DATE. Create a struct for a PERSON with the following fields. name [this will be a string] birthdate [this will be a DATE] gender [this will be a char] annualIncome [this will...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to create an array of structs Program Specifications: DESIGN and IMPLEMENT a program that will CREATE and use three different variables of type PERSON. Create a struct using the typedef command for a DATE. Create a struct for a PERSON with the following fields. name [this will be a string] birthdate [this will be a DATE] gender [this will be a char] annualIncome [this will...
2. Define and show using Venn diagrams, the following: 2.1 The union of two events. 2.2...
2. Define and show using Venn diagrams, the following: 2.1 The union of two events. 2.2 The intersection of two events. 2.3 The complement of an event in a sample space. 3. Write some limitations of Venn diagrams as discussed in the class.
For a supermarket, define a Inventory class. All the Inventory objects will contain S,No, name of...
For a supermarket, define a Inventory class. All the Inventory objects will contain S,No, name of clerk preparing the inventory, each item with id, quantity available , minimum order quantity ,price and date of expiry. There is an array to describe the above details. Your program generate the stock based on the items quantity is equal to minimum order quantity or less than minimum order quantity and also display items to check date of expiry with current date.
list.h file #ifndef LIST_H_ #define LIST_H_ struct ListNode { long value; struct ListNode *next; }; struct...
list.h file #ifndef LIST_H_ #define LIST_H_ struct ListNode { long value; struct ListNode *next; }; struct ListNode *list_prepend(struct ListNode *list, long value); int list_length(struct ListNode *list); struct ListNode *list_remove(struct ListNode *list, long value); #endif /* LIST_H_ */ given.c file #include #include "list.h" struct ListNode *list_prepend(struct ListNode *list, long value) { struct ListNode *node = malloc(sizeof(struct ListNode)); node->value = value; node->next = list; return node; } list.c file #include #include "list.h" /* Counts and returns the number of nodes in the...
declare a struct named matrix and typedef the struct to type name Matrix. A mathematical matrix...
declare a struct named matrix and typedef the struct to type name Matrix. A mathematical matrix is a two-dimensional, rectangular data structure. The matrix struct should have three fields (in this order): an unsigned variable named "rows", an unsigned variable named "columns", and a pointer to a pointer to double (i.e. double**) named "data". (Code #including matrix.h should be able to declare Matrix variables.) In matrix.c, implement the create_matrix function. The Matrix should be filled with 0.0 values. data[i] should...
Define a struct pet with properties name, age, weight, and type. Use appropriate data types for the different properties.
use C source code to complete the following:Define a struct pet with properties name, age, weight, and type. Use appropriate data types for the different properties. You may assume that the strings will never be longer than 19 chars. Don’t forget to add an extra char for the NULL character that terminates the strings.
Experiment 7: Thin Layer Chromatography What is the name of the technique you will be using...
Experiment 7: Thin Layer Chromatography What is the name of the technique you will be using in experiment No.7 lab? Thin Layer Chromatography Mass Spectrometry Thick Liquid Calorimetry Liquid Chamber Chromatography TLC plates separate molecules on the basis of: Polarity Color Size Bond orientation The mixture is dissolved in a fluid called the ___________ phase, which carries it through   a structure holding another material called the __________ phase. The polarity of a bond between two elements can be best determined...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT