0% found this document useful (0 votes)
19 views20 pages

Assignment

Assignment

Uploaded by

khaparderahil
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)
19 views20 pages

Assignment

Assignment

Uploaded by

khaparderahil
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/ 20

Assignment

Course: C language
Name:-Rahil P Khaparde

Code:
#include <stdio.h>
#include <string.h>
Struct Student {
Char fname[50];
Char lname[50];
Int roll;
Float cgpa;
Int cid[5];
};

Struct Student st[100];


Int i = 0;

Void add_student() {
Printf(“Add the Student’s Details\n”);
Printf(“-------------------------\n”);
Printf(“Enter the first name of the
student:\n”);
Scanf(“%s”, st[i].fname);

Printf(“Enter the last name of the


student:\n”);
Scanf(“%s”, st[i].lname);

Printf(“Enter the Roll Number:\n”);


Scanf(“%d”, &st[i].roll);

Printf(“Enter the CGPA you obtained:\n”);


Scanf(“%f”, &st[i].cgpa);

Printf(“Enter the course ID of each course (5


courses):\n”);
For (int j = 0; j < 5; j++) {
Scanf(“%d”, &st[i].cid[j]);
}
I++;
Printf(“Student added successfully.\n”);
}

Void find_rl() {
Int x;
Printf(“Enter the Roll Number of the
student:\n”);
Scanf(“%d”, &x);

Int found = 0;
For (int j = 0; j < i; j++) {
If (x == st[j].roll) {
Printf(“The Student’s Details are:\n”);
Printf(“First Name: %s\n”, st[j].fname);
Printf(“Last Name: %s\n”, st[j].lname);
Printf(“Roll Number: %d\n”, st[j].roll);
Printf(“CGPA: %.2f\n”, st[j].cgpa);
Printf(“Course Ids: “);
For (int k = 0; k < 5; k++) {
Printf(“%d “, st[j].cid[k]);
}
Printf(“\n”);
Found = 1;
Break;
}
}
If (!found) {
Printf(“Student with Roll Number %d not
found.\n”, x);
}
}

Void find_c() {
Int id;
Printf(“Enter the course ID:\n”);
Scanf(“%d”, &id);

Int found = 0;
For (int j = 0; j < i; j++) {
For (int d = 0; d < 5; d++) {
If (id == st[j].cid[d]) {
Printf(“The Student’s Details are:\n”);
Printf(“First Name: %s\n”,
st[j].fname); Printf(“Last
Name: %s\n”, st[j].lname);
Printf(“Roll Number: %d\n”,
st[j].roll);
Printf(“CGPA: %.2f\n”, st[j].cgpa);
Found = 1;
Break;
}
}
}
If
(!fo
und
){

Printf(“No students found enrolled in


course ID %d.\n”, id);
}
}

Void tot_s() {
Printf(“The total number of students is
%d\n”, i);
Printf(“You can have a maximum of 50
students.\n”);

Int remaining = 50 – i;
If (remaining > 0) {
Printf(“You can add %d more students.\n”,
remaining);
} else {
Printf(“The student limit has been reached.
You cannot add more students.\n”);
}
}

Void del_s() {
Int a;
Printf(“Enter the Roll Number which you
want to delete:\n”);
Scanf(“%d”, &a);

Int found = 0;
For (int j = 0; j < i; j++) {
If (st[j].roll == a) {
For (int k = j; k < i – 1; k++) {
St[k] = st[k + 1];
}
i--;
found = 1;
printf(“Student with Roll Number %d
has been removed successfully.\n”, a);
break;
}
}
If (!found) {
Printf(“Student with Roll Number %d not
found.\n”, a);
}
}

Void up_s() {
Int x;
Printf(“Enter the roll number to update the
entry: “);
Scanf(“%d”, &x);

Int found = 0;
For (int j = 0; j < i; j++) {
If (st[j].roll == x) {
Found = 1;
Int z;
Printf(“Select the detail to update:\n”
“1. First name\n”
“2. Last name\n”
“3. Roll number\n”
“4. CGPA\n”
“5. Courses\n”);
Scanf(“%d”, &z);

Switch (z) {
Case 1:
Printf(“Enter the new first name:
\n”);
Scanf(“%s”, st[j].fname);
Break;
Case 2:
Printf(“Enter the new last name:
\n”);
Scanf(“%s”, st[j].lname);
Break;
Case 3:
Printf(“Enter the new roll number:
\n”);
Scanf(“%d”, &st[j].roll);
Break;
Case 4:
Printf(“Enter the new CGPA: \n”);
Scanf(“%f”, &st[j].cgpa);
Break;
Case 5:
Printf(“Enter the new courses (5
course Ids): \n”);
For (int k = 0; k < 5; k++) {
Scanf(“%d”, &st[j].cid[k]);
}
Break;
Default:
Printf(“Invalid option.\n”);
Return;
}
Printf(“UPDATED
SUCCESSFULLY.\n”);
Break;
}
}
If (!found) {
Printf(“Student with Roll Number %d not
found.\n”, x);
}
}

Int main() {
Add_student();
Find_rl();
Find_c();
Tot_s();
Del_s();
Up_s();

Return 0;
}
Output:
Enter the first name of the student:
Rahil
Enter the last name of the student:
Khaparde
Enter the Roll Number:
1
Enter the CGPA you obtained:
3
Enter the course ID of each course (5
courses): 101
102
103
104
105
Student added successfully.
Enter the Roll Number of the student:
1
The Student’s Details are:
First Name: Rahil
Last Name: Khaparde
Roll Number: 1
CGPA: 3.00
Course Ids: 101 102 103 104 105 Enter
the course ID:
101
The Student’s Details are:
First Name: Rahil
Last Name: Khaparde
Roll Number: 1
CGPA: 3.00
The total number of students is 1 You
can have a maximum of 50 students.
You can add 49 more students.
Enter the Roll Number which you want
to delete:
1
Student with Roll Number 1 has been
removed successfully.
Enter the roll number to update the entry:
1
Student with Roll Number 1 not found.

You might also like