| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 397 人关注过本帖
标题:求大神帮忙加个表格数据统计计算模块
只看楼主 加入收藏
小兵有大智慧
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2012-6-18
结帖率:0
收藏
 问题点数:0 回复次数:0 
求大神帮忙加个表格数据统计计算模块
#include<iostream>
#include<string>
#include<vector>
#include <stdlib.h>//atoi
using namespace std;
class Table{
private:
    string title;
    int row,column,width;
    vector< vector<string> > data;
public:
    Table(string title):title(title){   
        while(true){
            cout<<"请输入表格列数[1-10]:";
            cin>>column;
            if(column<=10&&column>=1)break;
            else{
                cout<<"输入有误,请重新输入..........."<<endl;
                system("pause");
                system("cls");
            }
        }
        while(true){
            cout<<"请输入表格行数[1-99]:";
            cin>>row;
            if(row<=99&&row>=1)break;
            else{
                cout<<"输入有误,请重新输入..........."<<endl;
                system("pause");
                system("cls");
            }
        }
        data.resize(column);
        for(int i=0;i<column;i++){
            data[i].resize(row);
        }
        for(int j=0;j<column;j++){
            for(i=0;i<row;i++){
                data[j][i]=" ";
            }
        }
    };
    /*
    制表符:
    ┏━┓┃┗┛┣┳┫┻╋■●
   
      7列:
      ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
                                                              
      ┣━━━┳━━━┳━━━┳━━━┳━━━┳━━━┳━━━━┫
      6列:
      ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
                                                              
      ┣━━━━┳━━━━┳━━━━┳━━━━┳━━━━┳━━━┫
      5列:
      ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
                                                              
      ┣━━━━━┳━━━━━┳━━━━━┳━━━━━┳━━━━┫
      4列:
      ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
                                                              
      ┣━━━━━━┳━━━━━━┳━━━━━━┳━━━━━━━┫
      3列:
      ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
                                                              
      ┣━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━┫
      2列:
      ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
                                                              
      ┣━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┫
    */
    void draw(){
        system("cls");
        int i,j,k;   
        char c='A';
        int x=30/column;
        width=(x-1)*2;
        int len=x*column+1;
        int y=len*2 - title.length() -4;
        //X------------------------------------------------
        cout<<"  ●";
        for(j=0;j<column;j++)
        {
            for(i=0;i<x-1;i++)cout<<" ";
            cout<<c++;
            for(i=0;i<x-2;i++)cout<<" ";
            cout<<"●";
            if(j>=column-1)cout<<endl;
        }
        //header------------------------------------------------
        cout<<"  ┏";
        for(i=0;i<len-2;i++)
        {
            cout<<"━";
        }
        cout<<"┓"<<endl;
        
        cout<<"  ┃";
        for(i=0;i<y/2;i++)cout<<" ";
        cout<<title;
        if(title.length()%2==0){
            for(i=0;i<y/2;i++)cout<<" ";
        }
        else{
            for(i=0;i<y/2+1;i++)cout<<" ";
        }
        cout<<"┃"<<endl;
        
        cout<<"●┣";
        for(j=0;j<column;j++)
        {
            for(i=0;i<x-1;i++)cout<<"━";
            (j<column-1)?cout<<"┳":cout<<"┫"<<endl;
        }
        //row------------------------------------------------
        for(k=0;k<row;k++){
            if(k<10){
                cout<<" "<<k<<"┃";
            }
            else{
                cout<<k<<"┃";
            }
            for(j=0;j<column;j++)
            {
                cout<<data[j][k];
                for(i=0;i<(x-1)*2-data[j][k].length();i++)cout<<" ";
                cout<<"┃";
                if(j==column-1)cout<<endl;
            }
            (k<row-1)?cout<<"●┣":cout<<"●┗";
            for(j=0;j<column;j++)
            {
                for(i=0;i<x-1;i++)cout<<"━";
                if(k<row-1){
                    (j<column-1)?cout<<"╋":cout<<"┫"<<endl;
                }
                else{
                    (j<column-1)?cout<<"┻":cout<<"┛"<<endl;
                }
               
            }
        }
    }
    void addRow(){
        row++;
        for(int i=0;i<column;i++){
            data[i].resize(row);
            data[i][row-1]=" ";
        }
        cout<<" ●添加成功..."<<endl;
    }
    void addColumn(){
        column++;
        data.resize(column);
        for(int i=0;i<column;i++){
            data[i].resize(row);
        }
        for(i=0;i<row;i++){
            data[column-1][i]=" ";
        }
        cout<<" ●添加成功..."<<endl;
    }
    void update(){   
        string str,s;
        char c;
        int x,y;
        while(true){
            while(true){
                system("cls");
                draw();
                cout<<"请输入要修改数据的坐标(如'A0',输入0返回):";
                cin>>str;
                if(str=="0"){
                    system("cls");
                    return;
                }
                c=str[0];
                x=c-65;
                str=str.substr(1,str.length());
                y=atoi(str.c_str());
                if(x<column && x>=0 && y>=0 && y<row){
                    break;
                }
                else{
                    cout<<"输入有误,请重新输入"<<endl;
                    system("pause");
                    continue;
                }
            }
            cout<<"请输入修改值:";
            cin>>s;
            data[x][y]=s;
        }
    }
};
int main()
{
    string title;
    int option;
    system("color a");
    cout<<"请输入表格的标题:"<<endl;
    cin>>title;
    Table t(title);
    cout<<"表格创建完成...."<<endl;
    system("pause");
    system("cls");
    while(true){
        cout<<"┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓"<<endl;
        cout<<"┃1.显示表格\t2.修改数据\t3.增加列\t4.增加行\t5.退出程序  ┃"<<endl;
        cout<<"┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛"<<endl;
        cout<<" ●请选择:";
        cin>>option;
        switch(option){
        case 1:t.draw();break;
        case 2:t.update();break;
        case 3:t.addColumn();break;
        case 4:t.addRow();break;
        case 5:exit(0);break;
        }
    }
   
}
搜索更多相关主题的帖子: 表格 计算 private include public 
2012-06-18 17:46
快速回复:求大神帮忙加个表格数据统计计算模块
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029840 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved