综合项目 一

【问题描述】在程序中请用顺序表或链表存储结构,实现以下一种系统,采用菜单模式,功能上尽可能的完善,实现例如增、删、改、查等操作。

【综合题目】自定或任选

(1)学生成绩管理系统

(2)图书管理系统

(3)家谱管理系统

(4)药店药品管理系统

(5)手机销售管理系统

(6)火车订票管理系统

(7)电影院管理系统

(8)小区物业管理系统

(9)汽车租赁管理系统

(10)教师人事管理系统

(11)二手房销售信息管理系统

… … … …

话不多说直接贴代码:

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include <fstream>
#include<malloc.h>
#include<math.h>
#include<iomanip>
#include<windows.h>
HANDLE han = GetStdHandle(-11);
#define LEN sizeof(struct student)
using namespace std;
typedef struct birthday
{
    int year;
    int month;
    int day;
} Birthday;
typedef struct student
{
    int id;
    string name;
    string gender;
    int age;
    Birthday bir;
    float c;
    float math;
    float eng;
    float sum;
    float ave;
    student *next;
} Student;
void color(short x)	//自定义函根据参数改变颜色
{
    if(x>=0 && x<=15)//参数在0-15的范围颜色
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x);	//只有一个参数,改变字体颜色
    else//默认的颜色白色
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
}
void Title1()
{
    cout<<"------------------------------------------------------------------------------------------"<<endl;
    cout<<"|  学号  |  姓名  |  性别  |  年龄  |  出生日期  |  C语言成绩  |  数学成绩  |  英语成绩  |"<<endl;
    cout<<"------------------------------------------------------------------------------------------"<<endl;

}
void Title2()
{
    cout<<"--------------------------------------------------------------------------------------------------------------"<<endl;
    cout<<"|  学号  |  姓名  |  性别  |  年龄  |  出生日期  |  C语言成绩  |  数学成绩  |  英语成绩  |  总分  |  平均分  |"<<endl;
    cout<<"--------------------------------------------------------------------------------------------------------------"<<endl;
}
void Save1(Student*S)///保存至文件不覆盖原数据 孟
{
    ofstream outfile;
    outfile.open("D:\\项目1\\student.txt",ios::app);
    if(!outfile.is_open())
    {
        cout<<"Open file failure"<<endl;
        return ;
    }
    Student *p;
    p=S->next;
    while(p!=NULL)
    {
        outfile<<p->id<<"\t"<<p->name<<"\t"<<p->gender<<"\t"<<p->age<<"\t"<<p->bir.year<<"\t"<<p->bir.month<<"\t"<<p->bir.day<<"\t"<<p->c<<"\t"<<p->math<<"\t"<<p->eng<<"\t"<<p->sum<<"\t"<<p->ave<<endl;
        p=p->next;
    }
    cout<<"OK"<<endl;
}
void Save2(Student*S)///保存至文件覆盖原数据 孟
{
    ofstream outfile;
    outfile.open("D:\\项目1\\student.txt",ios::out);
    if(!outfile.is_open())
    {
        cout<<"Open file failure"<<endl;
        return ;
    }
    Student *p;
    p=S->next;
    while(p!=NULL)
    {
        outfile<<p->id<<"\t"<<p->name<<"\t"<<p->gender<<"\t"<<p->age<<"\t"<<p->bir.year<<"\t"<<p->bir.month<<"\t"<<p->bir.day<<"\t"<<p->c<<"\t"<<p->math<<"\t"<<p->eng<<"\t"<<p->sum<<"\t"<<p->ave<<endl;
        p=p->next;
    }
    cout<<"OK"<<endl;
}
void Read(Student*S)///读取文件  孟
{
    ifstream infile;
    infile.open("D:\\项目1\\student.txt",ios::in);
    if(!infile.is_open())
    {
        cout<<" 未成打开文件 "<<endl;
    }
    char ch;
    infile>>ch;
    if(!ch)
    {
        cout<<" 文件为空 "<<endl;
    }
    infile.seekg(0,ios::beg);
    Student *p,*q;
    q=S;
    while(q->next!=NULL)
    {
        q=q->next;
    }
    int Id;
    string Name;
    string Gender;
    int Age;
    Birthday Bir;
    float C;
    float Math;
    float Eng;
    float Sum;
    float Ave;
    while(infile>>Id>>Name>>Gender>>Age>>Bir.year>>Bir.month>>Bir.day>>C>>Math>>Eng>>Sum>>Ave)
    {
        p=new student;
        p->next=NULL;
        p->id=Id;
        p->name=Name;
        p->gender=Gender;
        p->age=Age;
        p->bir.year=Bir.year;
        p->bir.month=Bir.month;
        p->bir.day=Bir.day;
        p->c=C;
        p->math=Math;
        p->eng=Eng;
        p->sum=Sum;
        p->ave=Ave;
        q->next=p;
        q=p;
    }
    cout<<"读取成功"<<endl;

}
void Create(Student *S)///录入学生记录   张
{
    Student *p,*q;
    q=S;
    while(q->next!=NULL)
    {
        q=q->next;
    }
    cout<<"请输入学生信息:"<<endl;
    Title1();
    while(1)
    {
        p=new student;
        p->next=NULL;
        cin>>p->id;
        if(p->id==0)
            break;
        else
        {
            cin>>p->name>>p->gender>>p->age>>p->bir.year>>p->bir.month>>p->bir.day>>p->c>>p->math>>p->eng;
            p->sum=p->c+p->math+p->eng;
            p->ave=p->sum/3;
            q->next=p;
            q=p;
        }
    }
}

