nazdarek.potreboval by som pomoct s niecim takymto:
Mam program Airport(letisko),je tam okrem ineho ze urcim vysku letu lietadiel a ja potrebujem doplnit uz len to,ze ked je vyska lietadiel rovnaka vypise nejake chybove hlasenie!
PLEASE surnejsie
program pre liedadlo( :!: spusta sa to s kodom co je nizsie,este nizie je potrebna kniznica:!: ):
airplane.cpp
Kód:
#include <iostream.h>
#include <stdio.h>
#pragma hdrstop
#include "airplane.h"
//
// Constructor performs initialization
//
Airplane::Airplane(const char* _name, int _type) :
type(_type),
status(ONRAMP),
speed(0),
altitude(0),
heading(0)
{
switch (type) {
case AIRLINER : ceiling = 35000; break;
case COMMUTER : ceiling = 20000; break;
case PRIVATE : ceiling = 8000;
}
name = new char[50];
strcpy(name, _name);
}
//
// Destructor performs cleanup.
//
Airplane::~Airplane()
{
delete[] name;
}
//
// Gets a message from the user.
//
bool
Airplane::SendMessage(int msg, char* response,
int spd, int dir, int alt)
{
//
// Check for bad commands.
//
if (spd > 500) {
strcpy(response, "Speed cannot be more than 500.");
return false;
}
if (dir > 360) {
strcpy(response, "Heading cannot be over 360 degrees.");
return false;
}
if (alt < 100 && alt != -1) {
strcpy(response, "I'd crash, bonehead!");
return false;
}
if (alt > ceiling) {
strcpy(response, "I can't go that high.");
return false;
}
//
// Do something base on which command was sent.
//
switch (msg) {
case MSG_TAKEOFF : {
// Can't take off if already in the air!
if (status != ONRAMP) {
strcpy(response, "I'm already in the air!");
return false;
}
TakeOff(dir);
break;
}
case MSG_CHANGE : {
// Can't change anything if on the ground.
if (status == ONRAMP) {
strcpy(response, "I'm on the ground");
return false;
}
// Only change if a non-negative value was passed.
if (spd != -1) speed = spd;
if (dir != -1) heading = dir;
if (alt != -1) altitude = alt;
status == CRUISING;
break;
}
case MSG_LAND : {
if (status == ONRAMP) {
strcpy(response, "I'm already on the ground.");
return false;
}
Land();
break;
}
case MSG_REPORT : ReportStatus();
}
//
// Standard reponse if all went well.
//
strcpy(response, "Roger.");
return true;
}
//
// Perform takeoff.
//
void
Airplane::TakeOff(int dir)
{
heading = dir;
status = TAKINGOFF;
}
//
// Perform landing.
//
void
Airplane::Land()
{
speed = heading = altitude = 0;
status == ONRAMP;
}
//
// Build a string to report the airplane's status.
//
int
Airplane::GetStatus(char* statusString)
{
sprintf(statusString, "%s, Altitude: %d, Heading: %d, "
"Speed: %d\n", name, altitude, heading, speed);
return status;
}
//
// Get the status string and output it to the screen.
//
void
Airplane::ReportStatus()
{
char buff[100];
GetStatus(buff);
cout << endl << buff << endl;
}
a s tymto sa to spustaairport.cppKód:
//---------------------------------------------------------------------------
#include <condefs.h>
#include <iostream.h>
#include <conio.h>
#pragma hdrstop
//---------------------------------------------------------------------------
USERES("..\Airport.res");
USEUNIT("airplane.cpp");
//---------------------------------------------------------------------------
#include "airplane.h"
int getInput(int max);
void getItems(int& speed, int& dir, int& alt);
int main(int, char **)
{
char returnMsg[100];
//
// Set up an array of Airplanes and create
// three Airplane objects.
//
Airplane* planes[3];
planes[0] = new Airplane("TWA 1040");
planes[1] = new Airplane("United Express 749", COMMUTER);
planes[2] = new Airplane("Cessna 3238T", PRIVATE);
//
// Start the loop.
//
do {
int plane, message, speed, altitude, direction;
speed = altitude = direction = -1;
//
// Get a plane to whom a message will be sent.
// List all of the planes and let the user pick one.
//
cout << endl << "Who do you want to send a message to?";
cout << endl << endl << "0. Quit" << endl;
for (int i=0;i<3;i++)
cout << (i + 1) << ". " << planes[i]->name << endl;
//
// Call the getInput() function to get the plane number.
//
plane = getInput(4);
//
// If the user chose item 0 then break out of the loop.
//
if (plane == -1) break;
//
// The plane acknowledges.
//
cout << endl << planes[plane]->name << ", roger.";
cout << endl << endl;
//
// Allow the user to choose a message to send.
//
cout << "What message do you want to send?" << endl;
cout << endl << "0. Quit" << endl;;
cout << "1. State Change" << endl;
cout << "2. Take Off" << endl;
cout << "3. Land" << endl;
cout << "4. Report Status" << endl;
message = getInput(5);
//
// Break out of the loop if the user chose 0.
//
if (message == -1) break;
//
// If the user chose item 1 then we need to get input
// for the new speed, direction, and altitude. Call
// the getItems() function to do that.
//
if (message == 0)
getItems(speed, direction, altitude);
//
// Send the plane the message.
//
bool goodMsg = planes[plane]->SendMessage(
message, returnMsg, speed, direction, altitude);
//
// Something was wrong with the message
//
if (!goodMsg) cout << endl << "Unable to comply.";
//
// Display the plane's response.
//
cout << endl << returnMsg << endl;
} while (1);
//
// Delete the Airplaine objects.
//
for (int i=0;i<3;i++) delete planes[i];
return 0;
}
int getInput(int max)
{
int choice;
do {
choice = getch();
choice -= 49;
} while (choice < -1 || choice > max);
return choice;
}
void getItems(int& speed, int& dir, int& alt)
{
cout << endl << "Enter new speed: ";
getch();
cin >> speed;
cout << "Enter new heading: ";
cin >> dir;
cout << "Enter new altitude: ";
cin >> alt;
cout << endl;
}
//---------------------------------------------------------------------------
airplane.hKód:
//---------------------------------------------------------------------------
#ifndef airplaneH
#define airplaneH
//---------------------------------------------------------------------------
#define AIRLINER 0
#define COMMUTER 1
#define PRIVATE 2
#define TAKINGOFF 0
#define CRUISING 1
#define LANDING 2
#define ONRAMP 3
#define MSG_CHANGE 0
#define MSG_TAKEOFF 1
#define MSG_LAND 2
#define MSG_REPORT 3
class Airplane {
public:
Airplane(const char* _name, int _type = AIRLINER);
~Airplane();
virtual int GetStatus(char* statusString);
int GetStatus()
{
return status;
}
int Speed()
{
return speed;
}
int Heading()
{
return heading;
}
int Altitude()
{
return altitude;
}
void ReportStatus();
bool SendMessage(int msg, char* response,
int spd = -1, int dir = -1, int alt = -1);
char* name;
protected:
virtual void TakeOff(int dir);
virtual void Land();
private:
int speed;
int altitude;
int heading;
int status;
int type;
int ceiling;
};
#endif
PLEASE....pripadne poslem program