请高手帮忙找个错误

Legend258 2008-11-08 10:45:04
//"car.h"
#ifndef _CAR_H
#define _CAR_H
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class car;
istream &operator>>(istream &stream, car &e);
class car {
private:
string license;
string action;
int number;
public:
car ();
car (string license, string action,int number);
string getlicense() ;
string getaction() ;
int getnumber();
void plusnumber();
friend istream &operator>>(istream &stream, car &c);
};
#endif
//"car.cpp"
#include<iostream>
#include"car.h"
using namespace std;
car::car(string license,string action,int number){
this->license = license;
this->action = action;
this->number =number;
}
car::car(){
number = 0;
}
string car::getlicense (){
return license;
}

string car::getaction (){
return action;
}
int car::getnumber (){
return number;
}
void car::plusnumber (){
number= 10;
}
istream &operator>>(istream &stream, car &c) {
stream >> c.license;
stream >> c.action;
return stream;
}
//"main.cpp"
#include<iostream>
#include<fstream>
#include<stack>
#include <sstream>
#include"car.h"
using namespace std;
int main () {
stack<car*>file;
stack<car*> s;
ifstream in;
in.open("data.txt");
if (!in) {
cerr << "Couldn't open data file, data file empty" << endl;
return 0;
}
string line;
while(getline(in,line)){
stringstream strcin(line);
car a;
strcin>>a;
if(a.getaction() == "arrives"&&file.size () < 5){
file.push(&a);
}
else if (file.size () == 5&&a.getaction ()=="arrives"){
cout<<"Sorry "<<a.getlicense ()<<", the lot is full"<<endl;
}
else if (a.getaction() =="departs"){
int m=0;
while (file.top()->getlicense() !=a.getlicense() ){
cout<<"askd"<<endl;
s.push(file.top());
file.pop();
m++;
}
if(m!= 0){
while(!s.empty ()){
s.top()->plusnumber ();
cout<<s.top()->getnumber ();
file.push(s.top());
s.pop();
}
}


cout<<file.top()->getlicense()<<" was moved "<<file.top()->getnumber() <<" times while it is here"<<endl;
file.pop();
}
}

while(file.size()!= 0){
cout<<(file.top())->getlicense()<<" was moved "<<(file.top())->getnumber() <<" times while it is here"<<endl;
file.pop();
}
in.close ();
return 0;

}

//"data.txt"
COOLONE arrives
COOLONE departs
TKG-123 arrives
QWE-839 arrives
UTU-K90 arrives
QWE-839 departs
RRR-877 arrives
GHL-GII arrives
PROGRAM arrives
TKG-123 departs
HEAD-DR arrives
UTU-K90 departs
RRR-877 departs
DMS-RJS arrives
DMS-RJS departs
TUE-87B arrives
GHL-GII departs
WEW-GH1 arrives
THE-MAN arrives
PORSCHE arrives
HEAD-DR departs
ERU-883 arrives
TUE-87B departs
WEW-GH1 departs
APPLE-1 arrives
BKE-284 arrives
BKE-284 departs
APPLE-1 departs
THE-MAN departs

//要求最后的结果为
COOLONE was moved 0 times while it was here
QWE-839 was moved 0 times while it was here
TKG-123 was moved 0 times while it was here
UTU-K90 was moved 2 times while it was here
RRR-877 was moved 2 times while it was here
DMS-RJS was moved 0 times while it was here
GHL-GII was moved 3 times while it was here
Sorry PORSCHE, the lot is full
HEAD-DR was moved 3 times while it was here
TUE-87B was moved 2 times while it was here
WEW-GH1 was moved 2 times while it was here
BKE-284 was moved 0 times while it was here
APPLE-1 was moved 0 times while it was here
THE-MAN was moved 3 times while it was here
ERU-883 was moved 3 times while it was here
PROGRAM was moved 4 times while it was here


大部分都编好了,可就是结果有问题
看了半天,小弟认为出错的原因可能是"main.cpp"中
while(file.top()->getlicense()!=a.getlicense())
这个循环判断上出错了,可小弟不知道错在哪了
请各位大侠帮帮忙,小弟必有重谢。
...全文
117 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
内容概要:本文详细介绍了利用Simulink进行变压器开路试验的电路连接配置与仿真实现方法,重点在于通过仿真手段还原实际电力系统中变压器在空载条件下的电气特性,从而深入理解其工作原理与性能表现。文章作为电力系统仿真系列研究的一部分,系统阐述了从电路模型搭建、参数设定、仿真运行到结果分析的完整流程,突出展示了MATLAB/Simulink在电力设备建模与教学科研中的强大功能与应用价值。; 适合人群:具备电力系统基础知识,熟悉MATLAB/Simulink仿真环境,从事电气工程、自动化及相关领域的研发人员,以及高年级本科生和研究生。; 使用场景及目标:①掌握变压器开路试验的基本原理与Simulink仿真建模的具体步骤;②通过仿真实验深入理解空载电流、铁芯损耗及励磁特性等关键参数的物理意义;③为后续开展变压器短路试验、暂态过程分析以及其他电力设备的仿真研究奠定理论与实践基础。; 阅读建议:建议结合Simulink软件动手实践,逐步构建并调试电路模型,重点关注各元件参数的设置方法与测量模块的应用技巧,同时推荐参考文中提及的其他相关仿真案例进行拓展学习,以全面提升对电力系统仿真实践的整体认知与操作能力。

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