weixin_45975596
初夏浅梦i
2020-06-02 18:39

大哥们谁帮我看看代码 为什么数组调到50了 只要调用Pt类 就无法cout了 项目这星期教了很急

  • c++

图片说明
#pragma once
#include

class Pt
{
public:
NetwordCarPlatform orders[50];
void allorders(); //所有订单
void buildorders(); //生成的订单
void dispatchorders(); //派遣的订单

int len,kehulen;
int  kehunum;

Pt();
~Pt();

};

#include"stdafx.h"
using namespace std;

Pt::Pt()
{
    int ids[50]={6235001,6235002,6235003,6235004};
    string kehus[50] = { "张三","李四","王二","麻子" };
    //客户数组
    string sjhs[50] = {"19124214124","19323574212","18427380461","14214985858"};
    //手机号数组
    string cjsjs[50] = {"Fri May 24 01:11:05 2019","Fri May 24 07:31:01 2019","Fri May 24 08:100:49 2019","Fri May 24 09:30  2019"};
    //订单创建时间
    string orderdiver[50] = { "马男","蔡家正","傅英欣","暂未接单" };
    string ztais[50] = { "是","是","是","否"};
    //订单状态
    string slsjs[50]={"Fri May 24 01:15:23 2019","Fri May 24 07:32:05 2019","Fri May 24 08:55:24 2019","暂未受理"};     
    //受理时间


    len = sizeof(ids) / sizeof(int);

    for (kehulen = 0; kehulen < 50; kehulen++)
    {
        if (orders[kehulen].kehu == "\0")
        {
            break;
        }
    }

    kehunum = rand() % kehulen;



    for (int i = 0; i < len; i++)
    {
        orders[i].id = ids[i];
        orders[i].kehu = kehus[i];
        orders[i].sjh = sjhs[i];
        orders[i].cjsj = cjsjs[i];
        orders[i].diver = orderdiver[i];
        orders[i].ztai = ztais[i];
        orders[i].slsj = slsjs[i];  

    }
}


Pt::~Pt()
{

}


void Pt::allorders()                                            //显示所有订单
{
    cout << "已显示所有订单:" << endl;
    cout << "订单号\t\t客户名\t\t手机号\t\t生成订单时间\t\t\t司机名\t接受订单状态\t\t受理订单时间" << endl;
    for (int i = 0; i < len ; i++)
    {
        if (orders[i].kehu=="\0")
        {
            break;
        }
        orders[i].allorders();
    }
}


void Pt::buildorders()                                          //显示生成订单
{
    cout << "已显示生成订单:" << endl;
    cout << "订单号\t\t生成订单时间\t\t\t\t接受订单状态\t\t受理订单时间" << endl;
    for (int i = 0; i < len; i++)
    {
        if (orders[i].kehu == "\0")
        {
            break;
        }
        if (orders[i].ztai == "是")
        {
            continue;
        }
        orders[i].scorders();
    }
}



void Pt::dispatchorders()                                       //显示派遣订单
{
    cout << "已显示派遣订单:" << endl;
    cout << "订单号\t\t客户名\t\t手机号\t\t生成订单时间\t\t\t接受订单状态\t\t受理订单时间" << endl;
    for (int i = 0; i < len; i++)
    {
        if (orders[i].kehu == "\0")
        {
            break;
        }
        if (orders[i].ztai == "否")
        {
            continue;
        }
        orders[i].pqorders();
    }
}


#pragma once

class NetwordCarPlatform
{
public:
int id;
string kehu; //客户名
string sjh; //手机号
string cjsj; //订单创建时间
string diver; //司机名
string ztai; //订单状态
string slsj; //受理时间
string sjdiver;

void allorders();                                   //全部订单
void scorders();                                    //生成订单
void pqorders();                                    //派遣订单
void showalldivers();
void addalldiver();

NetwordCarPlatform();
NetwordCarPlatform(int ids, string kh, string sj, string cj, string cardiver, string zt,string sl,string showdiver);
~NetwordCarPlatform();

};

