#include "stdioh"
/定义学生结构体/
struct Student
{
char ID[20];
char Name[20];
float Mark1;
float Mark2;
float Mark3;
float Average;
};
/声明学生数组及学生数量/
struct Student students[1000];
int num=0;
/求平均值/
float Avg(struct Student stu)
{
return (stuMark1+stuMark2+stuMark3)/3;
}
/通过学号返回数组下标/
int Student_SearchByIndex(char id[])
{
int i;
for (i=0;i<num;i++)
{
if (strcmp(students[i]ID,id)==0)
{
return i;
}
}
return -1;
}
/通过姓名返回数组下标/
int Student_SearchByName(char name[])
{
int i;
for (i=0;i<num;i++)
{
if (strcmp(students[i]Name,name)==0)
{
return i;
}
}
return -1;
}
/显示单条学生记录/
void Student_DisplaySingle(int index)
{
printf("%10s%10s%8s%8s%8s%10s\n","学号","姓名","成绩","成绩","成绩","平均成绩");
printf("-------------------------------------------------------------\n");
printf("%10s%10s%82f%82f%82f%102f\n",students[index]ID,students[index]Name,
students[index]Mark1,students[index]Mark2,students[index]Mark3,students[index]Average);
}
/插入学生信息/
void Student_Insert()
{
while(1)
{
printf("请输入学号:");
scanf("%s",&students[num]ID);
getchar();
printf("请输入姓名:");
scanf("%s",&students[num]Name);
getchar();
printf("请输入成绩:");
scanf("%f",&students[num]Mark1);
getchar();
printf("请输入成绩:");
scanf("%f",&students[num]Mark2);
getchar();
printf("请输入成绩:");
scanf("%f",&students[num]Mark3);
getchar();
students[num]Average=Avg(students[num]);
num++;
printf("是否继续(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/修改学生信息/
void Student_Modify()
{
float mark1,mark2,mark3;
while(1)
{
char id[20];
int index;
printf("请输入要修改的学生的学号:");
scanf("%s",&id);
getchar();
index=Student_SearchByIndex(id);
if (index==-1)
{
printf("学生不存在!\n");
}
else
{
printf("你要修改的学生信息为:\n");
Student_DisplaySingle(index);
printf("-- 请输入新值--\n");
printf("请输入学号:");
scanf("%s",&students[index]ID);
getchar();
printf("请输入姓名:");
scanf("%s",&students[index]Name);
getchar();
printf("请输入成绩:");
scanf("%f",&students[index]Mark1);
getchar();
printf("请输入成绩:");
scanf("%f",&students[index]Mark2);
getchar();
printf("请输入成绩:");
scanf("%f",&students[index]Mark3);
getchar();
students[index]Average=Avg(students[index]);
}
printf("是否继续(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/删除学生信息/
void Student_Delete()
{
int i;
while(1)
{
char id[20];
int index;
printf("请输入要删除的学生的学号:");
scanf("%s",&id);
getchar();
index=Student_SearchByIndex(id);
if (index==-1)
{
printf("学生不存在!\n");
}
else
{
printf("你要删除的学生信息为:\n");
Student_DisplaySingle(index);
printf("是否真的要删除(y/n)");
if (getchar()=='y')
{
for (i=index;i<num-1;i++)
{
students[i]=students[i+1];
}
num--;
}
getchar();
}
printf("是否继续(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/按姓名查询/
void Student_Select()
{
while(1)
{
char name[20];
int index;
printf("请输入要查询的学生的姓名:");
scanf("%s",&name);
getchar();
index=Student_SearchByName(name);
if (index==-1)
{
printf("学生不存在!\n");
}
else
{
printf("你要查询的学生信息为:\n");
Student_DisplaySingle(index);
}
printf("是否继续(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/按平均值排序/
void Student_SortByAverage()
{
int i,j;
struct Student tmp;
for (i=0;i<num;i++)
{
for (j=1;j<num-i;j++)
{
if (students[j-1]Average<students[j]Average)
{
tmp=students[j-1];
students[j-1]=students[j];
students[j]=tmp;
}
}
}
}
/显示学生信息/
void Student_Display()
{
int i;
printf("%10s%10s%8s%8s%8s%10s\n","学号","姓名","成绩","成绩","成绩","平均成绩");
printf("-------------------------------------------------------------\n");
for (i=0;i<num;i++)
{
printf("%10s%10s%82f%82f%82f%102f\n",students[i]ID,students[i]Name,
students[i]Mark1,students[i]Mark2,students[i]Mark3,students[i]Average);
}
}
/将学生信息从文件读出/
void IO_ReadInfo()
{
FILE fp;
int i;
if ((fp=fopen("Databasetxt","rb"))==NULL)
{
printf("不能打开文件!\n");
return;
}
if (fread(&num,sizeof(int),1,fp)!=1)
{
num=-1;
}
else
{
for(i=0;i<num;i++)
{
fread(&students[i],sizeof(struct Student),1,fp);
}
}
fclose(fp);
}
/将学生信息写入文件/
void IO_WriteInfo()
{
FILE fp;
int i;
if ((fp=fopen("Databasetxt","wb"))==NULL)
{
printf("不能打开文件!\n");
return;
}
if (fwrite(&num,sizeof(int),1,fp)!=1)
{
printf("写入文件错误!\n");
}
for (i=0;i<num;i++)
{
if (fwrite(&students[i],sizeof(struct Student),1,fp)!=1)
{
printf("写入文件错误!\n");
}
}
fclose(fp);
}
/主程序/
main()
{
int choice;
IO_ReadInfo();
while(1)
{
/主菜单/
printf("\n------ 学生成绩管理系统------\n");
printf("1 增加学生记录\n");
printf("2 修改学生记录\n");
printf("3 删除学生记录\n");
printf("4 按姓名查询学生记录\n");
printf("5 按平均成绩排序\n");
printf("6 退出\n");
printf("请选择(1-6):");
scanf("%d",&choice);
getchar();
switch(choice)
{
case 1:
Student_Insert();
break;
case 2:
Student_Modify();
break;
case 3:
Student_Delete();
break;
case 4:
Student_Select();
break;
case 5:
Student_SortByAverage();
Student_Display();
break;
case 6:
exit();
break;
}
IO_WriteInfo();
}
}
final String url = "jdbc:oracle:thin:@localhost:1521:ORCL";
final String user = "store";
final String password = "store_password";
ClassforName("oraclejdbcdriverOracleDriver");
Connection con = DriverManagergetConnection(url, user, password);
return con;
}
这是我以前写的库存管理,和你的要求差不多,你看一下吧,希望对你有帮助#include <iostream>
#include <cstring>
using namespace std;struct inv
{
char item[40];
double cost;
double retail;
int on_hand;
int lead_time;
inv next;
};//建立商品信息库
inv creat()
{
inv head, tail, pro;
head = tail = NULL;
cout << "Please initialize first:" << endl;
while (1)
{
pro = new inv;
pro -> next = NULL;
cout << "Item: ";
cin >> pro -> item; //如果输入商品名字为0,结束
if (pro -> item[0] == '0')
{
delete pro;
break;
} cout << "Cost: ";
cin >> pro -> cost;
cout << "Retail: ";
cin >> pro -> retail;
cout << "on_hand: ";
cin >> pro -> on_hand;
cout << "Lead_time: ";
cin >> pro -> lead_time; //如果链表为空,加入第一个结点
if (tail == NULL)
head = tail = pro;
else
{
//如果链表中已经有其他点,将新结点加入链表结尾
tail -> next = pro;
tail = pro;
}
}
cout << endl;
return head;
}//选择菜单
char manu()
{
char str;
do
{
cout << "e: enter new information" << endl;
cout << "d: display all of them" << endl;
cout << "r: delete one of them" << endl;
cout << "u: update one of them" << endl;
cout << "v: view one of them" << endl;
cout << "q: quit" << endl << endl;
cout << "choose one: ";
cin >> str;
}
while (!strchr("edruvq", tolower(str)));
return str;
}//输出所有库存信息
void display(inv pro)
{
//如果链表为空,输出提示语句
if (pro == NULL)
{
cout << "Link is NULL!" << endl << endl;
return;
} inv p;
p = pro; //如果链表不为空,输出库存信息
while (p != NULL)
{
cout << "Items: " << p -> item << endl;
cout << "Cost: " << p -> cost << endl;
cout << "Retail price: " << p -> retail << endl;
cout << "On hand: " << p -> on_hand << endl;
cout << "Lead time to resupply: " << p -> lead_time << endl;
cout << endl;
p = p -> next;
}
}//输入新产品信息
inv enter(inv pro)
{
inv tail, p;
tail = pro; //如果链表不为空,找到链表结尾
if (tail != NULL) //必须加这一步判断,否则链表为空时,输入产品信息会出错
{
while (tail -> next != NULL)
tail = tail -> next;
}
//申请结点,存入新产品信息
p = new inv;
p -> next = NULL;
cout << "Item: ";
cin >> p -> item;
cout << "Cost: ";
cin >> p -> cost;
cout << "Retail: ";
cin >> p -> retail;
cout << "on_hand: ";
cin >> p -> on_hand;
cout << "Lead_time: ";
cin >> p -> lead_time; //如果链表为空,加入第一个结点 必须加这一步,否则链表为空时,输入产品信息会出错
if(tail == NULL)
tail = p;
//如果链表不为空,将新结点加到链表尾部
else
tail -> next = p; cout << endl;
return pro;
}//删除某个产品信息
inv remove(inv pro)
{
//如果链表为空,输出提示信息
if (pro == NULL)
{
cout << "Link is NULL" << endl << endl;
return pro;
} inv p, q;
p = pro;
q = pro -> next;
char name[40];
cout << "Please input the item you want to remove: ";
cin >> name;
cout << endl;
//如果头结点为要删除的点,删除之
if (!strcmp(name, pro -> item))
{
p = pro;
pro = pro -> next;
delete p;
return pro;
}
//找到要删除结点
while (q != NULL)
{
if (strcmp(name, q -> item))
{
p = q;
q = q -> next;
}
} if (q != NULL)
{
p -> next = q -> next;
delete q;
}
//如果未找到要删除的产品,输出提示信息
else
cout << "Item is not found!" << endl; cout << endl;
return pro;
}//更新某个产品信息
inv update(inv pro)
{
//如果链表为空,输出提示信息
if (pro == NULL)
{
cout << "Link is NLL!" << endl << endl;
return pro;
} inv p;
p = pro;
char name[40];
cout << "Please input the item you want to update: ";
cin >> name;
cout << endl; //找到要更新的产品
while (p != NULL)
p = p -> next; //如果未找到该产品,输出提示信息
if (p == NULL)
{
cout << "Item is not found!" << endl << endl;
return pro;
}
//更新产品信息
cout << "Cost: ";
cin >> p -> cost;
cout << "Retail: ";
cin >> p -> retail;
cout << "on_hand: ";
cin >> p -> on_hand;
cout << "Lead_time: ";
cin >> p -> lead_time; cout << endl;
return pro;
}//查看某种产品信息
void view(inv pro)
{
//如果链表为空,输出提示信息
if (pro == NULL)
{
cout << "Link is NULL!" << endl << endl;
return;
}
char name[40];
cout << "Please input the item you want to view: ";
cin >> name;
cout << endl; inv p;
p = pro; //找到要查看的产品
while (p != NULL)
p = p -> next; //如果未找到该产品,输出提示信息
if (p == NULL)
{
cout << "Item is not found!" << endl << endl;
return;
}
//输出该产品信息
cout << "Items: " << p -> item << endl;
cout << "Cost: " << p -> cost << endl;
cout << "Retail price: " << p -> retail << endl;
cout << "On hand: " << p -> on_hand << endl;
cout << "Lead time to resupply: " << p -> lead_time << endl;
cout << endl;
}int main()
{
inv product;
product = new inv;
product = NULL; //链表初始化
product = creat();
char choice;
while (1)
{
//读入要进行的 *** 作
choice = manu();
switch (choice)
{
case 'e':
product = enter(product);
break;
case 'd':
display(product);
break;
case 'r':
product = remove(product);
break;
case 'u':
product = update(product);
break;
case 'v':
view(product);
break;
case 'q':
return 0;
}
}
return 0;
}
以上就是关于C语言程序设计学生成绩管理系统全部的内容,包括:C语言程序设计学生成绩管理系统、C语言程序设计 学生档案管理系统、C语言程序设计 学生信息管理系统等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)