发布网友 发布时间:2022-04-24 18:30
共3个回答
热心网友 时间:2023-11-01 11:40
//学生成绩管理 2014-6-15 16:20:50 onion
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
class student{
public:
student(int );
void write();
void read();
void del();
private:
int n;
string name;
double score;
double sc_music;
double sc_math;
unsigned sc_coding;
double sc_e;
};
int main(){
start:
cout<<" ┌────────────┐\n"
<<" │ 学生成绩管理系统 │\n"
<<" │ 1.输入成绩 │\n"
<<" │ 2.查询成绩 │\n"
<<" │ 3.删除成绩 │\n"
<<" │ 4.退出 │\n"
<<" └────────────┘\n";
int num;
cin>>num;
while( num!=1 && num!=2 && num!=3 && num!=4){
cout<<"输入无效,重新输入(1-4):";
cin>>num;
}
switch(num){
case 1:{
student a(1);
break;
}
case 2:{
student a(2);
break;
}
case 3: {
student a(3);
break;
}
default:
exit(0);
break;
}
goto start; //请原谅goto 的简洁高效吧
system("PAUSE");
return 0;
}
student::student(int a){
n=a;
if(n==1)
write();
else if(n==2)
read();
else if(n==3)
del();
else
; //很显然,除了上面的,其余参数传不过来。空语句说明。
}
void student::write(){
//ofstream wfile("admin.dat",ios::app); //这个文件用来存储所有的学生成绩文件。
cout<<"输入学生名称:";
cin>>name;
string fname;
fname = name + ".dat";
ofstream file;
file.open(fname.c_str()); //open()要接受c风格字符串的文件名,所以将string用c_str()转换
// wfile<<fname<<'$'<<endl;
file << "\n姓名:"<<name<<endl;
cout<<"输入学生各科成绩(1~100):\nMusic:";
cin>>sc_music;
file<<"Music:"<<sc_music<<endl;
cout<<"math:";
cin>>sc_math;
file<<"math:"<<sc_math<<endl;
cout<<"E文:";
cin>>sc_e;
file<<"english:"<<sc_e<<endl;
cout<<"程序总行数(1~5W):";
cin>>sc_coding;
file<<"coding-line:"<<sc_coding<<"行"<<endl;
file.close();
// wfile.close();
}
void student::read(){
cout<<"输入学生名查询成绩:";
cin>>name;
name+=".dat";
ifstream infile(name.c_str());
if(!infile){
cout<<"open file error!"<<endl;
return ;
}
else
cout<<"读取数据中...."<<endl;
getline(infile,name,'^');
cout<<name<<endl<<endl<<endl;
infile.close();
}
void student::del(){
cout<<"输入学生名删除成绩:";
cin>>name;
name += ".dat";
ifstream infile(name.c_str()); //文件不存在时处理。
if(!infile){
cout<<"open file error!"<<endl;
return ;
}
infile.close(); //不需要使用文件时就要关闭的嘛。。
string fname;
fname = "del "+ name;
system(fname.c_str());
cout<<name<<"删除成功。"<<endl<<endl;
}
以前写的,给你参考吧。恩,c++的,c的改下就好喽。看思路思路
热心网友 时间:2023-11-01 11:40
在TC2.0下编写的程序,学生成绩管理,跨平台可能有些bug,需要的话可以给你改
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include<malloc.h>
#define NULL 0
#define LEN sizeof(ST)
typedef struct student
{char num[20];
char name[20];
int score[3];
int sum;
float average;
int order;
struct student *next;
}ST;
ST *init();
int caidan();
ST *create();
void print(ST *head);
ST *xiugai(ST *head);
void chazhao(ST *head);
ST *shanchu(ST *head);
ST *paixu(ST *head);
ST *charu(ST *head,ST *new);
void save(ST *head);
ST *load();
void main()
{ST *head,new;
head=init();
for(;;)
{switch(caidan())
{
case 1:head=create();break;
case 2:print(head);break;
case 3:chazhao(head);break;
case 4:head=xiugai(head);break;
case 5:head=shanchu(head);break;
case 6:head=paixu(head);break;
case 7:head=charu(head,&new);break;
case 8:save(head);break;
case 9:head=load(); break;
case 10:exit(0);
}
}
}
ST *init()
{
return NULL;
}
int caidan()
{int n;
printf("press any key to enter the menu......");
getch();
clrscr();
printf("********************************************************************************\n");
printf("\t\t Welcome to\n");
printf("\n\t\t The student score manage system\n");
printf("*************************************MENU***************************************\n");
printf("\t\t\t1. Shu ru xue sheng xin xi\n");
printf("\t\t\t2. Xian shi xue sheng xin xi\n");
printf("\t\t\t3. Cha zhao xue sheng xinxi\n");
printf("\t\t\t4. xiu gai xue sheng xinxi\n");
printf("\t\t\t5. Shan chu xue sheng xinxi\n");
printf("\t\t\t6. Xue sheng cheng ji guan li\n");
printf("\t\t\t7. Cha ru xin xue sheng xinxi\n");
printf("\t\t\t8. Save the file\n");
printf("\t\t\t9. Load the file\n");
printf("\t\t\t10. Quit\n");
printf("\n\t\t Made by Yin Weifeng.\n");
printf("********************************************************************************\n");
do{
printf("\n\t\t\tEnter your choice(1~10):");
scanf("%d",&n);
}while(n<1||n>10);
return(n);
}
ST *create()
{int i,s;
char k;
ST *head=NULL,*p;
clrscr();
for(;;)
{clrscr();
p=(ST *)malloc(LEN);
if(p==NULL)
{printf("\nSorry,Dong tai nei cun bu dou.");
return (head);
}
printf("Enter the num:");
scanf("%s",p->num);
printf("Enter the name:");
scanf("%s",p->name);
printf("Please enter the %d scores\n",3);
s=0;
printf("Gao Shu:");
do{
scanf("%d",&p->score[0]);
if(p->score[0]<0 || p->score[0]>100)
printf("Error!please enter again.\n");
}while(p->score[0]<0 || p->score[0]>100);
printf("Ying Yu:");
do{
scanf("%d",&p->score[1]);
if(p->score[1]<0 || p->score[1]>100)
printf("Error!please enter again.\n");
}while(p->score[1]<0 || p->score[1]>100);
printf("C Yu Yan:");
do{
scanf("%d",&p->score[2]);
if(p->score[2]<0 || p->score[2]>100)
printf("Error!please enter again.\n");
}while(p->score[2]<0 || p->score[2]>100);
s=p->score[0]+p->score[1]+p->score[2];
p->sum=s;
p->average=(float)s/3;
p->order=0;
p->next=head;
head=p;
printf("continue?y/n:\n");
k=getch();
if(k=='y'||k=='Y') continue;
else break;
}
return(head);
}
void print(ST *head)
{int i=0,e[3][4]={{0,0,0,0},{0,0,0,0},{0,0,0,0}};
ST *p1;
ST *p2;
clrscr();
p1=head;
p2=head;
while(p1!=NULL)
{ if(p1->score[0]>=90)e[0][0]++;
else if(p1->score[0]>=80)e[0][1]++;
else if(p1->score[0]>=60)e[0][2]++;
else e[0][3]++;
if(p1->score[1]>=90)e[1][0]++;
else if(p1->score[1]>=80)e[1][1]++;
else if(p1->score[1]>=60)e[1][2]++;
else e[1][3]++;
if(p1->score[2]>=90)e[2][0]++;
else if(p1->score[2]>=80)e[2][1]++;
else if(p1->score[2]>=60)e[2][2]++;
else e[2][3]++;
p1=p1->next;
}
printf("\n************************************STUDENT************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Rec | Num | Name | Gao shu | ying yu | C yuyan | Sum | Ave |Order|\n");
printf("-------------------------------------------------------------------------------\n");
while(p2!=NULL)
{
i++;
printf("| %3d | %3s |%-16s| %3d | %3d | %3d | %3d |%3.2f| %3d |\n",
i, p2->num,p2->name,p2->score[0],p2->score[1],p2->score[2],p2->sum,p2->average,p2->order);
p2=p2->next;
}
printf("-------------------------------------------------------------------------------\n");
printf("| You xiu student shu | %3d | %3d | %3d |\n",e[0][0],e[1][0],e[2][0]);
printf("| Liang hao student shu | %3d | %3d | %3d |\n",e[0][1],e[1][1],e[2][1]);
printf("| Zhong deng student shu | %3d | %3d | %3d |\n",e[0][2],e[1][2],e[2][2]);
printf("| Bu he ge student shu | %3d | %3d | %3d |\n",e[0][3],e[1][3],e[2][3]);
printf("-------------------------------------------------------------------------------\n");
printf("****************************************END*************************************\n");
}
此处只能打10000个字,余下的在问题补充中继续,见谅!追问有错误要怎么修改,我不会的,我用的是Visual Studio,大神求帮忙,我可以提高悬赏。。
热心网友 时间:2023-11-01 11:41
现成的没有,着急吗?可以根据你的条件题材做