// 网约车.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"

using namespace std;



NetwordCarPlatform::NetwordCarPlatform(int ids, string kh, string sj, string cj, string cardiver, string zt, string sl,string showdiver)
{
    this->id = ids;
    this->kehu = kh;
    this->sjh = sj;
    this->cjsj = cj;
    this->diver = cardiver;
    this->ztai = zt;
    this->slsj = sl;
    this->sjdiver = showdiver;
}

void NetwordCarPlatform::allorders()                                //所有订单
{
    cout << id << "\t\t" << kehu << "   \t" << sjh << "\t" << cjsj << "\t" << diver << "\t" << ztai << "\t\t" << slsj<<endl;

}


void NetwordCarPlatform::scorders()                                 //生成订单
{
    cout << id << "\t\t"  << cjsj << "\t\t" << ztai << "\t\t\t" << slsj<<endl;
}


void NetwordCarPlatform::pqorders()                                 //派遣订单
{
    cout << id << "\t\t" << kehu << "   \t" << sjh << "\t" << cjsj << "\t" << ztai << "\t\t" << slsj<<endl;
}

void NetwordCarPlatform::showalldivers()
{
    cout << sjdiver << endl;
}

void NetwordCarPlatform::addalldiver()
{

}

NetwordCarPlatform::NetwordCarPlatform()
{

}


NetwordCarPlatform::~NetwordCarPlatform()
{

}


int main()
{
    string js;
    int num;
    time_t now = time(0);
    char* localtime = ctime(&now); // 获取时间

    while(1)
    {
        cout << "请选择角色:" << endl;
        cout << "平台 司机  乘客" <<endl;
        cout << "请输入你的选择:";
        cin >> js;
        if(js=="平台")
        {
            while(1)
            {
            Pt _middle;
            string xz;
            cout<<"欢迎进入网约车平台"<<endl;
            cout<<"请选择操作:1、显示所有订单、2、显示生成的订单、3、显示派遣的订单、4、添加司机、5、显示所有司机、6、返回上一级"<<endl;
            cout<<"请输入你的选择:";
            cin>>xz;
            if(xz=="1"||xz=="显示所有订单")
            {
                _middle.allorders();
            }
            else if(xz=="2"||xz=="显示生成的订单")
            {
                _middle.buildorders();
            }
            else if(xz=="3"||xz=="显示派遣的订单")
            {
                _middle.dispatchorders();
            }
            else if(xz=="4"||xz=="添加司机")
            {

            }
            else if(xz=="5"||xz=="显示所有司机")
            {
                Diver _dver;

            }
            else if(xz=="6"||xz=="返回上一级")
            {
                break;
            }
            else
            {
                cout<<"输入错误,请你检查后重新输入!" << endl;
                continue;
            }
            }
        }
        else if(js=="司机")
        {
            while (1)
            {
                Diver cardiver;
                string diverxz;
                int carnum = cardiver.divernum;

                cout << "欢迎进入司机模块" << endl;
                cout << "请选择操作:1、查看受理订单、2、查看待接收订单、3、返回上一级" << endl;
                cout << "请输入你的选择:";
                cin >> diverxz;
                if (diverxz == "1" || diverxz == "查看受理订单")
                {

                }
                else if (diverxz == "2" || diverxz == "查看待接收订单")
                {

                }
                else if (diverxz == "3" || diverxz == "返回上一级")
                {
                    break;
                }
                else
                {
                    cout << "输入错误,请你检查后重新输入!" << endl;
                    continue;
                }
            }
        }
        else if(js=="乘客")
        {

            string farexz,farename,bourn,phone,orderxz;
            while(1)
            {
            cout<<"欢迎进入用户模块"<<endl;
            cout<<"请选择操作:1、发布订单、2、查看已发布订单、3、返回上一级"<<endl;
            cout<<"请输入你的选择:";
            cin >> farexz;
            if(farexz=="1"||farexz=="发布订单")
            {
                while(1)
                {
                cout<<"请你输入你的姓名:";
                cin>>farename;
                cout<<"请你输入你的目的地:";
                cin>>bourn;
                cout<<"请你输入你的手机号:";
                cin>>phone;
                cout<<"你确定提交该订单吗?是<Y>/否<N>";
                cin>>orderxz;
                if(orderxz=="是"||orderxz=="Y"||orderxz=="y")
                {
                    int i;
                    int idbh = 623500 + i;
                cout<<"提交成功,你的订单号为:"<< idbh <<"正在等待司机的受理,可在用户模块查看已发布订单查询!"<<endl;

                break;  
                }
                else if(orderxz=="否"||orderxz=="N"||orderxz=="n")
                {
                    cout<<"订单已取消!"<<endl;
                    cout << "请问是输入输入错误,需要重新输入还是返回上一级,请选择以下操作:" << endl;
                    cout << "1、重新输入、2、返回上一级"<<endl;
                    cout << "请输入你的选择:";
                    cin >> farexz;
                    if (farexz == "1" || farexz == "重新输入")
                    {
                        continue;
                    }
                    else if (farexz == "2" || farexz == "返回上一级")
                    {
                        break;
                    }
                    else
                    {
                        cout << "输入错误,请你检查后重新输入!"<<endl;
                    }
                }
                else
                {
                cout<<"输入错误,请你检查后重新输入!" << endl;
                continue;
                }
                }
            }
            else if(farexz=="2"||farexz=="查看已发布订单")
            {

                while(1)
                {
                    cout<<"请输入你的姓名进行查询:";
                    cin>>farename;
                }
            }
            else if(farexz=="3"||farexz=="返回上一级")
            {
                break;
            }
            else
            {
                cout<<"输入错误,请你检查后重新输入!" << endl;
                continue;
            }
            }
        }
        else
        {
            cout<<"输入错误,请你检查后重新输入!" << endl;
            continue;
        }
    }
}


