zoukankan      html  css  js  c++  java
  • 从一个表格文件中录入信息,进行计算后,在文件中输出这个表格

    源代码:

    #include <iostream>
    #include<fstream>
    #include<string>
    using namespace std;
    class student
    {
    private:
        string num;
        string name;
        double listen;
        double analyze;
        double think;
        double cplus;
        double speak;
        double jihe;
        double gaodai;
        double sum;
    public:
        void luru(string num1,string name1,double listen1,double analyze1,double think1, double cplus1,double speak1,double jihe1,double gaodai1);
        double getsum();
        string geth(){return num;}
        string getw(){return name;}
        double geta(){return listen;}
        double getb(){return analyze;}
        double getc(){return think;}
        double getd(){return cplus;}
        double gete(){return speak;}
        double getf(){return jihe;}
        double getg(){return gaodai;}
        double gets()   {return sum;}
    };
    void student::luru(string num1,string name1,double listen1,double analyze1,double think1, double cplus1,double speak1,double jihe1,double gaodai1)
    {
        num=num1;
        name=name1;
        listen=listen1;
        analyze=analyze1;
        think=think1;
        cplus=cplus1;
        speak=speak1;
        jihe=jihe1;
        gaodai=gaodai1;
    }
     double student::getsum()
     {
         sum=(listen+analyze+think+cplus+speak+jihe+gaodai)/7.0;
     }
    int main()
    {
        student e1[40];
        double a,b,c,d,e,f,g;
        string p,w;
        ifstream infile("C:\a\ab.txt");  //录入的文件一定要是txt格式,且各个信息间用一个空格隔开
        if(!infile.is_open())
            cout<<"can not"<<endl;
        else
        {
            for(int i=1;i<=39;i++)
            {
                infile>>p>>w>>a>>b>>c>>d>>e>>f>>g;
                e1[i].luru(p,w,a,b,c,d,e,f,g);
                e1[i].getsum();
            }
        }
        infile.close();
        ofstream outfile("C:\a\au.xls"); //这是创建的一个空白Excel文件
        if(!outfile.is_open())
        {
            cout<<"can not"<<endl;
        }
        else
        {
            for(int j=1;j<=39;j++){
            outfile<<e1[j].geth()<<' '<<e1[j].getw()<<' '<<e1[j].geta()<<' '<<e1[j].getb()<<' '<<e1[j].getc()<<' '<<e1[j].getd()<<' '<<e1[j].gete()<<' '<<e1[j].getf()<<' '<<e1[j].getg()<<' '<<e1[j].gets()<<' ';
            }
        }
        return 0;
    }


    C:\a\ab.txt 中的信息:如图1

    C:\a\au.xls中的信息:如图1


  • 相关阅读:
    gdb段错误
    gdb断点
    init.d详解
    asp.net中的服务器端控件 textbox 设为只读属性后无法获取 javascript给其赋的值
    关于“金点子”征集通知
    Notepad++ SQL Assistant
    IoC Container Benchmark Unity, Windsor, StructureMap and Spring.NET
    如何判断个人电脑是多少位(32位?还是64位系统)
    批量执行SQL文件
    SQL Server 2005 dev 开发板 版本说明
  • 原文地址:https://www.cnblogs.com/iamjuruo/p/7470974.html
Copyright © 2011-2022 走看看