社区
系统维护与使用区
帖子详情
linux shell 文件配置
pantaishuai
2014-04-29 10:17:28
各位大神,我在运行文件时出现了乱码,而且设置了编码运行正常,但是关闭shell再运行就不可以了。还有就是出现了sh:color:+乱码
...全文
206
7
打赏
收藏
linux shell 文件配置
各位大神,我在运行文件时出现了乱码,而且设置了编码运行正常,但是关闭shell再运行就不可以了。还有就是出现了sh:color:+乱码
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
7 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
pantaishuai
2014-04-30
打赏
举报
回复
编译能通过,但就是运行出来时显示目录是乱码。
pantaishuai
2014-04-30
打赏
举报
回复
//停车场模拟程序
//该程序需实现以下功能:
//(1) 模拟车辆进出
//(2) 模拟停车功能,该程序需要为进来的车辆安排一个车位
//(3) 计费功能,根据停车时间计算费用,在车辆离开时收取
#include<iostream>
#include<vector>
#include<time.h>
#include<string>
#include<stdlib.h>
using namespace std;
//定义车位数量
const int pNumber=10;
//定义当前时间
const time_t beginTime=time(NULL);
//定义停车的价格
const int price=5;
//申明Calendar函数
void Calendar(time_t t);
//申明一个全局临时变量来存储每辆车的费用
double amountMoney=0;
class Car
{
private:
//定义车辆进入和离开停车场的时间
string carID;
time_t enterTime;
time_t leaveTime;
int parkID;//停车位编号
double money;
public:
int getParkID()
{
return parkID;
}
string getID()
{
return carID;
}
Car(string str,int parkNumber)
{
this->carID=str;
this->enterTime=time(NULL);
this->parkID=parkNumber;
cout<<"进入停车场的时间:"<<endl;
Calendar(enterTime);
}
~Car()
{
}
double countMoney()
{
return this->money=price*(this->leaveTime-this->enterTime);
}
void Leave()
{
this->leaveTime=time(NULL);
cout<<"离开停车场的时间:"<<endl;
Calendar(leaveTime);
cout<<"共计在停车场停留 "<<this->leaveTime-this->enterTime<<"秒"<<endl;
amountMoney+=countMoney();
cout<<"总费用为 :"<<countMoney()<<" RMB"<<endl;
this->~Car();
}
};
class CarPark
{
private:
vector<bool> bvec;
vector<Car> cvec;
int parkNumber;//车位号
double amountMoney;
public:
CarPark()
{
//将停车位容器置为pNumber大小,并且以false表示空车位,true表示车位有车占用
this->bvec.resize(pNumber);
this->amountMoney=0;
for(size_t i=0;i<this->bvec.size();i++)
bvec[i]=false;
}
//判断停车场是否停满了车辆
bool isEmpty()
{
for(size_t i=0;i<this->bvec.size();i++)
{
if(bvec[i]==false)
{
this->parkNumber=i;
return true;
}
}
return false;
}
//存车
void enterCar()
{
if(this->isEmpty()==true)
{
string id;
cout<<"输入车牌号:"<<endl;
cin>>id;
//存车前应该检查输入的车牌号是否之前输入过
vector<Car>::iterator iter;
bool exist=false;
for(iter=this->cvec.begin();iter!=this->cvec.end();iter++)
{
if(iter->getID()==id)
{
cout<<"此车牌号的车已经在停车场内,车牌号输入错误!"<<endl;exist=true; break;
}
}
if(exist==false)
{
Car car(id,this->parkNumber);//通过id和parkNumber对car进行标识
cvec.push_back(car);
cout<<"请停在 "<<this->parkNumber<<" 号车位!"<<endl;
bvec[this->parkNumber]=true;//将此车位标识为true表示已有车停留
}
}
else
cout<<"停车场现在没有空的车位!"<<endl;
}
//取车
void leaveCar()
{
string id;
cout<<"输入车牌号:"<<endl;
cin>>id;
vector<Car>::iterator iter;
for(iter=this->cvec.begin();iter!=this->cvec.end();iter++)
{
if(iter->getID()==id)
{
int value;
value=iter->getParkID();
this->bvec[value]=false;//车辆离开将车位设为false标识为车位空闲
iter->Leave();
}
}
}
//查询空位
void findParking()
{
cout<<"空闲车位有:"<<endl;
for(size_t i=0;i<this->bvec.size();i++)
if(bvec[i]==false)
cout<<i<<" ";
cout<<endl;
}
};
void Menu()
{
system("color 2E");
for(int i=0;i<20;i++)
cout<<"*";
cout<<"停车场模拟程序";
for(int i=0;i<20;i++)
cout<<"*";
cout<<endl;
CarPark carPark;
do{
cout<<"1:存入车辆 2:取出车辆 3:查询空闲车位 4:查看收益 5:退出"<<endl;
char key;
cin>>key;
switch(key)
{
case '1':
carPark.enterCar();cout<<endl;break;
case '2':
carPark.leaveCar();cout<<endl;break;
case '3':
carPark.findParking();cout<<endl;break;
case '4':
cout<<amountMoney<<endl;break;
case '5':
exit(0);cout<<endl;break;
default:
cout<<"输入了错误的指示,请重新输入!"<<endl;
}
}while(true);
}
void Calendar(time_t t)
{
time(&t);
struct tm* tminfo;
tminfo=localtime(&t);
cout <<("Date: %04d-%02d-%02d %02d时%02d分%02d秒\n", tminfo->tm_year + 1900,
tminfo->tm_mon + 1, tminfo->tm_mday,tminfo->tm_hour,tminfo->tm_min,tminfo->tm_sec);
}
int main()
{
Menu();
return 0;
}
我用的linux系统Chakra版本的。
ljc007
2014-04-30
打赏
举报
回复
代码发出来看看
pantaishuai
2014-04-30
打赏
举报
回复
引用 1 楼 ljc007 的回复:
你是用putty或securecrt之类的登录的不?
应该没有吧,我只知道超级用户登录,那个代码我是从网上下载的,可能是编码不一样。linux 里面没有智能识别编码的吗?每次运行的时候都乱码。
thankinglove
2014-04-30
打赏
举报
回复
回车符格式不一样吧
ljc007
2014-04-29
打赏
举报
回复
你是用putty或securecrt之类的登录的不?
linux
中
shell
的
配置
文件
,
linux
的
shell
配置
文件
linux
的
shell
配置
文件
linux
linux
下有着众多的
shell
环境
配置
文件
,如果不好好缕缕,确实会有点搞不清概念。1、 /etc/profile此
文件
为系统的每个用户设置环境信息,当用户第一次登录时,该
文件
被执行。并从/etc/profile....
linux
shell
读取
配置
文件
随着
linux
接触的越来越多,我们难免需要从一些
配置
文件
中进行读取
配置
参数,
linux
中
shell
属于脚本型语言,读取时没有其它语言方便,特将用过的一种方式分享给大家 实战代码: $ more a.txt name=hello world age=22 ...
Linux
Shell
读取key=value
配置
文件
linux
shell
简单读取
配置
文件
Linux
中
Shell
与环境变量与
配置
文件
shell
的介绍、环境变量、别名、
shell
配置
文件
Shell
读取
配置
文件
ini
Shell
读取
配置
文件
ini
系统维护与使用区
19,612
社区成员
74,603
社区内容
发帖
与我相关
我的任务
系统维护与使用区
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
复制链接
扫一扫
分享
社区描述
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章