#pragma once
class Diver
{
public:
int namelen, divernum;
NetwordCarPlatform cg[50];
void checkorder(string name); //司机模块的接收订单
void sendorder(string determine, string divernanme); //司机模块的分发订单
void allshowdiver();
void addonediver();

Diver();
~Diver();

};

#include"stdafx.h"



void Diver::checkorder(string name)                             //给司机模块进行查询该司机已经接受过的订单
{ 
    Pt middle;
    int ddlen = middle.len;
    cout << "订单号\t\t生成订单时间\t\t\t\t接受订单状态\t\t受理订单时间" << endl;
    for (int i = 0; i < ddlen; i++)
    {
        if (middle.orders[i].ztai == "\0")
        {
            break;
        }
        if (middle.orders[i].ztai == "是")
        {
            continue;
        }
        middle.orders[i].scorders();
    }
}


void Diver::sendorder(string determine, string divername)           //给司机模块进行派遣订单
{

}
void Diver::allshowdiver()
{
    for (int i = 0; i < namelen; i++)
    {
        cout << i + 1 << "、";
        cg[i].showalldivers();
    }
}

void Diver:: addonediver()
{

}

Diver::Diver() 
{
    string divers[50] = { "张五","李飞","王浩","马男","广源浩","刘伟","董瑞瑞","陆志胜","蔡家正","董瑶","王龙","李端","胡子睿","许嘉茂","孙元道","贾汉印","贺谦静","莫宇","扬丘","傅英欣","萧如","邱兴易" };
    //司机名
    for (namelen = 0; namelen < 100; namelen++)
    {
        if (divers[namelen] == "\0")
        {
            break;
        }
    }
    divernum = rand() % namelen;                                    //每次运行取随机一位司机
    for (int i = 0; i < namelen; i++)
    {
        cg[i].sjdiver = divers[i];
    }
}


Diver::~Diver()
{

}
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答