[go: up one dir, main page]

0% found this document useful (0 votes)
13 views6 pages

Extension

Uploaded by

velshakthi406
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views6 pages

Extension

Uploaded by

velshakthi406
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

#include <stdio.

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

typedef struct list {


int regno;
char name[50];
int sem;
char course[10];
oat marks;
struct list *next;
struct list *pre;
} LIST;

LIST *p, *t, *h;


int j, pos, count;

// Function prototypes
void create(void);
void inse (void);
void delet(void);
void display(void);
void failed_students(void);
void passed_count_each_course(void);
void topper_each_course(void);

void main()
{
int n, i = 1, opt;
p = NULL;

prin ("Enter the number of students: ");


scanf("%d", &n);
count = n;

while (i <= n) {
create();
i++;
}

prin ("\nMenu:\n");
prin ("1. Inse \n2. Delete\n3. Display\n4. Failed Students in a Course\n");
prin ("5. Passed Count in Each Course\n6. Topper in Each Course\n7. Exit\n");

do {
prin ("\nEnter option: ");
scanf("%d", &opt);
switch (opt) {
case 1: inse (); count++; break;
case 2: delet(); count--; if (count == 0) prin ("\nList is empty\n"); break;
case 3: display(); break;
case 4: failed_students(); break;
case 5: passed_count_each_course(); break;
case 6: topper_each_course(); break;
}
} while (opt != 7);

getch();
}

void create()
{
if (p == NULL) {
p = (LIST*) malloc(sizeof(LIST));
prin ("Enter Reg No: "); scanf("%d", &p->regno);
prin ("Enter Name: "); scanf("%s", p->name);
prin ("Enter Sem: "); scanf("%d", &p->sem);
prin ("Enter Course Code: "); scanf("%s", p->course);
prin ("Enter Marks: "); scanf("%f", &p->marks);
p->next = NULL;
p->pre = NULL;
h = p;
} else {
t = (LIST*) malloc(sizeof(LIST));
prin ("Enter Reg No: "); scanf("%d", &t->regno);
prin ("Enter Name: "); scanf("%s", t->name);
prin ("Enter Sem: "); scanf("%d", &t->sem);
prin ("Enter Course Code: "); scanf("%s", t->course);
prin ("Enter Marks: "); scanf("%f", &t->marks);
t->next = NULL;
p->next = t;
t->pre = p;
p = t;
}
}

void inse ()
{
t = h;
p = (LIST*) malloc(sizeof(LIST));
prin ("Enter Reg No: "); scanf("%d", &p->regno);
prin ("Enter Name: "); scanf("%s", p->name);
prin ("Enter Sem: "); scanf("%d", &p->sem);
prin ("Enter Course Code: "); scanf("%s", p->course);
prin ("Enter Marks: "); scanf("%f", &p->marks);
prin ("Enter the position to inse : ");
scanf("%d", &pos);

if (pos == 1) {
p->next = t;
if (t != NULL) t->pre = p;
h = p;
h->pre = NULL;
} else {
for (j = 1; j < (pos - 1) && t->next != NULL; j++)
t = t->next;
p->next = t->next;
if (t->next != NULL) t->next->pre = p;
t->next = p;
p->pre = t;
}
}
void delet()
{
prin ("Enter the position to delete: ");
scanf("%d", &pos);

if (pos == 1) {
h = h->next;
if (h != NULL) h->pre = NULL;
} else {
t = h;
for (j = 1; j < pos && t != NULL; j++)
t = t->next;
if (t != NULL) {
p = t;
if (t->next != NULL) t->next->pre = t->pre;
t->pre->next = t->next;
free(p);
}
}
}

void display()
{
t = h;
prin ("\n%-10s %-15s %-5s %-10s %-6s\n", "RegNo", "Name", "Sem", "Course",
"Marks");
while (t != NULL) {
prin ("%-10d %-15s %-5d %-10s %-6.2f\n", t->regno, t->name, t->sem, t->course,
t->marks);
t = t->next;
}
}

void failed_students()
{
char code[10];
prin ("Enter Course Code: ");
scanf("%s", code);
t = h;
prin ("Failed Students in %s:\n", code);
while (t != NULL) {
if (strcmp(t->course, code) == 0 && t->marks < 40)
prin ("%d\n", t->regno);
t = t->next;
}
}

void passed_count_each_course()
{
char course_list[100][10];
int pass_count[100] = {0};
int ccount = 0, i, found;
t = h;

while (t != NULL) {
found = 0;
for (i = 0; i < ccount; i++) {
if (strcmp(course_list[i], t->course) == 0) {
if (t->marks >= 40) pass_count[i]++;
found = 1;
break;
}
}
if (!found) {
strcpy(course_list[ccount], t->course);
pass_count[ccount] = (t->marks >= 40) ? 1 : 0;
ccount++;
}
t = t->next;
}

prin ("\nPass Count per Course:\n");


for (i = 0; i < ccount; i++) {
prin ("%s: %d passed\n", course_list[i], pass_count[i]);
}
}
void topper_each_course()
{
char course_list[100][10];
oat top_marks[100] = {0};
int topper_reg[100];
int ccount = 0, i, found;
t = h;

while (t != NULL) {
found = 0;
for (i = 0; i < ccount; i++) {
if (strcmp(course_list[i], t->course) == 0) {
if (t->marks > top_marks[i]) {
top_marks[i] = t->marks;
topper_reg[i] = t->regno;
}
found = 1;
break;
}
}
if (!found) {
strcpy(course_list[ccount], t->course);
top_marks[ccount] = t->marks;
topper_reg[ccount] = t->regno;
ccount++;
}
t = t->next;
}

prin ("\nTopper in Each Course:\n");


for (i = 0; i < ccount; i++) {
prin ("%s: RegNo %d with %.2f marks\n", course_list[i], topper_reg[i], top_marks[i]);
}
}

You might also like