c语言管理系统设计源代码
以下是一个简单的C语言管理系统示例,用于管理学生信息。该系统可以添加、删除、修改和查学生信息。
c复制代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student {
char name[50];
int roll;
float marks;
};
struct student students[100];
int count = 0exited;
void add_student() {
struct student new_student;
printf("Enter name: ");
scanf("%s", new_student.name);
printf("Enter roll number: ");
scanf("%d", &ll);
printf("Enter marks: ");
scanf("%f", &new_student.marks);
students[count] = new_student;
count++;
}
void delete_student() {
int index;
printf("Enter index of student to delete: ");
scanf("%d", &index);
for (int i = index; i < count - 1; i++) {
students[i] = students[i + 1];
}
count--;
}
void modify_student() {
int index;
struct student new_student;
printf("Enter index of student to modify: ");
scanf("%d", &index);
printf("Enter new name: ");
scanf("%s", new_student.name);
printf("Enter new roll number: ");
scanf("%d", &ll);
printf("Enter new marks: ");
scanf("%f", &new_student.marks);
students[index] = new_student;
}
void find_student() {
char name[50];
printf("Enter name of student to find: ");
scanf("%s", name);
for (int i = 0; i < count; i++) {
if (strcmp(students[i].name, name) == 0) {
printf("Roll number: %d\n", students[i].roll);
printf("Marks: %.2f\n", students[i].marks);
return;
}
}
printf("Student not found.\n");
}
int main() {
int choice;
do {
printf("\nMenu:\n");
printf("1. Add student\n");
printf("2. Delete student\n");
printf("3. Modify student\n");
printf("4. Find student\n");
printf("5. Exit\n");
printf("Enter choice: ");
scanf("%d", &choice);
switch (choice) {
case 1: add_student(); break;
case 2: delete_student(); break;
case 3: modify_student(); break;
case 4: find_student(); break;
case 5: exit(0); break; // exit the program here, otherwise the loop will keep running indefinitely, as it is in the do-while loop above. We are not returning, but rather exiting the program completely, so we do not need to return anything. The return value of main is always 0, and this is how the program exits. If you want to return a value other than 0, you can do so like this: return 1; or return -1; or return any other integer value you want to represent an error condition. The operating system will interpret this as the program's exit status. In this case, it will be seen as successful, as it is returning 0. The return value of main is not used for anything in this program, but it can be used in other programs to determine whether the program exited successfully or with an error. For example, if you were writing a shell script that executed this program and needed to know if it was successful or not, you could check the return value of the program and act accordingly. This is a common practice in programming, and it is important to understand how it works so that you can use it effectively in your own programs.

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。