void Add(Student *S)///添加学生记录  何
{
    student *p,*q;
    q=S;
    p=new student;
    cout<<"请输入学生信息:"<<endl;
    Title1();
    cin>>p->id>>p->name>>p->gender>>p->age>>p->bir.year>>p->bir.month>>p->bir.day>>p->c>>p->math>>p->eng;
    p->sum=p->c+p->math+p->eng;
    p->ave=p->sum/3;
    while(q!=NULL)
    {
        if((q->id<p->id&&q->next->id>p->id)||(q->id<p->id&&q->next==NULL))
        {
            p->next=q->next;
            q->next=p;
            break;
        }
        q=q->next;
    }
    cout<<"添加成功"<<endl;
}
void Show(Student *S)///输出 张
{
    student *p;
    p=S->next;
    Title2();
    while(p!=NULL)
    {
        cout<<setfill('0')<<setw(4)<<p->id<<"\t   "<<p->name<<"\t\t"<<p->gender<<"\t"<<p->age<<"\t"<<p->bir.year<<"."<<p->bir.month<<"."<<p->bir.day<<"\t";
        cout<<p->c<<"\t     "<<p->math<<"\t\t"<<p->eng<<"\t   "<<p->sum<<"\t   "<<p->ave<<endl;
        p=p->next;
    }
}
void Del(Student *S)///删除学生记录  张
{
    int Id;
    cout<<"请输入需要删除的学号"<<endl;
    cin>>Id;
    student *p,*q,*tmp;
    p=S->next;
    q=S;
    while(p!=NULL)
    {
        if(p->id==Id)
        {
            tmp = p;
            cout<<"删除的学生信息为:"<<endl;
            Title2();
            cout<<setfill('0')<<setw(4)<<tmp->id<<"\t   "<<tmp->name<<"\t\t"<<tmp->gender<<"\t"<<tmp->age<<"\t"<<tmp->bir.year<<"."<<tmp->bir.month<<"."<<tmp->bir.day<<"\t";
            cout<<tmp->c<<"\t     "<<tmp->math<<"\t\t"<<tmp->eng<<"\t   "<<tmp->sum<<"\t   "<<tmp->ave<<endl;
            q->next=p->next;
            free(p);
            break;
        }
        p=p->next;
        q=q->next;
    }
    if(p->next!=NULL)
    {
        Save2(S);
    }


}
void Search_Name(Student *S)///按姓名查找 刘
{
    string a;
    student *p;
    p=S->next;
    cout<<"请输入需要查找的学生姓名:"<<endl;
    cin>>a;
    while(1)
    {
        if(p->name==a)
        {
            Title2();
            cout<<setfill('0')<<setw(4)<<p->id<<"\t   "<<p->name<<"\t\t"<<p->gender<<"\t"<<p->age<<"\t"<<p->bir.year<<"."<<p->bir.month<<"."<<p->bir.day<<"\t";
            cout<<p->c<<"\t     "<<p->math<<"\t\t"<<p->eng<<"\t   "<<p->sum<<"\t   "<<p->ave<<endl;
            break;
        }
        else if(p->next==NULL)
        {
            cout<<"查无此人"<<endl;
            break;
        }
        else
            p=p->next;

    }
}
void Search_id(Student *S)///按学号查找 刘
{
    cout<<"请输入查找的学号:"<<endl;
    int Id;
    cin>>Id;
    student *p;
    p=S->next;
    while(1)
    {
        if(p->id==Id)
        {
            Title2();
            cout<<setfill('0')<<setw(4)<<p->id<<"\t   "<<p->name<<"\t\t"<<p->gender<<"\t"<<p->age<<"\t"<<p->bir.year<<"."<<p->bir.month<<"."<<p->bir.day<<"\t";
            cout<<p->c<<"\t     "<<p->math<<"\t\t"<<p->eng<<"\t   "<<p->sum<<"\t   "<<p->ave<<endl;
            break;
        }
        else if(p->next==NULL)
        {
            cout<<"查无此人"<<endl;
            break;
        }
        else
            p=p->next;

    }
}
void change_Student(Student *S)///修改学生信息 刘
{
    int Id,a;
    cout<<"请输入需要修改信息的学号:"<<endl;
    cin>>Id;
    Student *p;
    p=S->next;
    while(1)
    {
        int flag=1;
        if(p->id==Id)
        {
            while(flag)
            {
                cout<<"输入你想修改的内容"<<endl;
                cout<<"1、C语言成绩"<<endl;
                cout<<"2、数学成绩"<<endl;
                cout<<"3、英语成绩"<<endl;
                int n;
                cin>>n;
                switch(n)
                {
                case 1:
                    float cc;
                    cout<<"新成绩"<<endl;
                    cin>>cc;
                    p->c=cc;
                    break;
                case 2:
                    float mm;
                    cout<<"新成绩"<<endl;
                    cin>>mm;
                    p->math=mm;
                    break;
                case 3:
                    float ee;
                    cout<<"新成绩"<<endl;
                    cin>>ee;
                    p->eng=ee;
                    break;
                }
                cout<<"是否继续修改,是输入1,否输入0"<<endl;
                cin>>flag;
            }
            p->sum=p->c+p->math+p->eng;
            float su=p->sum;
            p->ave=su/3;
            break;
        }
        else if(p->next==NULL)
        {
            cout<<"查无此人"<<endl;
            break;
        }
        else
            p=p->next;
    }
    if(p->next!=NULL)
    {
        Save2(S);
    }
}

void Copy(Student*PLa,Student*PLb)///复制 何
{
    Student *p,*ra,*rb;
    ra=PLa->next;
    rb=PLb;
    while(ra)
    {
        p=new Student;
        p->id=ra->id;
        p->name=ra->name;
        p->age=ra->age;
        p->gender=ra->gender;
        p->bir.day=ra->bir.day;
        p->bir.month=ra->bir.month;
        p->bir.year=ra->bir.year;
        p->c=ra->c;
        p->math=ra->math;
        p->eng=ra->eng;
        p->ave=ra->ave;
        p->sum=ra->sum;
        p->next=NULL;
        rb->next=p;
        rb=p;
        ra=ra->next;
    }
}
void Sort(Student *S)///按照总分排序  何
{
    Student *tmp=new Student;
    tmp->next=NULL;
    Copy(S,tmp);
    int count=0;
    Student *p,*q,*r;
    p=tmp;
    q=tmp->next;
    r=tmp->next->next;
    while(q!=NULL)
    {
        count++;
        q=q->next;
    }
    q=tmp->next;
    for(int i=0; i<count; i++)
    {
        while(r!=NULL)
        {
            if(q->sum<r->sum)
            {
                q->next=r->next;
                r->next=q;
                p->next=r;
                p=r;
                r=q->next;

            }
            else
            {
                p=p->next;
                q=q->next;
                r=r->next;
            }
        }
        p=tmp;
        q=tmp->next;
        r=tmp->next->next;
    }
    p=tmp->next;
    int x=1;
    Title2();
    while(p!=NULL)
    {
        cout<<x<<". ";
        cout<<setfill('0')<<setw(4)<<p->id<<"\t   "<<p->name<<"\t\t"<<p->gender<<"\t"<<p->age<<"\t"<<p->bir.year<<"."<<p->bir.month<<"."<<p->bir.day<<"\t";
        cout<<p->c<<"\t     "<<p->math<<"\t\t"<<p->eng<<"\t   "<<p->sum<<"\t   "<<p->ave<<endl;

        p=p->next;
        x++;
    }

}
void Avarage(Student *S)///求平均分 何
{
    cout<<"请选择科目:"<<endl;
    cout<<"1.C语言"<<endl;
    cout<<"2.数学"<<endl;
    cout<<"3.英语"<<endl;
    cout<<"4.总分"<<endl;
    int a,count=0;
    float b=0,c;
    while(1)
    {
        cin>>a;
        if(a==1||a==2||a==3||a==4)
            break;
        else
        {
            cout<<"请选择正确的科目"<<endl;
            continue;
        }
    }
    student *p;
    p=S->next;
    while(p!=NULL)
    {
        if(a==1)
            b+=p->c;
        else if(a==2)
            b+=p->math;
        else if(a==3)
            b+=p->eng;
        else if(a==4)
            b+=p->sum;
        p=p->next;
        count++;
    }
    c=b/count;
    cout<<"该科目的平均分为"<<c<<"分"<<endl;
}
void chang_Manage(char password[],char password1[],char password2[],char password3[])///修改管理员密码 孟
{
    cout<<"旧密码:";
    cin>>password1;
    cout<<"新密码(6位):";
    cin>>password2;
    cout<<"请您确认新密码(6位):";
    cin>>password3;
    for(;;)
    {
        if(strcmp(password,password1)!=0)
        {
            cout<<"输入的旧密码有误"<<endl;
            cout<<"旧密码:";
            cin>>password1;
            cout<<"新密码(6位):";
            cin>>password2;
            cout<<"请确认新密码(6位):";
            cin>>password3;
        }
        if(strcmp(password2,password3)!=0)
        {
            cout<<"输入的新密码与确认的新密码不一致"<<endl;
            cout<<"旧密码:";
            cin>>password1;
            cout<<"新密码(6位):";
            cin>>password2;
            cout<<"请确认新密码(6位):";
            cin>>password3;
        }
        if(strcmp(password,password1)==0&&strcmp(password2,password3)==0)
        {
            cout<<"成功修改密码."<<endl;
            break;
        }
    }
    strcpy(password,password2);
    FILE *fp=fopen("D:\\项目1\\密码.txt","w");
    fputs(password,fp);
    fclose(fp);

}
void fail(Student *S)///统计挂科数 孟
{
    int a,b,c,d,count=0;
    cout<<"请选择科目:"<<endl;
    cout<<"1.C语言"<<endl;
    cout<<"2.数学"<<endl;
    cout<<"3.英语"<<endl;
    while(1)
    {
        cin>>a;
        if(a!=1&&a!=2&&a!=3)
        {
            cout<<"请选择正确的科目:"<<endl;
            continue;
        }
        else
            break;
    }
    student *p;
    p=S->next;
    while(p!=NULL)
    {
        if(a==1)
        {
            if(p->c<60.0)
                count++;
            p=p->next;
        }
        else if(a==2)
        {
            if(p->math<60.0)
                count++;
            p=p->next;
        }
        else if(a==3)
        {
            if(p->eng<60.0)
                count++;
            p=p->next;
        }
    }
    cout<<"该科目共不及格"<<count<<"人"<<endl;
}
void Print()/// 打印菜单  孟
{
    color(1);
    cout<<"★★★★欢迎使用学生成绩管理系统★★★★"<<endl<<endl;
    color(2);
    cout<<"---------------------------------------"<<endl;
    color(3);
    cout<<"\t"<<"0.退出程序"<<endl;
    color(4);
    cout<<"\t"<<"1.录入学生记录"<<endl;
    color(5);
    cout<<"\t"<<"2.添加学生记录"<<endl;
    color(6);
    cout<<"\t"<<"3.删除学生记录"<<endl;
    color(7);
    cout<<"\t"<<"4.修改学生记录"<<endl;
    color(8);
    cout<<"\t"<<"5.查找学生记录"<<endl;
    color(9);
    cout<<"\t"<<"6.按总分对学生记录进行降序排序"<<endl;
    color(10);
    cout<<"\t"<<"7.将数据保存至文件"<<endl;
    color(11);
    cout<<"\t"<<"8.输出所有学生信息"<<endl;
    color(12);
    cout<<"\t"<<"9.计算班级平均分"<<endl;
    color(13);
    cout<<"\t"<<"10.修改管理员密码"<<endl;
    color(14);
    cout<<"\t"<<"11.统计挂科人数"<<endl;
    color(15);
    cout<<"\t"<<"12.读取文件数据"<<endl<<endl;
    cout<<"---------------------------------------"<<endl;

}
void Choose(Student *head)///小组四人共同完成
{
    int choose,n;
    long number,e;
    string name;
    char password[10]= {"123456"};
    char password1[10],password2[10],password3[10],password4[10],num[3];
    FILE *fp=fopen("D:\\项目1\\密码.txt","r");
    fgets(password,10,fp);
    fclose(fp);
    cout<<"请输入进入学生成绩管理系统的管理员代号和密码:"<<endl;
    cout<<"系统的默认登录密码为123456: "<<endl;
    cout<<"管理员代号: "<<endl;
    cin>>num;
    cout<<"密码: "<<endl;
    cin>>password1;
    cout<<endl;
    while(1)
    {
        if(strcmp(password1,password)==0)
        {
            cout<<num<<" 管理员登录成功"<<endl;
            break;
        }
        else
        {
            cout<<"输入的密码有误,请重新输入:"<<endl;
            cout<<"管理员代号: "<<endl;
            cin>>num;
            cout<<"密码: "<<endl;
            cin>>password1;
            cout<<endl;
        }
    }
    system("pause");
    system("cls");
    choose=-1;
    while(choose!=0)
    {
        Print();
        cout<<"请输入一个数字:"<<endl;
        cin>>choose;
        switch(choose)
        {
        case 0:
            system("cls");
            cout<<"\n\n";
            color(6);cout<<"★★★★期待您的下次使用★★★★";
            cout<<"\n\n";
            break;
        case 1:
            system("cls");
            Create(head);
            system("pause");
            system("cls");
            break;
        case 2:
            system("cls");
            Add(head);
            system("pause");
            system("cls");
            break;
        case 3:
            system("cls");
            Del(head);
            system("pause");
            system("cls");
            break;
        case 4:
            system("cls");
            change_Student(head);
            system("pause");
            system("cls");
            break;
        case 5:
            system("cls");
            int ch;
            cout<<"输入你要查找的学生内容"<<endl;
            cout<<"1.按照学号查找"<<endl;
            cout<<"2.按照姓名查找"<<endl;
            cin>>ch;
            if(ch==1)
                Search_id(head);
            else
                Search_Name(head);
            system("pause");
            system("cls");
            break;
        case 6:
            system("cls");
            Sort(head);
            system("pause");
            system("cls");
            break;
        case 7:
            system("cls");
            Save1(head);
            system("pause");
            system("cls");
            break;
        case 8:
            system("cls");
            Show(head);
            system("pause");
            system("cls");
            break;
        case 9:
            system("cls");
            Avarage(head);
            system("pause");
            system("cls");
            break;
        case 10:
            system("cls");
            chang_Manage(password,password1,password2,password3);
            system("pause");
            system("cls");
            break;
        case 11:
            system("cls");
            fail(head);
            system("pause");
            system("cls");
            break;
        case 12:
            system("cls");
            Read(head);
            system("pause");
            system("cls");
            break;

        }
    }
}
int main()
{

    Student *head,*p;
    head = new Student;
    head->next=NULL;
    Choose(head);
    return 0;
}

备注: 里面有两份 .txt 的文件就自己搞吧,暂不提供。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值