Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- struct school {
- char name[40];
- int roll;
- double marks;
- };
- struct school student[50];
- int number = 0;
- void insert() {
- printf("Enter student's number:\n");
- scanf("%d", &number);
- for (int i = 0; i < number; i++) {
- printf("Enter student's name:\n");
- fflush(stdin);
- gets(student[i].name);
- fflush(stdout);
- printf("Enter student's roll\n");
- scanf("%d", &student[i].roll);
- printf("Enter student's marks:\n");
- scanf("%lf", &student[i].marks);
- }
- }
- void display() {
- if(number == 0) {
- printf("Please insert the value first!\n");
- } else {
- for (int i = 0; i < number; i++) {
- printf("Name: %s\n", student[i].name);
- printf("Roll: %d\n", student[i].roll);
- printf("Marks: %.2lf\n\n", student[i].marks);
- }
- }
- }
- void search() {
- if(number == 0) {
- printf("Please insert the value first!\n");
- } else {
- int value, flag = 1;
- printf("Enter the roll number\n");
- scanf("%d", &value);
- // Search Operation
- for (int i = 0; i < number; i++) {
- if(value == student[i].roll) {
- printf("Name: %s\n", student[i].name);
- printf("Roll: %d\n", student[i].roll);
- printf("Marks: %.2lf\n", student[i].marks);
- flag = 0;
- }
- }
- if(flag == 1) {
- printf("Roll number doesn't exist\n");
- }
- }
- }
- int main() {
- printf("Welcome to our project!\n");
- while(1) {
- printf("Main Menu:\n");
- printf("1. Insert\n");
- printf("2. Display\n");
- printf("3. Search\n");
- printf("4. Exit\n");
- int choise;
- printf("Enter your choise:\n");
- scanf("%d", &choise);
- if(choise == 1) {
- insert();
- } else if (choise == 2) {
- display();
- } else if (choise == 3) {
- search();
- } else if (choise == 4) {
- break;
- } else {
- printf("\nWrong Input\nYou have to choose between 1 - 3\n\n");
- }
- }
- }
- /*
- Project Submission Date:
- Structure
- -> insert
- -> query
- -> update
- -> delete (optional)
- File -> (optional) // (Bonus!)
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement