首页 > 编程语言 > 详细

C++ 写的字符画全球定位,还带gps哟!

时间:2014-02-26 11:54:49      阅读:456      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
#include <iostream>
#include <fstream>
#include <memory.h>
using namespace std;
const int FULL_LOGITUDE = 180;
const int FULL_LATITUDE = 90;
const int THE_PRIME_MERIDIAN = 3;
class World {
    //地图的长度
private:
    int width;
    int high;
    char** arr;
public:
    World(string file) {
        width = 135;
        high  = 36;
        char buffer[256];
        ifstream ifile;
        ifile.open("world.txt");
        arr = new char*[high];
        for(int i=0; i<high; i++) {
            arr[i] = new char[width];
            for(int j=0 ;j<width;j++){
                arr[i][j]=+;
            }
        }
        for(int i=0;i<high;i++) {
            ifile.getline(buffer,256);
            memcpy(arr[i],buffer,width);
        }
    };
    ~World(){
      for(int i=0;i<high;i++){
        delete []arr[i];
      }
      delete []arr;
    }
    void Print() {
        for(int i =0; i<high; i++) {
            for(int j=0;j<width;j++){
             cout<<arr[i][j];
            }
            cout<<endl;
        }
    };
    //对应x,y轴  东经是正数,西经是负数,北纬是正数,南纬是负数
    void Where(double log, double lat){
       int x = int ((log*width/2)/FULL_LOGITUDE);
       int y = int ((lat*high/2)/FULL_LATITUDE);

        x+=THE_PRIME_MERIDIAN;
        if(x<0){
          x+=width;
        }
        y=high/2-y;
        cout<<"x y "<<x<<" "<<y<<endl;
        char temp = arr[y][x];
      /*     @
            @@@
             @
      */

        arr[y][x]=@;


        Print();

        arr[y][x] = temp;
    }
};

int main() {
    World world  = World("world.txt");
    //world.Print();
    int x,y;
    cout<<"一次输入经度和纬度,东西经用正负表示,北南纬用正负表示"<<endl;
    cin>>x;
    cin>>y;
    world.Where(x,y);
}
还有一个 世界地图字符画的txt文件

在这个地址下面 https://github.com/ggaaooppeenngg/worldPicture/blob/master/world.txt

 
bubuko.com,布布扣

C++ 写的字符画全球定位,还带gps哟!

原文:http://www.cnblogs.com/ggaaooppeennngg/p/3567655.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!