Question

Write a menu driven program to create a linked list of a class of students and...

Write a menu driven program to create a linked list of a class of students and perform the following
operations:
a. Write out the contents of the list

b. Edit the details pf a specified student

c. Count the number of students above 21 years and 55 kg weight

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C CODE:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct Student
{
char name[20];
int weight;
int age;
struct Student *next;
};
struct Student *insert(struct Student *head,char n[20],int w,int a)
{
struct Student *newnode=(struct Student *)malloc(sizeof(struct Student));
strcpy(newnode->name,n);
newnode->weight=w;
newnode->age=a;
newnode->next=NULL;
if(head==NULL)
{
head=newnode;
return head;
}
struct Student *temp=head;
while(temp->next!=NULL)
temp=temp->next;
temp->next=newnode;
return head;
};
void print(struct Student *head)
{
struct Student *temp=head;
while(temp!=NULL)
{
printf("Name: %s Weight: %d Age: %d\n",temp->name,temp->weight,temp->age);
temp=temp->next;
}
}
struct Student *edit(struct Student *head)
{
printf("Enter name of student to edit: ");
char n[20];
scanf("%s",n);
struct Student *p;
p=head;
int f=0;
while(p!=NULL)
{
if(strcmp(p->name,n)==0)
{
f=1;
break;
}
p=p->next;
}
if(f==0)
printf("Student not found\n");
else
{
printf("Enter new name: ");
char m[20];
scanf("%s",m);
printf("Enter new age: ");
int a;
scanf("%d",&a);
printf("Enter new weight: ");
int w;
scanf("%d",&w);
strcpy(p->name,m);
p->age=a;
p->weight=w;
}
return head;
}
void count(struct Student *head)
{
struct Student *p=head;
int count=0;
while(p!=NULL)
{
if(p->age>21&&p->weight>55)
count++;
p=p->next;
}
printf("Total Students above 21 years age and 55 kg weight: %d\n",count);
}
int main()
{
struct Student *head =NULL;
head=insert(head,"John",60,22);
head=insert(head,"David",70,21);
head=insert(head,"Jonny",54,22);
while(1)
{
printf("1: Print List\n");
printf("2: Edit List\n");
printf("3: Count students above 21 years age and 55 kg weight\n");
printf("4: Exit\n");
printf("Enter choice: ");
int n;
scanf("%d",&n);
if(n==1)
print(head);
else if(n==2)
head=edit(head);
else if(n==3)
count(head);
else if(n==4)
break;
else
printf("Wrong choice\n");
}
return 0;
}

Output:

Add a comment
Know the answer?
Add Answer to:
Write a menu driven program to create a linked list of a class of students and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Assignment Write a menu-driven C++ program to manage a class roster of student names that can...

    Assignment Write a menu-driven C++ program to manage a class roster of student names that can grow and shrink dynamically. It should work something like this (user input highlighted in blue): Array size: 0, capacity: 2 MENU A Add a student D Delete a student L List all students Q Quit ...your choice: a[ENTER] Enter the student name to add: Jonas-Gunnar Iversen[ENTER] Array size: 1, capacity: 2 MENU A Add a student D Delete a student L List all students...

  • Write a menu-driven C++ program to manage a class roster of student names that can grow...

    Write a menu-driven C++ program to manage a class roster of student names that can grow and shrink dynamically. It should work something like this (user input highlighted in blue): Array size: 0, capacity: 2 MENU A Add a student D Delete a student L List all students Q Quit ...your choice: a[ENTER] Enter the student name to add: Jonas-Gunnar Iversen[ENTER] Array size: 1, capacity: 2 MENU A Add a student D Delete a student L List all students Q...

  • Create a linked list with the following features. A Node class that stores the data type...

    Create a linked list with the following features. A Node class that stores the data type of your choice. A constructor that creates a dummy header node. void display() -- A method for printing the list. void add(item) -- A method for adding a value to the beginning of the list void addEnd(item) -- A method of adding a value to the end of the list. bool contains(item) -- A method for finding a specified value in the list. int...

  • Write a c/c++ program to read a list of students from a file and create a...

    Write a c/c++ program to read a list of students from a file and create a list. The program should use a linked list for implementation. Each node in the linked list should have the student’s name, a pointer to the next student, and a pointer to a linked list of scores. There may be up to four scores for each student.

  • At this time, you need to create menu driven program. The menu includes the following list....

    At this time, you need to create menu driven program. The menu includes the following list. The menu should keep showing if a wrong choice is selected until one of the choices of 1 to 4 is selected. After each of the options 1 to 3 is done, the program shows the menu and waits for the user's choice. Upload your code here. 1. Add odd numbers from a to b 2. Add even numbers from a to b 3....

  • C++ Data Structure Write a program to read a list of students from a file and...

    C++ Data Structure Write a program to read a list of students from a file and create a list. The program should use a linked list for implementation. Each node in the linked list should have the student’s name, a pointer to the next student, and a pointer to a linked list of scores. There may be up to four scores for each student.

  • In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, t...

    In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, then present a menu to the user, and at the end print a final report shown below. You may(should) use the structures you developed for the previous assignment to make it easier to complete this assignment, but it is not required. Required Menu Operations are: Read Students’ data from a file to update the list (refer to sample...

  • Linked List in Java The data node should be modeled somewhat like this: class node{ int...

    Linked List in Java The data node should be modeled somewhat like this: class node{ int node iNum; node next; } Write a program that creates a linked list and loads it with the numbers 0 to 9. Start with an empty list and then use a "for loop" to fill it. Create a linked list class, a node class, etc. Routines like makeNode and findTail should be methods in the linked list class. Create a showList function to display...

  • please make sure rubics Program Specifications: Write a C++ program to manage a list of students...

    please make sure rubics Program Specifications: Write a C++ program to manage a list of students waiting to register for a course using a linked list. Operations should include adding a new student at the end of the list, adding a new student at the beginning of the list, removing a student from the beginning of the list, removing a student from the end of the list, and removing a student by name. Allow the user an option to exit....

  • In Java: Develop a simple class for a Student. Include class variables; StudentID (int), FirstName, LastName,...

    In Java: Develop a simple class for a Student. Include class variables; StudentID (int), FirstName, LastName, GPA (double), and Major. Extend your class for a Student to include classes for Graduate and Undergraduate. o Include a default constructor, a constructor that accepts the above information, and a method that prints out the contents FOR EACH LEVEL of the object, and a method that prints out the contents of the object. o Write a program that uses an array of Students...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT