zoukankan      html  css  js  c++  java
  • 2020 7 9 每日总结

    今天研究了小学期的第一个项目,学生成绩管理系统,对输入输出运算符的重载进行运用,并运用类的知识,附代码:

    #include <iostream>
    #include <string>
    #include <fstream>
    using namespace std;
    string file;
    struct StudentInfo
    {
    long num;
    string name;
    int s[3];
    };
    class StudentManage
    {
    private:
    StudentInfo st[100];
    public:
    void one();
    void two();
    void three();
    void four();
    void five();
    };
    void StudentManage::one()
    {
    cout<<"请输入想要创建的文件路径:"<<endl;
    cin>>file;
    ofstream outfile;
    outfile.open("file",ios::trunc);
    outfile.close();
    }
    void StudentManage::two()
    {
    cout<<"请输入想要读取的文件路径:"<<endl;
    ifstream infile;
    infile.open(file);
    for(int i=0;i<100;i++)
    {
    infile>>st[i];
    }
    infile.close();
    }
    void StudentManage::three()
    {
    for(int i=0;i<100;i++)
    {
    cout<<st[i]<<endl;
    }
    }
    void StudentManage::four()
    {
    cout<<"输入多少位同学呢:"<<endl;
    int n;
    cin>>n;
    cout<<"是否使用之前的文件路径:A 是 B 不是"<<endl;
    char temp;
    cin>>temp;
    if(temp=='B'){cout<<"输入新的文件路径:"<<endl;cin>>file;}
    ofstream outfile;
    outfile.open(file);
    for(int i=0;i<n;i++)
    {
    cout<<"请输入第"<<i<<"位同学的学号,姓名,语文成绩,数学成绩,英语成绩:"<<endl;
    cin>>st[i];
    outfile<<st[i]<<endl;
    }
    outfile.close();
    }
    void StudentManage::five()
    {
    cout<<"是否使用之前的文件路径:A 是 B 不是"<<endl;
    char temp;
    cin>>temp;
    if(temp=='B'){cout<<"输入新的文件路径:"<<endl;cin>>file;}
    cout<<"请输入删除同学的学号:"<<endl;
    long n;
    cin>>n;
    ifstream infile;
    infile.open(file);
    for(int i=0;i<100;i++)
    {
    infile>>st[i];
    }
    for(int i=0;i<100;i++)
    {
    int temp=0;
    if(st[i].num ==n)
    {
    for(int j=i;j<100;j++)
    {
    st[j].name =st[j+1].name ;
    st[j].num =st[j+1].num ;
    st[j].s[0]=st[j+1].s [0];
    st[j].s [1]=st[j+1].s [1];
    st[j].s [2]=st[j+1].s [2];
    }
    break;
    }
    }
    }
    istream& operator >>(istream& input,StudentInfo& c)
    {
    input>>c.num >>c.name >>c.s [0]>>c.s [1]>>c.s [2];
    return input;
    }
    ostream& operator << (ostream& output,StudentInfo& c)
    {
    output<<c.num <<" "<<c.name <<" "<<c.s [0]<<" "<<c.s[1]<<" "<<c.s [2];
    return output;
    }
    int main()
    {
    cout<<"**************学生成绩管理系统**************"<<endl;
    cout<<endl<<"请选择:"<<endl;
    cout<<"****** 1.创建文件 "<<endl;
    cout<<"****** 2.文件导入 "<<endl;
    cout<<"****** 3.显示数据 "<<endl;
    cout<<"****** 4.数据录入 "<<endl;
    cout<<"****** 5.删除数据 "<<endl;
    cout<<"****** 6.数据修改 "<<endl;
    cout<<"****** 7.数据查找 "<<endl;
    cout<<"****** 8.成绩汇总 "<<endl;
    cout<<"****** 9.成绩排序 "<<endl;
    cout<<"****** 10.数据导入 "<<endl;
    cout<<"****** 11.数据插入 "<<endl;
    int temp;
    cin>>temp;

  • 相关阅读:
    pytorch+tensorboard 安装
    pytorch安装
    255.用队列实现堆栈
    23. 合并K个升序链表(学习了java的自定义比较类)
    21.合并两个有序链表
    138.复制带随机指针的链表
    10个教师必备的资源网站,想要免费地过来看看
    班主任如何管理一个乱班、差班?
    高阶函数_函数柯里化 以及 setState中动态key
    React中的PropTypes详解
  • 原文地址:https://www.cnblogs.com/fuxw4971/p/13275520.html
Copyright © 2011-2022 走看看