1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <ctime>
using namespace std;
float ShowData(float time, float s1, float d1, float s2, float d2);
class Airplane
{
private:
float Accel;
float distance;
float speed;
float t;
float distanceConversion = 1 / 1000;
float speedConversion = 1 / 3600;
public:
Airplane()
{
float s1 = getSpeed();
float s2 = getSpeed();
float d1 = getDistance();
float d2 = getDistance();
cout << setw(10) << s1 << setw(10) << d1 << setw(10) << s2 << setw(10) << d2 << endl;
}
void setTime(float);
void setAccel(float);
void setSpeed(float);
void setDistance(float);
float getTime();
float getAccel();
float getSpeed();
float getDistance();
float ShowData(float &t, float, float, float, float);
void Run();
};
void Airplane::setTime(float time)
{
for ((time == 0); t == 0; time++)
// This doesn't make sense because of your assigment. Do you want to assign time as 0 or have it equal 0? use = for assignment and == for equal.
//What is the function suppose to do?
t = time;
}
void Airplane::setAccel(float accel)
{
accel = rand() % 25 + 1; // what my compiler says is the problem: " '=' conversion from 'int' to 'float' error."
Accel = accel;
}
void Airplane::setSpeed(float Speed)
{
speed = Speed;
}
void Airplane::setDistance(float Distance)
{
distance = Distance;
}
float Airplane::getAccel()
{
return Accel;
}
float Airplane::getTime()
{
return t;
}
float Airplane::getSpeed()
{
return speed;
}
float Airplane::getDistance()
{
return distance;
}
int main()
{
Airplane Airplane1, Airplane2;
unsigned seed;
seed = time(0); // "'=' : conversion from 'time_t' to 'float' error."
srand(seed); // "'argument' : conversion from 'float' to 'unsigned int' error."
float Distance = 0;
float Speed = 0;
float Acceleration = 0;
float time = 0;
Airplane1.setAccel(Acceleration);
Airplane2.setAccel(Acceleration);
Airplane1.setTime(time);
Airplane2.setTime(time);
Airplane1.setSpeed(Speed);
Airplane2.setSpeed(Speed);
Airplane1.setDistance(Distance);
Airplane2.setDistance(Distance);
///////////////////////////////////////////
Airplane1.getAccel();
Airplane2.getAccel();
Airplane1.getTime();
Airplane2.getTime();
Airplane1.getSpeed();
Airplane2.getSpeed();
Airplane1.getDistance();
Airplane2.getDistance();
///////////////////////////////////////////
time = Airplane1.getTime();
float s1 = Airplane1.getSpeed();
float s2 = Airplane2.getSpeed();
float d1 = Airplane1.getDistance();
float d2 = Airplane2.getDistance();
while (time >= 0) //wrong. never do this while (time >= 0);
{
if (d1 < 10 && d2 < 10)
{
//time += time; This doenst make sense because your taking time and adding itself
cout << time;
}
else
{
cout << time;
}
ShowData(Airplane1.getTime(), Airplane1.getSpeed(), Airplane1.getDistance(), Airplane2.getSpeed(), Airplane2.getDistance());
// never redeclare intialized functions. You already have them stated.
}
return 0;
}
/*
void Run()
{
What did this look like?
};
*/
float ShowData(float &time, float s1, float d1, float s2, float d2)
{
static float t;
/*s1, s2;
d1, d2; you already declared these. No sense in repeating.*/
cout << setw(15) << "Airplane 1" << setw(5) << "" << setw(11) << "Airplane 2" << endl;
cout << "Time" << setw(5) << "Km/h" << setw(5) << "Km" << setw(6) << "" << setw(5) << "Km/h" << setw(5) << "Km" << endl;
return 0;
/*do{
for (time >= 0; d1 < 10 || d2 < 10; time++)
{
cout << setw(10) << s1 << setw(10) << d1 << setw(10) << s2 << setw(10) << d2 << endl;
}
return 0;
} while (d1 >0 && d2 >0); This nexted loop loop is nonsense, avoid this. Use different variables.*/
}
|