既存のメインのヘッダーと cpp ファイルを作成するのは初めてです。プログラムを実行できますが、出力がありません。誰かがトラブルシューティングを手伝ってくれるなら、とても感謝しています。このプログラムは、エレベーターをシミュレートすることになっています。ありがとう!
これが私が与えられたものです:
int main()
{
elevator aLift(1);
aLift.select(5);
aLift.select(3);
system("pause");
return 0;
}
これが私のヘッダーファイルです。
#ifndef elevator_h
#define elevator_h
#include <string>
using namespace std;
class elevator {
public: //operations
elevator();
//coonstructors
elevator (int initFloor);
//modifiers
void select (int newFloor);
//my floor is increased/decreased by difference.
//accessors
int getFloor() const;
//gets current floor number
private: //state
int my_floor;
int selected_floor;
};
#endif // ifndef elevator_h
最後に、これが私のcppファイルです
#include "elevator.h"
#include <string>
#include <iostream>
using namespace std;
int selected_floor;
elevator;
elevator::elevator (int initFloor)
//coonstructors
{
my_floor=initFloor;
}
//modifiers
void elevator::select (int)
{
while(my_floor < selected_floor)
cout << "Going up to " << ++my_floor << endl;
}
//my floor is increased/decreased by difference.
//accessors
int elevator::getFloor() const
{
return selected_floor;
}