Answer to Question #255657 in C for Neil

Question #255657

Create three structures using linked list: Student, University & Branch.

Student structure contains Name, Roll No & Branch ID [in which the student studies], University structure contains University ID & University Name) &

Branch structure contains Branch ID & Branch Name


Implement the following function to :-

  • Display the list of students reading in IIT University.
  • Display the student details who are reading at IIT University with branch CSE.
1
Expert's answer
2021-10-25T17:00:13-0400
#include<stdio.h>
#include <stdlib.h>
struct Student {
 int rollNo;
 char name[30];
 int branchID;
 double CGPA;
};




struct University{
 int uniID;
 char uniName[30];
 char location[30];
 int startYear;
 
};




struct Branch{
 int branchID;
 int uniID;
 char branchN[60];
 
};
struct Details{
 struct University U;
 struct Student X;
 struct Branch B;
 struct Details * next;
};




void push(struct Details** head)
{
 
 
 struct Details * newNode = (struct Details*)malloc(sizeof(struct Details));
 
 struct Details d;
 struct Student R;
 printf("Input student details:\n");
 printf("Input the roll no: ");
 scanf("%d",&R.rollNo);
 printf("student name: ");
 scanf("%s", &R.name);
 printf("Branch ID: ");
 scanf("%d", &R.branchID);
 printf("CGPA: ");
 scanf("%d", &R.CGPA);
 
 struct University un;
 printf("Input university details: ");
 printf("University id:");
 scanf("%d", &un.uniID);
 printf("University name: ");
 scanf("%s", &un.uniName);
 printf("University location: ");
 scanf("%s", &un.location);
 printf("Year of start: ");
 scanf("%d", &un.startYear);
 
 struct Branch br;
 printf("Input branch details:\n");
 printf("Branch id: ");
 scanf("%d", &br.branchID);
 printf("Branch name: ");
 scanf("%s", &br.branchN);
 printf("University id: ");
 scanf("%d", &br.uniID);
 newNode->U = un;
 newNode->X = R;
 newNode->B = br;
 newNode->next = (*head);
 (*head) = newNode;
}
void display(struct Details* node){
 while(node != NULL){
 
 printf("Student details are:\n");
 printf("Name: %s\n", node->X.name);
 printf("Roll No: %d\n", node->X.rollNo);
 printf("Branch ID: %d\n", node->X.branchID);
 printf("CGPA: %d\n", node->X.CGPA);
 printf("University details are:\n");
 printf("ID: %d\n", node->U.uniID);
 printf("Name: %s\n", node->U.uniName);
 printf("Location %s\n", node->U.location);
 printf("Year of start %d\n", node->U.startYear);
 printf("Branch Details:\n");
 printf("Branch ID: %d\n", node->B.branchID);
 printf("Branch Name: %s\n", node->B.branchN);
 printf("University ID: %d\n", node->B.uniID);
 node = node->next;
 }
}
int main(){
 struct Details * head = NULL;
 push(&head);
 push(&head);
 display(head);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS