This class happens to be for a rocket, it's a game that you play and you try to see it you can land safely from 1000 meters up in the air.
The problem is when I input the throttle the program ignores it.
It doesn't matter what i input into the throttle i get the same result.
There are also other problems as well.
Some of my accessors don't change correctly.
What is wrong with my program?
Here is my code first i have the cpp.
I don't know if this helps but im running this off of a Win XP PC using Visual studio 2005.
Expand|Select|Wrap|Line Numbers
- --------------------------------------------------------------------------------------------------------------
- [
- // Program6.cpp
- // Elliot Weimann
- // November 21, 2006
- // This program is a rocket game
- // Computer Science 210
- #include <iostream>
- #include <string>
- #include "program6.h"
- using namespace std;
- void changetime();
- void main()
- {
- int throttle = 0;
- int time = 0;
- lunar c1;
- c1.setFuelflow(0.0);
- cout << "Welcome to my rocket game try to land the rocket safetly from 1000 meters" << endl;
- cout << "To start input the time interval" << endl;
- cin >> time;
- while (c1.getAltitude() > 0 && c1.getAltitude() != 0)
- {
- cout << "Enter a number 1 through 10 for the fuel flow rate " << endl;
- cin >> throttle;
- cout << "Your altitude is " << c1.getAltitude() << endl;
- cout << "Your mass is " << c1.getMass() << endl;
- cout << "Your fuel is " << c1.getFuel() << endl;
- cout << "Your speed is " << c1.getVerticalspeed() << endl;
- if ( throttle > 10 || throttle < 0)
- {
- cerr << "You can't input that amount" << endl;
- system("pause");
- return;
- }
- c1.setFuelflow(throttle/10.0);
- for (int i = 0; i < time; ++i)
- {
- c1.setPasstime(.01);
- }
- }
- {
- if (0 > c1.getVerticalspeed() && c1.getVerticalspeed() > -10 || c1.getVerticalspeed() == 0)
- cout << "safe landing" << endl;
- else
- cout << "unsafe landing" << endl;
- }
- system("pause");
- }
- --------------------------------------------------------------------------------------------------
- Here is my implentation file
- --------------------------------------------------------------------------------------------------
- // Program6implentation.cpp
- // Elliot Weimann
- // November 21, 2006
- // This program is a rocket game
- // Computer Science 210
- #include <iostream>
- #include "program6.h"
- using namespace std;
- lunar::lunar()
- {
- thrust = 5000;
- altitude = 1000;
- mass = 900;
- fuel = 1700;
- fuelrate = 10;
- fuelflow = 0;
- verticalspeed = 0;
- passtime = .01;
- }
- float lunar::getFuel()
- {
- fuel += passtime * fuelrate * fuelflow;
- return fuel;
- }
- float lunar::getFuelrate()
- {
- return fuelrate;
- }
- float lunar::getThrust()
- {
- return thrust;
- }
- void lunar::setFuelflow(float)
- { if (fuel == 0 && fuelflow > 0)
- {
- fuelflow = 0;
- }
- }
- float lunar::getFuelflow()
- {
- return fuelflow;
- }
- float lunar::getMass()
- {
- mass = mass + fuel;
- return mass;
- }
- void lunar::setPasstime(float)
- {passtime += .01;
- }
- float lunar::getPasstime()
- {
- return passtime;
- }
- float lunar::getAltitude()
- {
- altitude += passtime * verticalspeed;
- if(altitude < 0)
- {
- altitude = 0;
- }
- if(altitude > 1000)
- {
- altitude -= passtime * verticalspeed;
- }
- return altitude;
- }
- void lunar::setVerticalspeed(float)
- {
- }
- float lunar::getVerticalspeed()
- {
- verticalspeed += passtime * ((thrust * fuelflow)/mass) - 1.62;
- return verticalspeed;
- }
- ---------------------------------------------------------------------------------------------------
- here is my header file
- --------------------------------------------------------------------------------------------
- // Program6.h
- // Elliot Weimann
- // November 21, 2006
- // This program is a rocket game
- // Computer Science 210
- #ifndef LUNAR_H
- #define LUNAR_H
- class lunar
- {
- public:
- lunar();
- lunar(float, float);
- // Set time of lunar
- void setPasstime(float);
- // Set fuel of lunar
- void setFuelflow(float);
- // Set speed of lunar
- void setVerticalspeed(float);
- // get thrust of lunar
- float getThrust();
- // get time of lunar
- float getPasstime();
- // get altitude of lunar
- float getAltitude();
- // get mass of lunar
- float getMass();
- // get fuel of lunar
- float getFuel();
- // get fuel of lunar
- float getFuelrate();
- // get fuel of lunar
- float getFuelflow();
- // get fuel of lunar
- float getVerticalspeed();
- float fuelflow;
- private:
- // Data members (attributes)
- float fuel;
- float altitude;
- float mass;
- float thrust;
- float fuelrate;
- float verticalspeed;
- float passtime;
- };
- #endif // LUNAR_H
- ]
- -------------------------------------------------------------------------------------------