| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 534 人关注过本帖
标题:请求完善程序(制作阅读器实现翻页)
取消只看楼主 加入收藏
bluegirlhere
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2013-4-7
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:2 
请求完善程序(制作阅读器实现翻页)
#include <iostream>
#include <fstream>
#include <iomanip>
#include <windows.h>
using namespace std;

//设计和实现一个NewsBrowser类,读取一个txt文件,允许按一定格式(10列*15行,15列*22行)
//来显示允许page down and page up
class txtRead{
private:
    fstream newsFile;
    char y;
    int rows;
    int cols;
    char news;
public:
    void printTxt();
    void countNum();
    void chooseSize();
    void changePage();
    txtRead();
};

txtRead::txtRead(){
    newsFile.open("I:\\NewBrowserText.txt");
    if(!newsFile){
        cout<<"you get wrong file's address!"<<endl;
    rows=15,cols=10;
    }
}

void txtRead::printTxt(){
    while(newsFile.get(news)){
        if(news!=' '&& news!='\n'){
            cout<<news;
        }
        if(news==' '){
            cout<<" ";
        }
        if(news=='\n'){
            cout<<"\n";
        }
        if(news=='\0')break;
    }
    newsFile.close();
}

 void txtRead::changePage(){

    int countRow=1;
    int countCol=1;
    int i=0;
    countNum();
    while(printTxt()){
        if(countRow<rows){
            cout<<news;
            //cout<<endl<<setfill(' ')<<setw(40);
            countRow++;
            countCol=1;
            i++;
        }
        else{
            cout<<endl;
            cout<<news;
            countRow=1;
            countCol=1;
            countCol++;
            i++;
        }
            //cout<<endl<<setfill(' ')<<setw(40);

        if(countCol==cols){
            cout<<"the words:"<<i<<endl;
            cout<<"the"<<(i/(rows*cols))<<"page"<<endl;
            system("pause");
            system("cls");
            countCol=0;
            countRow=0;
            changePage();
            }
    }


}

void txtRead::countNum(){
    int countAll=0;
    while(newsFile.get(news)){
        if(news==' '){
            countAll++;
        }
        else
        countAll++;
    }
    chooseSize();
    int page;
    if(countAll%(rows*cols)!=0){
        page=countAll/(rows*cols)+1;
    }
    if(countAll%(rows*cols)==0){
        page=countAll/(rows*cols);
    }
    newsFile.close();
    //cout<<"                       "<<"conclude"<<countAll<<"words    "<<"and   "<<page<<"   pages"<<endl;
   // system("pause");
}

/*void txtRead::chooseSize(){
    cout<<"Please choose your size:"<<endl;
    cout<<"a(15rows*10cols)  or  b(22rows*15cols)"<<endl;

    cin>>y;
    if(y=='a'){
        rows=15,cols=10;
    }
    if(y=='b'){
        rows=22,cols=15;
    }
    /*if(y!='a' || y!='b'){
    cout<<"You choose the wrong number!"<<endl;
    }
    system("pause");
    return y;}*/


int main(){
    txtRead readNews;
    cout<<"                                   "<<"NewBrowser"<<endl;
    cout<<"-------------------------------------------------------------------------------"<<endl;
    //readNews.countNum();
    readNews.printTxt();


}
搜索更多相关主题的帖子: void private include public 
2013-04-13 17:15
bluegirlhere
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2013-4-7
收藏
得分:0 
while(printTxt()不通过,要怎么修改
2013-04-13 17:16
bluegirlhere
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2013-4-7
收藏
得分:0 
回复 3楼 peach5460
我自己写的。。正在学类。不断尝试,卡在那了不知道要怎么改。。昨晚连做六小时。。
2013-04-14 02:15
快速回复:请求完善程序(制作阅读器实现翻页)
数据加载中...
 
   



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

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