Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- struct school {
- char name[100];
- int roll;
- double marks;
- };
- struct school student[100];
- int size = 0;
- void menu() {
- printf("Main Menu\n");
- printf("1. Insert\n");
- printf("2. Display\n");
- printf("3. Search\n");
- printf("4. Update\n");
- printf("5. Exit\n");
- }
- void insert() {
- printf("How many students do you have?\n");
- scanf("%d", &size);
- for (int i = 0; i < size; i++) {
- printf("Enter student's name:\n");
- fflush(stdin);
- gets(student[i].name);
- fflush(stdout);
- printf("Enter student's roll no:\n");
- scanf("%d", &student[i].roll);
- printf("Enter student's total marks:\n");
- scanf("%lf", &student[i].marks);
- }
- }
- void display() {
- if (size == 0) {
- printf("Array is empty\n\n");
- } else {
- printf("Student's Information\n");
- for (int i = 0; i < size; i++) {
- printf("Name: %s\t", student[i].name);
- printf("Roll: %d\t", student[i].roll);
- printf("Marks: %.2lf\n", student[i].marks);
- }
- printf("\n");
- }
- }
- void search() {
- if (size == 0) {
- printf("Array is empty\n\n");
- } else {
- int temp;
- printf("Enter studen't roll no:\n");
- scanf("%d", &temp);
- int flag = 1;
- for (int i = 0; i < size; i++) {
- if (student[i].roll == temp) {
- printf("Name: %s\t", student[i].name);
- printf("Roll: %d\t", student[i].roll);
- printf("Marks: %.2lf\n", student[i].marks);
- flag = 0;
- }
- }
- if (flag == 1) {
- printf("Invalid Information\n\n");
- }
- }
- }
- void update() {
- if (size == 0) {
- printf("Array is empty\n\n");
- } else {
- int temp;
- printf("Enter studen't roll no:\n");
- scanf("%d", &temp);
- int flag = 1;
- for (int i = 0; i < size; i++) {
- if (student[i].roll == temp) {
- double value;
- printf("Enter the updated marks:\n");
- scanf("%lf", &value);
- student[i].marks = value;
- flag = 0;
- }
- }
- if (flag == 1) {
- printf("Invalid Information\n\n");
- }
- }
- }
- int main() {
- printf("Student Mangement System\n");
- while (1) {
- int choice;
- menu();
- printf("Enter your choice\n");
- scanf("%d", &choice);
- if (choice == 1) {
- insert();
- } else if (choice == 2) {
- display();
- } else if (choice == 3) {
- search();
- } else if (choice == 4) {
- update();
- } else if (choice == 5) {
- break;
- } else {
- printf("Invalid Information\n\n");
- }
- }
- }
- /*
- Project Submission Date: April -> 24
- Structure
- -> insert
- -> Search
- -> update
- -> delete (optional)
- File -> (optional) // (Bonus!)
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement