soarli

帮高中老师做了一个成绩录入系统
昨天晚上帮高中老师做了一个成绩录入系统,登入的分数会自动生成csv文件保存。程序使用C++编写,代码:#inclu...
扫描右侧二维码阅读全文
10
2020/03

帮高中老师做了一个成绩录入系统

昨天晚上帮高中老师做了一个成绩录入系统,登入的分数会自动生成csv文件保存。程序使用C++编写,代码:

#include<iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;
    void xuanze()
    {
        system("cls");
        double s=0, b[500][500];
        char f[100];
        int banhao,tishu,renshu,per;
        cout << "欢迎来到选择题成绩录入系统!" << endl;
        cout << "使用说明:输入1或0(分别表示正确和错误)。" << endl <<endl ;        
        cout<< "********************" <<endl <<"请先输入班号:";
        cin >> banhao;
        cout << "请输入" << banhao << "班有多少个学生:";
        cin >> renshu;
        cout << "请输入共有多少道选择题:";
        cin >> tishu; 
        cout << "请输入每道选择题多少分:";
        cin >> per;
        cout<< "********************" <<endl <<endl;
        sprintf(f, "%d班选择题.csv",banhao);
        ofstream in(f);
        //in.open("%d班选择题.txt",banhao);
        in << "学号" << ",";
        for(int i = 1; i<= tishu ;i++)
        {
            if(i!= tishu)
                in << "第" << i << "题" <<"," ;
            else
                in << "第" << i << "题"<< "," << "总分" <<endl;;
        }
        //in << "学号" << ","<< "1t" <<","<< "2t" ","<< "3t" << "," << "总分" <<endl;
        //in.close();
        int xuehao =  banhao * 100 + 1;
        for(int i = 1;i <= renshu;i++)
        {
            s = 0;

            for(int j = 1;j<=tishu;j++) 
            {
                begin_ij:
                cout << "请输入学号为:"<< xuehao <<"的学生第" << j << "道选择题是否正确(输入1或0):"<< endl;
                cin >> b[i][j];
                if(b[i][j] == 1 || b[i][j] == 0)
                    s += b[i][j] * per;
                else
                {
                    cout << "输入错误,请重新输入!" << endl;
                    cout<< "--------------------" <<endl <<endl;
                    goto begin_ij;
                } 

            }
            //in.open("阅卷.txt" , ios::app);
            in << xuehao << ",";
            for(int j = 1;j<=tishu;j++) 
            {
                if(j!=tishu)
                    in << b[i][j] * per << ",";
                else
                    in << b[i][j] * per << "," << s << endl;
            }

            cout << "第" << i << "位学生的分数是:" << s << endl<< endl<< endl;
            xuehao ++;            
        }
        in.close();
        cout<< "********************" <<endl<<endl; 
        cout << banhao << "班的学生选择题成绩录入完成!" << endl<<endl;
        cout<< "********************" <<endl<<endl<<endl;         
        system("pause");
    }
    void feixuanze()
    {
        system("cls");
        double s=0, b[500][500];
        char f[100];
        int banhao,tishu,renshu;
        cout << "欢迎来到非选择题成绩录入系统!" << endl <<endl ;
        cout<< "********************" <<endl <<"请输入班号:";
        cin >> banhao;
        cout << "请输入" << banhao << "班有多少个学生:";
        cin >> renshu;
        cout << "请输入共有多少道非选择题:";
        cin >> tishu; 
        cout<< "********************" <<endl <<endl;
        sprintf(f, "%d班非选择题.csv",banhao);
        ofstream in(f);
        //in.open("%d班非选择题.txt",banhao);
        in << "学号" << ",";
        for(int i = 1; i<= tishu ;i++)
        {
            if(i!= tishu)
                in << "第" << i << "题" <<"," ;
            else
                in << "第" << i << "题"<< "," << "总分" <<endl;;
        }
        //in << "学号" << ","<< "1t" <<","<< "2t" ","<< "3t" << "," << "总分" <<endl;
        //in.close();
        int xuehao =  banhao * 100 + 1;
        for(int i = 1;i <= renshu;i++)
        {
            s = 0;

            for(int j = 1;j<=tishu;j++) 
            {
                cout << "请输入学号为:"<< xuehao <<"的学生第" << j << "题的分数:"<< endl;
                cin >> b[i][j];
                s += b[i][j];
            }
            //in.open("阅卷.txt" , ios::app);
            in << xuehao << ",";
            for(int j = 1;j<=tishu;j++) 
            {
                if(j!=tishu)
                    in << b[i][j] << ",";
                else
                    in << b[i][j] << "," << s << endl;
            }

            cout << "第" << i << "位学生的分数是:" << s << endl<< endl<< endl;
            xuehao ++;            
        }
        in.close();
        cout<< "********************" <<endl<<endl; 
        cout << banhao << "班的学生非选择题成绩录入完成!" << endl<<endl;
        cout<< "********************" <<endl<<endl<<endl; 
        system("pause");
    } 
    int main()
    {
        int flag;
        cout << "欢迎来到学生成绩录入系统!" << endl <<endl ;
        while(1)
            {
                cout<< "********************" <<endl << "请输入模式(1表示选择题模式,2表示非选择题模式,3表示退出程序):"<< endl;
                cin >> flag;
                cout<< "********************" <<endl <<endl<<endl;
                if (flag == 1)
                {
                    xuanze();
                    return 0;
                } 
                else if (flag == 2)
                {
                    feixuanze();
                    return 0;
                } 
                else if(flag == 3)
                {
                    break;
                }        
                else
                {
                    cout << "输入错误,请重新输入!" << endl << endl << endl;
                }
            }
        
    }

参考资料:

https://blog.csdn.net/qq_41598072/article/details/83036098

https://www.cnblogs.com/shaoguobao/archive/2011/04/15/2017413.html

https://zhidao.baidu.com/question/617769773305413292.html

https://www.cnblogs.com/CodeAndMoe/p/ming-ling-xing-zhi-xingC-yu-yan-cheng-xu-shi-qing-.html

https://www.cnblogs.com/fuhang/p/9056803.html

https://blog.csdn.net/cainiaoyizhiyang/article/details/89891066

最后修改:2022 年 01 月 09 日 03 : 56 AM

发表评论