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

#include <stdio.h> #include <stdlib.h> #include <string.h> // declare struct Com

ID: 3569889 • Letter: #

Question

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// declare struct Company
struct Company{
    char name[100];

    char industry[100];
    double revenue;
    unsigned int employees;
    struct Company *next;
    struct Company *prev;
};

typedef struct Company Company;

// prototype
void display(Company *head, Company *tail);
void addCompany(Company *head, Company *tail, Company *cur);

int main(void){
    // create an empty list
    Company *head = (Company *)malloc(sizeof(Company));   
    Company *tail = (Company *)malloc(sizeof(Company));
    head->next = tail;
    tail->prev = head;

    int flag, choice, revenue, employees;
    char name[100]={''};
    char industry[100] = {''};
    char unit[50] = {''};
    flag = 0;

    while(flag != -1){
       printf("Please add a company's information (press 1) or exit (press 2): ");
       scanf("%d", &choice);
       if (choice == 1){
          printf("Company name: ");
          scanf("%s", name);
          printf("Industry: ");
          scanf("%s", industry);
          printf("Revenue(USD billions): ");
          scanf("%d", &revenue);
          printf("The number of employees: ") ;
          scanf("%d", &employees);

          // TODO: save the information that typed from the user and
          // call your function addCompany to add a node to the linked
          // list of companies
              

       }else if(choice == 2){
          flag = -1;
          display(head, tail);
       }
    }  


}


// display all companies in the linked list
void display(Company *head, Company *tail){
    printf(" The list of companies: ");
    Company *cur = head;
    while(cur->next != tail){
        cur = cur->next;
        printf("Company: %s Industry: %s Revenue(USD billions): %lf Employees: %d ", cur->name, cur->industry, cur->revenue, cur->employees);
        printf(" ");
    }  

}


// add a company information to the linked list
// hint: in main(), you should malloc memory to
//       save the user's input information in Company
//       struct. You declare a pointer to refer to the address
//       of the malloc memory and pass it to function addCompany().
void addCompany(Company *head, Company *tail, Company *cur){
    // TODO: put your code here

}

Explanation / Answer

#include<stdio.h>

#include<conio.h>

void main() {

  struct student {

     char name[30];

     char sex;

     int rollno;

     float percentage;

  };

  union details {

     struct student st;

  };

  union details set;

  printf("Enter details:");

  printf(" Enter name : ");

  scanf("%s", set.st.name);

  printf(" Enter roll no : ");

  scanf("%d", &set.st.rollno);

  flushall();

  printf(" Enter sex : ");

  scanf("%c", &set.st.sex);

  printf(" Enter percentage :");

  scanf("%f", &set.st.percentage);

  printf(" The student details are : ");

  printf(" ame : %s", set.st.name);

  printf(" Rollno : %d", set.st.rollno);

  printf(" Sex : %c", set.st.sex);

  printf(" Percentage : %f", set.st.percentage);

  getch();