Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write The program in Clanguage please exucute it in visual studio do the codeing

ID: 3670525 • Letter: W

Question

Write The program in Clanguage please exucute it in visual studio do the codeing in visualstudio

1) Create a Structure named employee with name, id, salary and department. Create two variables of employee type and assign values to the data members and then print all the data members. Write a sum() function which is going to take two structure variables and calculate the sum of salary of two employees. Print the sum of salary.

2) Change the above structure to union and then perform the above task

. 3) Print how many bytes are assigned for above structure and also the union?

4) Declare and initialize two character variables with values ‘d’ and ‘z’ and calculate the sum of these variables and explain whether it is implicit type casting or explicit type casting.

5) Pass two command line arguments { ‘Sam’, ‘John’} and print those two arguments onto the screen and print the total number of arguments and also what will be the first command line argument and print that first argument.

Explanation / Answer

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct Employee Employee;
struct Employee
{
int id;
float salary;
char department[20];
}e1,e2;

float sum(Employee e1,Employee e2)
{
    float sum;
    sum=e1.salary+e2.salary;
    return sum;
}

int main(int argc,char **argv)
{
printf("size of the Structure is is %d",sizeof(e1));
e1.id=1;
e1.salary=10050.45;
strcpy(e1.department,"Support");

e2.id=2;
e2.salary=12350.45;
strcpy(e2.department,"Production");

printf(" Details of Employee 1 ");
printf("Id is %d Salary is %f Department is %s ",e1.id,e1.salary,e1.department);
printf(" ");

printf(" Details of Employee 2 ");
printf("Id is %d Salary is %f Department is %s ",e2.id,e2.salary,e2.department);

printf(" The sum of the salaries of the given two employees is ");
printf("%.2f ",sum(e1,e2));

printf(" Character Declaration part ");
char a='d';
char b='z';
char c=a+b;
printf("The resulting character is ");
printf("%d",c);
printf(" This character addition is alll implicit casting........ ");


printf(" The given command line arguments are........ ");
printf(" %s",argv[1]);
printf(" %s",argv[2]);

printf("The first command line arugemnt will be the name of the c executable.....which is ");
printf("%s",argv[0]);

return 0;
}

----------------------------------------------------------------------

//This is by using the union in place of the structure.

/*

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef union Employee Employee;
union Employee
{
int id;
float salary;
char department[20];
}e1,e2;

float sum(Employee e1,Employee e2)
{
    float sum;
    sum=e1.salary+e2.salary;
    return sum;
}

int main()
{
printf("size of the union is %d",sizeof(e1));
e1.id=1;
e1.salary=10050.45;
strcpy(e1.department,"Support");

e2.id=2;
e2.salary=12350.45;
strcpy(e2.department,"Production");

printf(" Details of Employee 1 ");
printf("Id is %d Salary is %f Department is %s ",e1.id,e1.salary,e1.department);
printf(" ");

printf(" Details of Employee 2 ");
printf("Id is %d Salary is %f Department is %s ",e2.id,e2.salary,e2.department);

printf(" The sum of the salaries of the given two employees is ");
printf("%.2f ",sum(e1,e2));


return 0;
}
*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote